Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ghc, haskell-infra: Improve cross-compilation #40642

Merged
merged 12 commits into from May 21, 2018

Conversation

angerman
Copy link
Contributor

Motivation for this change

This adds some minor changes to the GHC expressions, and tries to align the head and 8.4.2 expression. Ideally we'd have one common one among all ghc expressions I think.

This should allow building quick flavors, and building cross compilers to windows.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

peti
peti previously requested changes May 17, 2018

, version ? "8.5.20180118"
, ghcRevision ? "e1d4140be4d2a1508015093b69e1ef53516e1eb6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to parameterize all aspects of the src attribute as function arguments? I would assume that few people actually mess with these settings, and those who want to can easily override the src attribute as a whole.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! that should better be handed like this once we have the generic expression. Will drop.

, description ? ""
, doCheck ? !isCross && (stdenv.lib.versionOlder "7.4" ghc.version)
, doBenchmark ? false
, doVerbose ? false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the presence of buildFlags this attribute seems redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we can drop this in favor or passing -v3 to the buildFlags.

(optionalString (versionOlder "8.4" ghc.version) (enableFeature enableStaticLibraries "static"))
# --enable-static does not work on windows. This is a bug in GHC.
# --enable-static will pass -staticlib to ghc, which only works for mach-o and elf.
(optionalString (!hostPlatform.isWindows && versionOlder "8.4" ghc.version) (enableFeature enableStaticLibraries "static"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone requests static builds for a given platform, then it feels like poor style to just ignore the setting and to silently build shared libraries instead. I'd prefer to see this particular limitation expressed as an assertion instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll amend the PR, to

enableStaticLibraries ? !hostPlatform.isWindows

and a

assert (enableStaticLibraries && hostPlatform.isWindows) "can't use `--enable-static` on windows."

The reason why this does not work is not that we can't built static objects, we can, but we can't use
-staticlib on ghc on windows. -staticlib rolls all dependencies into a combined archive. While this
would work on windows if we used gnu ar and MRI script, GHC can't rely on gnu ar, and as such has
a quck archive concatenation module for gnu and bsd archives only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Nix we do indeed provide GNU ar always, so it would be nice to optionally configure GHC to expect GNU binutils just as one can configure GCC for the same reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather prefer some runtime flag over a build time flag, or even some runtime support int he form of trying to use an MRI script and falling back to the backup solution.

, version ? "8.4.2"
, ghcFlavour ? ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a small comment here explaining that "" means "use ghc's default choice"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

@peti peti changed the title Feature/clean ghc Improved cross-compilation abilities for ghc and generic haskell builder May 17, 2018
@angerman
Copy link
Contributor Author

@peti, thanks for the quick review, I'll make some amendments later today.


# What flavour to build. An empty string indicates no
# specific flavour and falls back to ghc default values.
, ghcFlavour ? ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, ghcFlavour = stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also backport this change to the earlier GHCs for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. But I'd argue against it. I'd rather see us align the 8.{4,6}.y and head into a common form, and then graft previous version onto the common.nix. Otherwise we are going to end up backporting this stuff every time again across all expressions.

@@ -38,11 +46,14 @@ let
"${targetPlatform.config}-";

buildMK = ''
BuildFlavour = ${if targetPlatform != hostPlatform then ghcCrossFlavour else ghcFlavour}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple ${ghcFlavour} per the above

@@ -165,7 +176,11 @@ stdenv.mkDerivation rec {
# zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
# treat that as a unary `{x,y,z,..}` repetition.
postInstall = ''
paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
for f in $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do $out/lib/${name}/bin/* then?

@@ -38,11 +46,14 @@ let
"${targetPlatform.config}-";

buildMK = ''
BuildFlavour = ${if targetPlatform != hostPlatform then ghcCrossFlavour else ghcFlavour}
ifneq \"\$(BuildFlavour)\" \"\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nix doesn't require " to be escaped here, to be clear. Does make?

@@ -24,7 +24,15 @@
# platform). Static libs are always built.
enableShared ? !targetPlatform.useAndroidPrebuilt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wish to allow dynamic linking here but not 8.2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow? That line wasn't even changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh... ok. fixed.

@@ -68,6 +69,10 @@ in

assert editedCabalFile != null -> revision != null;

# --enable-static does not work on windows. This is a bug in GHC.
# --enable-static will pass -staticlib to ghc, which only works for mach-o and elf.
assert hostPlatform.isWindows -> enableStaticLibraries = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two equal signs

@@ -54,10 +68,11 @@ let
EXTRA_CC_OPTS += -std=gnu99
'';


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line wasn't added in 8.4.1. In general it's nice to diff the different GHCs so they don't unnecessarily drift apart. We really should deduplicate soon...

@@ -268,6 +278,28 @@ stdenv.mkDerivation ({
for f in "$packageConfDir/"*.conf; do
sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f
done
'') + (optionalString (isCross && setupHaskellDepends != []) ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you abstract this part out like https://github.com/NixOS/nixpkgs/pull/39735/files#diff-d65852670e35e11b4bd12ed1c634abce ? Fine to wait on separate derivations until #39735 to avoid controversy though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I kept the Setup.hs changes out of this diff on purpose.

@Ericson2314
Copy link
Member

I'm going to rebase onto #40442 after I merge it to staging.

Ericson2314 and others added 11 commits May 21, 2018 15:09
…Inputs

This is because they are just for Setup.hs, so they are just used at build time
and completely isolated from the normal components' dependencies.

This was previous implemented in 8a8f040, but
reverted in e69c7f5 because it broken
setup-depends non-cross in haskell shell environments (custom Setup.hs in cross
shell environments has never worked). This version adds a special native
exception to avoid that breakage.
…taticlib

The reason why this does not work is not that we can't built static
objects, we can, but we can't use `-staticlib` on GHC on windows.
`-staticlib` rolls all dependencies into a combined archive. While this
would work on windows if we used gnu ar and MRI script, GHC can't rely
on GNU ar, and as such has a quick archive concatenation module for GNU
and BSD archives only.
Shell glob works even as the exact set of executable (filenames) varries
beween configuations.
nixpkgs#37012 and  nixpkgs#37707 introduces the setup-hooks for libiconv, which inject `-liconv` into the `NIX_LDFLAGS`. This breaks horribly on windows where the linker end up having no idea how to linke `-liconv`. The configure.ac file specifically ignores libiconv on windows.
@Ericson2314 Ericson2314 changed the title Improved cross-compilation abilities for ghc and generic haskell builder ghc, haskell-infra: Improved cross-compilation abilities May 21, 2018
@Ericson2314 Ericson2314 changed the title ghc, haskell-infra: Improved cross-compilation abilities ghc, haskell-infra: Improve cross-compilation May 21, 2018
@Ericson2314 Ericson2314 dismissed peti’s stale review May 21, 2018 20:09

All requested changes were made

@Ericson2314 Ericson2314 changed the base branch from master to staging May 21, 2018 21:40
@Ericson2314
Copy link
Member

@peti I wanted to land this somewhere pronto so as to enable more work, but if you could also merge this into master via your normal haskell-updates workflow, that would be much appreciated.

@peti
Copy link
Member

peti commented May 22, 2018

It's not that easy, unfortunately, because the patch does not apply to current versions of master.

@Ericson2314
Copy link
Member

Ericson2314 commented May 22, 2018

I'll prepare another PR then. Thanks for checking.

peti added a commit that referenced this pull request May 22, 2018
peti added a commit that referenced this pull request May 23, 2018
teto pushed a commit to teto/nixpkgs that referenced this pull request May 23, 2018
…master

Revert "ghc, haskell infra: NixOS#40642 direct to master"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants