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

stdenv: Force doCheck to be false when we are cross compiling #33603

Merged
merged 2 commits into from Jan 9, 2018

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jan 8, 2018

Motivation for this change

This restores in effect what the old gcc-cross-wrapper did.

I hope this will be a temporary measure. If there is consensus around issue #33599, then we can follow an explicit dontCheck, but default to not checking during cross builds when none is given.

In anticipation of what I outline in #33599, I only simplify exactly those doChecks which are equal to hostPlatform != buildPlatform. I also stick a comment next to them so I can grep for them later.

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.

CC @dezgeg @bgamari @dtzWill

@dtzWill
Copy link
Member

dtzWill commented Jan 8, 2018

Thanks! Generally LGTM!

Few notes:

Could you add a note documenting this behavior? Especially important since the behavior won't be what one expects from looking at the expression.

Actually, on that:
Is there a good way to inject a single line warning about this (in the build log, not an evaluation message)? Something like replacing checkPhase with "echo skipping tests in cross-build"? This way it's always clear something intercepted so that no one is left wondering why tests aren't running.
Will require rebuild for impacted cross derivations but that seems a small cost for long-term sanity.

Also: probably should extend this to cover the installcheck phase (doInstallCheck) as well?

Finally, we don't need it yet AFAIK but while brainstorming on it it may make sense to add a doCrossCheck or dontDisableCheckOnCross to override. Don't see any reason to add it until it's needed, though.

@dezgeg
Copy link
Contributor

dezgeg commented Jan 9, 2018

Sounds good to me. Also fully agree with @dtzWill's comments.

@@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
# Darwin (http://thread.gmane.org/gmane.comp.gnu.core-utils.bugs/19351),
# and {Open,Free}BSD.
# With non-standard storeDir: https://github.com/NixOS/nix/issues/512
doCheck = hostPlatform == buildPlatform
doCheck = true; # not cross
&& hostPlatform.libc == "glibc"
&& builtins.storeDir == "/nix/store";
Copy link
Contributor

Choose a reason for hiding this comment

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

bad syntax

@Ericson2314
Copy link
Member Author

Probably can't so warning very well until mass rebuild, unless we do an eval time warning, but getting to the rest.

@Ericson2314 Ericson2314 force-pushed the cross-check branch 2 times, most recently from 1c2cfa5 to 178ca91 Compare January 9, 2018 16:12
…cross compiling

I hope this will be a temporary measure. If there is consensus around
issue NixOS#33599, then we can follow an explicit `dontCheck`, but default to
not checking during cross builds when none is given.
In anticipation of what I outline in NixOS#33599, I only simplify exactly those
`doCheck`s which are equal to `hostPlatform != buildPlatform`. I also stick a
comment next to them so I can grep for them later.
@Ericson2314
Copy link
Member Author

How does this look now?

@dtzWill
Copy link
Member

dtzWill commented Jan 9, 2018

Great! Bummer can't log without forcing a mass-rebuild :(.

I think the warning is absolutely worth the rebuild--although I'm happy if we tackle it separately and target staging with it or something (and not block this PR on it).

Do you know how such a warning might best be implemented?
Would it be a nix-level solution, modifying builder scripts, or blend of both?

I suppose if it's too much trouble re:complicating unrelated things, we don't "need" the warning. Would be nice though :).


Also, TIL:

nix-repl> let hasA = { a ? 1, ...} @ args: args ? a; in { X = hasA { }; Y = hasA { a = 2; }; }
{ X = false; Y = true; }

And less surprisingly:

nix-repl> :p let hasA = { a ? 1, ...} @ args: { contains = args ? a; inherit a; }; in { X = hasA { }; Y = hasA { a = 2; }; }
{ X = { a = 1; contains = false; }; Y = { a = 2; contains = true; }; }

Neat!

@dtzWill
Copy link
Member

dtzWill commented Jan 9, 2018

I love how this apparently causes "no" rebuilds?! (at least according to the rebuild-amount.sh script) 😁

@Ericson2314
Copy link
Member Author

Ericson2314 commented Jan 9, 2018

@dtzWill yeah something in setup.sh, pretty sure.

@Ericson2314 Ericson2314 merged commit 06a8d66 into NixOS:master Jan 9, 2018
@Ericson2314 Ericson2314 deleted the cross-check branch January 9, 2018 20:09
@dtzWill
Copy link
Member

dtzWill commented Jan 9, 2018

Hmm, should this be comparing buildPlatform instead of targetPlatform?

@Ericson2314
Copy link
Member Author

@dtzWill haha got me! Indeed it should.

@r-burns
Copy link
Contributor

r-burns commented Feb 22, 2021

Would it be reasonable to add a trapdoor so one can still use a checkPhase when cross-compiling? Currently there's no way to check cross-compiled packages - you have to put the check in some other phase because doCheck is impossible to enable. I think there should be an "I know what I'm doing" flag so one can write an idiomatic check phase, which will at least run some cross-friendly sanity checks.

@Cloudef
Copy link
Contributor

Cloudef commented Feb 15, 2022

Sorry for commenting on old pr, but I agree with @r-burns, forcing doCheck can be useful in controlled environments like CI, where for example x86_64 system can run a x86 binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 10.rebuild-darwin: 0 10.rebuild-linux: 0
Projects
No open projects
Cross compilation
After big PR
Development

Successfully merging this pull request may close these issues.

None yet

7 participants