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

Cross-compilation with MinGW broken #59

Closed
abbec opened this issue Nov 22, 2021 · 9 comments
Closed

Cross-compilation with MinGW broken #59

abbec opened this issue Nov 22, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@abbec
Copy link
Contributor

abbec commented Nov 22, 2021

Hi,

c7ed82b broke our cross-compilation for Windows. It seems that with this change, buildInputs (i.e. depsHostTarget) end up in the linker for the build platform (i.e. Linux) which results in /nix/store/5ddb4j8z84p6sjphr0kh6cbq5jd12ncs-binutils-2.35.1/bin/ld: /nix/store/pl9raxwyb6jg662ljd9f1q3hrb2cni8l-pthreads-w32-x86_64-w64-mingw32-2.9.1/lib/libpthread.a: error adding symbols: file format not recognized.

The commit before c7ed82b works as expected.

NIX_LDFLAGS and NIX_LDFLAGS_FOR_BUILD looks the same in both a working and non-working case though?

@abbec
Copy link
Contributor Author

abbec commented Nov 22, 2021

It looks like the same problem discussed at the end of #52, and it did work before c7ed82b so I think the issue is in here, or it exposed an issue in Nixpkgs.

@oxalica oxalica added the bug Something isn't working label Nov 22, 2021
@abbec
Copy link
Contributor Author

abbec commented Nov 22, 2021

Actually there is a small difference in *_LDFLAGS:

Working:

❯ echo $NIX_LDFLAGS
-L/nix/store/14s60q99gfkm52rfzfxry60cnm1f463j-mcfgthreads-x86_64-w64-mingw32-git/lib -L/nix/store/pl9raxwyb6jg662ljd9f1q3hrb2cni8l-pthreads-w32-x86_64-w64-mingw32-2.9.1/lib

❯ echo $NIX_LDFLAGS_FOR_BUILD
-L/nix/store/6bsh70027xrmjsqjxn5wpmwcl2xq8mg0-rust-default-1.53.0/lib -L/nix/store/2jh1myphkbxwwnw9zry684lybg3skgs4-file-5.39/lib

Not working:

❯ echo $NIX_LDFLAGS
-L/nix/store/14s60q99gfkm52rfzfxry60cnm1f463j-mcfgthreads-x86_64-w64-mingw32-git/lib -L/nix/store/14s60q99gfkm52rfzfxry60cnm1f463j-mcfgthreads-x86_64-w64-mingw32-git/lib -L/nix/store/pl9raxwyb6jg662ljd9f1q3hrb2cni8l-pthreads-w32-x86_64-w64-mingw32-2.9.1/lib -L/nix/store/pl9raxwyb6jg662ljd9f1q3hrb2cni8l-pthreads-w32-x86_64-w64-mingw32-2.9.1/lib

❯ echo $NIX_LDFLAGS_FOR_BUILD
-L/nix/store/q25xrjk7sq5pfqnr50xbmkrrkdab2nj1-rust-default-1.53.0/lib -L/nix/store/2jh1myphkbxwwnw9zry684lybg3skgs4-file-5.39/lib

So it is added twice in the case it does not work? Setting it to the "working version" seems to do nothing though.

@abbec
Copy link
Contributor Author

abbec commented Nov 22, 2021

AH!

There is a difference (that also makes sense):

Working:

❯ cat /nix/store/6bsh70027xrmjsqjxn5wpmwcl2xq8mg0-rust-default-1.53.0/nix-support/propagated-build-inputs
(empty)

❯ cat /nix/store/6bsh70027xrmjsqjxn5wpmwcl2xq8mg0-rust-default-1.53.0/nix-support/propagated-native-build-inputs
/nix/store/88ghxafjpqp5sqpd75r51qqg4q5d95ss-gcc-wrapper-10.3.0 /nix/store/88ghxafjpqp5sqpd75r51qqg4q5d95ss-gcc-wrapper-10.3.0

Not working:

❯ cat /nix/store/q25xrjk7sq5pfqnr50xbmkrrkdab2nj1-rust-default-1.53.0/nix-support/propagated-build-inputs
/nix/store/88ghxafjpqp5sqpd75r51qqg4q5d95ss-gcc-wrapper-10.3.0 /nix/store/88ghxafjpqp5sqpd75r51qqg4q5d95ss-gcc-wrapper-10.3.0

❯ ls /nix/store/q25xrjk7sq5pfqnr50xbmkrrkdab2nj1-rust-default-1.53.0/nix-support/
propagated-build-inputs
(no propagated-native-build-inputs)

Is it really expected that a derivation using the Rust compiler gets the host platform compiler as a buildInput (runtime dependency)? A nativeBuildInput makes sense though.

@abbec
Copy link
Contributor Author

abbec commented Nov 22, 2021

Note also that you will only be able to repro this error when you have a build.rs.

@abbec
Copy link
Contributor Author

abbec commented Nov 22, 2021

I have created an example+repro case in #60. Feel free to only use it to reproduce the issue or keep it as a permanent example/test :) I also added a CI job that fails with this exact error.

abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
abbec added a commit to goodbyekansas/rust-overlay that referenced this issue Nov 23, 2021
@abbec
Copy link
Contributor Author

abbec commented Nov 23, 2021

Commenting out propagatedBuildInputs on

propagatedBuildInputs =
, and instead adding depsBuildBuild = [ buildPackages.stdenv.cc ] in my derivation fixes both this issue and #54 (!?).

abbec added a commit to goodbyekansas/nedryland that referenced this issue Nov 23, 2021
This is done by using our own fork of the Rust overlay.
Issue reported here: oxalica/rust-overlay#59
sakarias88 pushed a commit to goodbyekansas/nedryland that referenced this issue Nov 24, 2021
This is done by using our own fork of the Rust overlay.
Issue reported here: oxalica/rust-overlay#59
@oxalica
Copy link
Owner

oxalica commented Nov 25, 2021

Commenting out propagatedBuildInputs on

propagatedBuildInputs =

, and instead adding depsBuildBuild = [ buildPackages.stdenv.cc ] in my derivation fixes both this issue and #54 (!?).

I use propagatedBuildInputs at first time because I want to add gcc to both downstream depsBuildBuild (for build script linking) and nativeBuildInputs (for crate linking). You reminds me that the former should actually be depsHostHostPropagated on our side. But the latter one is surely propagatedBuildInputs.

Here the issue is that CC wrapper for build script thinks it's from nativeBuildInputs and add NIX_LDFLAGS instead of NIX_LDFLAGS_FOR_BUILD, thus trying to link wrong libraries.
I'm working on this.

@abbec
Copy link
Contributor Author

abbec commented Nov 25, 2021

Thank you! Yeah, this seems like more of a nixpkgs bug?

@oxalica oxalica closed this as completed in 1fd2dc0 Dec 2, 2021
@oxalica
Copy link
Owner

oxalica commented Dec 2, 2021

Found that I stdenv.cc is always brought from buildPackages so pkgsHostTarget.stdenv.cc actually equals pkgsBuildHost.gcc, thus I used to pull in wrong ccs.

Now it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants