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

llvm for windows cross compiler #59865

Closed
wants to merge 2 commits into from
Closed

llvm for windows cross compiler #59865

wants to merge 2 commits into from

Conversation

tmcl
Copy link
Contributor

@tmcl tmcl commented Apr 19, 2019

Motivation for this change

Nixpkgs is almost capable of building GHC as an x86-64 Windows cross compiler. It just needs to useLLVM. The resulting binaries are capable of running on Windows 10 and making basic ffi calls. Note that it still fails if targeting 32-bit i686 on a 64 bit machine.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option 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 nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Win32 is marked as broken so you probably can't run cabal2nix to make things build. It is built as part of ghc so not a big deal.

without this it fails on missing `opt`
without this it fails on missing `opt`
@angerman
Copy link
Contributor

You can just use the NCG for windows cross compilation. We (iohk) are in fact cross compiling to windows successfully using nix.
I invite you to check out GitHub.com/input-output-hk/haskell.nix

NB: i would advise not to use the LLVM backend on x86_64. (See the GHC Release Notes)

Copy link
Contributor

@angerman angerman left a comment

Choose a reason for hiding this comment

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

Please don't use LLVM for windows. Use the NCG. The GHC LLVM backend has serious flaws on x86_64. See https://downloads.haskell.org/~ghc/8.6.4/docs/html/users_guide/8.6.4-notes.html#known-issues

Use the cross-ncg flavour, see: https://github.com/ghc/ghc/blob/36e51406eb5c551f6fdc5b2f9e087c1d3a809141/mk/build.mk.sample#L31-L32

@matthewbauer
Copy link
Member

Hmm... We are using ncg right now and getting this error:

"inplace/bin/hsc2hs" '--cc=/nix/store/gbpi592v6q4dvb94k4j0f261pjhwj5v2-x86_64-pc-mingw32-stage-final-gcc-debug-wrapper-7.4.0/bin/x86_64-pc-mingw32-cc' '--ld=/nix/store/gbpi592v6q4dvb94k4j0f261pjhwj5v2-x86_64-pc-mingw32-stage-final-gcc-debug-wrapper-7.4.0/bin/x86_64-pc-mingw32-cc'  --cross-safe  --cflag=-Wall --cflag=-fno-stack-protector   --cross-compile --cflag=-Dx86_64_HOST_ARCH --cflag=-Dmingw32_HOST_OS --cflag=-D__GLASGOW_HASKELL__=804 '--cflag=-fno-stack-protector' '--cflag=-Wall' '--cflag=-Ilibraries/Win32/dist-install/build/./autogen' '--cflag=-Ilibraries/Win32/include' '--cflag=-Ilibraries/Win32/dist-install/build/include' '--cflag=-fno-strict-aliasing' '--cflag=-Wall' '--cflag=-I/build/ghc-8.4.4/libraries/bytestring/include' '--cflag=-I/build/ghc-8.4.4/libraries/bytestring/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/bytestring/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/bytestring/dist-install/build/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/base/include' '--cflag=-I/build/ghc-8.4.4/libraries/base/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/base/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/base/dist-install/build/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/integer-gmp/include' '--cflag=-I/build/ghc-8.4.4/libraries/integer-gmp/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/integer-gmp/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/libraries/integer-gmp/dist-install/build/dist-install/build/include' '--cflag=-I/build/ghc-8.4.4/rts/dist/build' '--cflag=-I/build/ghc-8.4.4/includes' '--cflag=-I/build/ghc-8.4.4/includes/dist-derivedconstants/header' '--cflag=-Werror=unused-but-set-variable' '--cflag=-Wno-error=inline'  --cflag=-Ilibraries/Win32/dist-install/build/./autogen --cflag=-include --cflag=libraries/Win32/dist-install/build/./autogen/cabal_macros.h   libraries/Win32/./Graphics/Win32/Misc.hsc -o libraries/Win32/dist-install/build/Graphics/Win32/Misc.hs
Misc.hsc: In function '_hsc2hs_test8':
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:70:20: error: storage size of 'test_array' isn't constant
Misc.hsc:70:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc: In function '_hsc2hs_test10':
Misc.hsc:82:20: error: storage size of 'test_array' isn't constant
Misc.hsc:82:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:82:20: error: storage size of 'test_array' isn't constant
Misc.hsc:82:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:82:20: error: storage size of 'test_array' isn't constant
Misc.hsc:82:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:82:20: error: storage size of 'test_array' isn't constant
Misc.hsc:82:20: warning: unused variable 'test_array' [-Wunused-variable]
Misc.hsc:82:20: error: storage size of 'test_array' isn't constant
Misc.hsc:82:20: warning: unused variable 'test_array' [-Wunused-variable]
compilation failed
libraries/Win32/ghc.mk:4: libraries/Win32/dist-install/build/.depend-v-p.haskell: No such file or directory
make[1]: *** [libraries/Win32/ghc.mk:4: libraries/Win32/dist-install/build/Graphics/Win32/Misc.hs] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:127: all] Error 2

https://hydra.nixos.org/build/92403485

ghc-8.4.4 should cross compile to windows correct?

@angerman
Copy link
Contributor

@matthewbauer I think 8.4.4 did work. But you'll need to make sure that your hsc2hs is recent enough. You will need hsc2hs with --via-asm support for the Win32 package to build.

Our ghc is pretty heavily patched, but I believe you'll need at least the hsc2hs patch for ghc < 8.6. See https://github.com/input-output-hk/iohk-nix/blob/8a5bc149b4d4cfa8704be62cf1b8755c33e8ec4d/config.nix#L20-L60

@veprbl veprbl added 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 6.topic: windows Running, or buiding, packages on Windows labels Apr 28, 2019
@matthewbauer
Copy link
Member

matthewbauer commented May 12, 2019

@matthewbauer I think 8.4.4 did work. But you'll need to make sure that your hsc2hs is recent enough. You will need hsc2hs with --via-asm support for the Win32 package to build.

Our ghc is pretty heavily patched, but I believe you'll need at least the hsc2hs patch for ghc < 8.6. See https://github.com/input-output-hk/iohk-nix/blob/8a5bc149b4d4cfa8704be62cf1b8755c33e8ec4d/config.nix#L20-L60

@angerman
It looks like I misspoke on that. We're using the perf-cross backend which corresponds to LLVM. Is it safe to use perf-cross-ncg for all cross compilation?

@angerman
Copy link
Contributor

@matthewbauer I think 8.4.4 did work. But you'll need to make sure that your hsc2hs is recent enough. You will need hsc2hs with --via-asm support for the Win32 package to build.
Our ghc is pretty heavily patched, but I believe you'll need at least the hsc2hs patch for ghc < 8.6. See https://github.com/input-output-hk/iohk-nix/blob/8a5bc149b4d4cfa8704be62cf1b8755c33e8ec4d/config.nix#L20-L60

@angerman
It looks like I misspoke on that. We're using the perf-cross backend which corresponds to LLVM. Is it safe to use perf-cross-ncg for all cross compilation?

for windows/x86_64, yes! We have a proper native code generator (ncg) for x86_64, and the llvm one for x86_64 is buggy anyway.

For targets for which we don't have an ncg (arm, aarch64, ...) the only option is the llvm backend, but I believe the llvm pipeline for those backends is unaffected from the register confusion that can cause subtle bugs on x86_64 with llvm.

@cdepillabout
Copy link
Member

@tmcl Is this PR still relevant? Can it be closed?

If it is still relevant, what is the status of it?

@Mindavi
Copy link
Contributor

Mindavi commented May 19, 2021

I think this might be interesting for better windows support, but it doesn't seem like there's much interest from the creator. Please re-open when you still want to work on this, or when someone wants to pick this open, create a new PR :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 6.topic: haskell 6.topic: windows Running, or buiding, packages on Windows 10.rebuild-darwin: 0 10.rebuild-linux: 0 12. first-time contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants