Skip to content

Comments

[WIP] mingw-w64 for haskell cross compilation with ghc.#37254

Closed
angerman wants to merge 44 commits intoNixOS:masterfrom
angerman:feature/ghc-cross-mingw
Closed

[WIP] mingw-w64 for haskell cross compilation with ghc.#37254
angerman wants to merge 44 commits intoNixOS:masterfrom
angerman:feature/ghc-cross-mingw

Conversation

@angerman
Copy link
Contributor

Motivation for this change

This includes all the necessary changes to nixpkgs, that allow me to cross compile haskell to
windows via mingw-w64. It is not yet sufficient to allow cross compilation of Template Haskell.

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.

@angerman angerman requested a review from peti as a code owner March 17, 2018 15:41
@angerman
Copy link
Contributor Author

/cc @Ericson2314

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While disabling this check, allows most of the cross compilation to succeed on macOS, I believe this is also the reason why we end up with mixed (build and target) packages in the stdenv eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is motivated by the fact that we do not necessarily build haddock with quick flavours. As such we fall over trying to paxmark a file that does not exist.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good-- probably can collapse this to just {ghc,haddock} if we check for existence anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--via-asm is a rather recent feature in hsc2hs that is part of ghc > 8.4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could potentially also be the reason for the incorrect package set on darwin.

@GrahamcOfBorg GrahamcOfBorg added 6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels Mar 17, 2018
@bjornfor bjornfor added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Mar 19, 2018
Copy link
Member

Choose a reason for hiding this comment

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

Better to do ghcFlavour ? if targetPlatform != hostPlatform then "perf-cros" else ""

@angerman angerman force-pushed the feature/ghc-cross-mingw branch from c8f682e to de9b33e Compare March 21, 2018 23:36
@angerman angerman requested a review from FRidh as a code owner March 21, 2018 23:36
@GrahamcOfBorg GrahamcOfBorg added 6.topic: python Python is a high-level, general-purpose programming language. 8.has: package (new) This PR adds a new package labels Mar 21, 2018
Copy link
Member

Choose a reason for hiding this comment

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

Does terminfo/ncurses not work on windows?

If it was failing to find ncurses headers/libs see the fix on my musl PR (remove attempt to specify where to find them).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case of cross compiling to windows, we don't want terminfo, the GHC build system disables terminfoin that case anyway.

Copy link
Member

Choose a reason for hiding this comment

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

It only disables it in some cross build "flavour"s, which we don't have to use as-is. Works for me building cross-aarch64-musl and such. Anyway sounds like you're saying windows in particular shouldn't use this, which I'll take your word for.

Copy link
Member

@dtzWill dtzWill Mar 22, 2018

Choose a reason for hiding this comment

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

👍

@dtzWill
Copy link
Member

dtzWill commented Mar 22, 2018

If you're touching cctools, #37606 might have some useful bits.

Copy link
Member

Choose a reason for hiding this comment

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

I believe that the description of this option is actually quite incorrect and misleading. Setting this to true has no effect on whether ghc builds shared libraries or not. Rather, it affects the code that's used by ghci to load compiled objects for interpretation. There's a good chance that this setting is completely ignored on Windows anyway. Could you please check whether the change you've made here is actually necessary?

Copy link
Member

Choose a reason for hiding this comment

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

enable* is about how the current package is linked. I think this does just that. That this also affects how GHCi works is just a side affect due to GHCi's fragile interpretation.

@dtzWill
Copy link
Member

dtzWill commented Apr 21, 2018

Beep boop, how's this going?

@angerman
Copy link
Contributor Author

angerman commented Apr 21, 2018

@dtzWill this does work as-is (I've used this to build dhall-json among others...). I did however get severely frustrated with the conditionals missing in cabal2nix generated cabal expressions. I did look into making cabal2nix generate better expressions, but learned that what I wanted was a bad fit for what cabal2nix does. And I don't want to disrupt any working solution in nix.

So I ended up writing Cabal2Nix, which really needs a better name. I now have hackage.nix, stackage.nix as well as some glue code in haskell.nix. This is pretty much work-in-progress. While it does allow me to build some trivial hs-hello package, it is nowhere near polished yet, and will likely see some additional changes.

I believe it will provide a much better basis for cross compilation haskell packages.

@Ericson2314
Copy link
Member

@angerman that sounds fascinating but I think your links are broken?

Copy link
Member

Choose a reason for hiding this comment

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

Here propagated setup dependencies are not taken into account. That is, your pkgdb will contain only immediate setup dependencies but their transitive dependencies will not be in it, so it won’t compile.

Copy link
Member

Choose a reason for hiding this comment

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

inherit setupHaskellDepends, I guess.

Copy link
Member

Choose a reason for hiding this comment

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

I think ghc should go to nativeBuildInputs.

@angerman angerman force-pushed the feature/ghc-cross-mingw branch from 98cff92 to 68d2d15 Compare June 8, 2018 15:46
@angerman angerman requested a review from nbp as a code owner June 8, 2018 15:46
Nix cc logic relies on passing /lib for each dependency as a library
search path.  This makes little sense for haskell packages, as their
libs are nested deeply in the /lib tree.  Also GHC will generate the
right library serach paths on its own from the package database
entries.

The larger issue though is that with one search path entry for each
library, and a similar one generated by GHC for each dependency
will eventually overflow the command line argument limits.

As such we do *not* put haskell libraries into $out anymore.
@angerman angerman closed this Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: python Python is a high-level, general-purpose programming language. 8.has: clean-up This PR removes packages or removes other cruft 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants