You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
buildPackages should not know about the top-level targetPlatform #35543
Currently when cross-compiling, the buildPackages set sees the top-level targetPlatform and thus cross-compiling-aware toolchain components are built to target targetPlatform instead of buildPlatform. To get access to a buildPlatform-targeted version of the tool, you need to access buildPackages.buildPackages or, in the special case of cc, we have a hack to make buildPackages.stdenv.cc do the right thing.
Also, anything that checks targetPlatform != buildPlatform (which is now aliased to stdenv.isCross) will get the wrong answer inside buildPackages.
Semantically, it seems like buildPackages should be exactly the same package set you'd get if you weren't cross-compiling at all. Ideally we'd live in a world where all tools were like clang and didn't need specific advance target awareness, but for tools that do isn't this exactly what targetPackages is for? That is, shouldn't I take my build-native compiler from buildPackages, my cross-compiler from targetPackages, and my cross-compiled target-native compiler from hostPackages?
As an aside, those names are really unclear even though they are conventional. I'd expect targetPackages to be "packages that run on the target" and something like crossPackages to be the source of cross-compiling tools.
Erm, generally the check for "is cross-compiling" is `hostPlatform != buildPlatform'.
The Nixpkgs manual helps explain these, although even so they're a bit hard to follow 😇.
However, from the manual, nativeBuildInputs:
A list of dependencies whose host platform is the new derivation's build platform, and target platform is the new derivation's host platform.
So, for building perl that runs on RISC-V (host=riscv, build=x86_64), nativeBuildInputs will give you packages that are:
host == (new derivation's build) == x86_64 -- that is, it will run on the current builder
target == (new derivation's host) == RISC-V -- that is, the compiler will generate code for RISC-V.
So the fact that nativeBuildInputs = [ ...compiler-package ]; gives you a cross-compiler is not surprising.
What is surprising is that depsBuildBuild = [ ... ]; doesn't work., since according to docs depsBuildBuild is:
A list of dependencies whose host and target platforms are the new derivation's build platform. This means a -1 host and -1 target offset from the new derivation's platforms. They are programs/libraries used at build time that furthermore produce programs/libraries also used at build time. If the dependency doesn't care about the target platform (i.e. isn't a compiler or similar tool), put it in nativeBuildInputs instead.
Actually, would depsBuildBuild = [ gcc6 ] work? I think that's the intended usage?
Anyway I think this is clearly a source of confusion and we should try to sort this out. Hopefully @Ericson2314 will be by soon :).
You've a few times told me that I'm too trepid about extra rebuilds, but maybe this a good reason why :). By making as few packages as possible know about the target platform, I make stage 3 very small. (Vanilla final stage, crucially, is its own buildPackages, which allows the cross tools stage target-platform-agnostic packages to be identical since `f (fix f) = f``.)
What is surprising is that depsBuildBuild = [ ... ]; doesn't work.
Actually, would depsBuildBuild = [ gcc6 ] work? I think that's the intended usage?
Yeah it should work; if it doesn't that's a bug. One needs the buildPackages in depsBuildBuild = [ buildPackages.stdenv.cc ] only because stdenv is a one a few attributes on a blacklist not to be spliced.
in the special case of cc, we have a hack to make buildPackages.stdenv.cc do the right thing.
Elaborating on what I said above, this is actually not a hack. stdenv is a very weird because all the packages in it (except for stdenv.libc) are actually drawn from the previous stage. Pretending we only have gcc:
OK, this makes a lot more sense now. I've also been reading from the 17.09 manual, not the unstable manual, which made things even more confusing 😀
So yes, things are all working as expected and this is fine. A few things that I think might be better than the status quo:
We need better names for these stages, despite their ubiquity. Especially targetPackages not actually being "packages which target your target" is very confusing.
depsBuildBuild is a really confusing name.
If we're going to stick with the splicing approach (and I'm not convinced we shouldn't just require specifying the source package set more explicitly somehow), nativeBuildInputs should mean "target-unaware" stuff and something new, like crossBuildInputs, should be used if you need to explicitly include a cross-compiler whose host is the build-system.
Proposal: buildSystemInfo, systemInfo, and crossSystemInfo corresponding to buildPackages, pkgs, and crossPackages which are selected from nativeBuildInputs, buildInputs, and crossBuildInputs. Ideally I'd like to make the latter set buildInputs, inputs, and crossBuildInputs.
Mmmm there is some symmetry / other logic in the existing names I want to lay out first before thinking about improvements:
depsBuildBuild is because there would be all combinations of deps{Build,Host,Target}{Build,Host,Target} satisfying the restriction that the second build/host/target is less than or equal the first, given the order Build < Host, Target. That gives us:
depsBuildBuild
depsBuildHost
depsBuildTarget
depsHostHost
depsHostTarget
depsTargetTarget
Its unfortunate, but unavoidable that there really is two axes here.
As per the manual, I didn't want to break back compat, so buildInputs == depsHostTarget and nativeBuildInputs == depsBuildHost. Only the legacy names are supports cause I need only one name in bash and it would be weird to rename.
If we're going to stick with the splicing approach (and I'm not convinced we shouldn't just require specifying the source package set more explicitly somehow)
Agreed, I hate splicing. I just didn't know an easier way to be backwards compatible.
But also, to be clear, we still need to distinguish the inputs for reasons other than splicing, namely env hooks and similar deps-processing-other-deps stuff. The only good thing about splicing besides back compat is it makes it sorta avoids using the wrong package set for the wrong dep since its (lamely) automatic.
nativeBuildInputs should mean "target-unaware" stuff and something new
Ah so this would be like depsBuildWhatever, in my naming scheme? I thought about that. Indeed the vast majority of packages don't care about the second axis. But I didn't want to make even more deps. and target = host + 1 (of which depsBuildHost and depsHostTarget are examples) is the sanest default if one has to be chosen.
something new, like crossBuildInputs, should be used if you need to explicitly include a cross-compiler whose host is the build-system.
To be clear, depsBuildBuilddepsBuildHost and depsBuildTarget all have the compiler's host as the current package's build. They differ in what the compiler's target is (the second axis).
Thanks for this summary! I think there are two action items here:
Split out the core, language-agnostic, full cross-compilation-details aware bits of mkDerivation into as clean an interface as possible while still supporting mapping from legacy mkDerivation calls (it's OK if corner cases e.g. cc-wrapper need to be rewritten). This wouldn't necessarily need be limited to better cross support, if e.g. propagation needs to be fixed somehow or whatever this is a good time to do it.
Design buildCPackage, buildHaskellPackage, etc. to be built on top of the new core design but with the per-package cross-compilation concerns more easily visible (and the handling of the cross-compiler itself abstracted away).
Thoughts? Do you have a clear vision for 1? I can take a look at 2.
That sounds good. I have a clear vision for 1, and some WIP work for Haskell you may be interested. I'd also like to brainstorm about how to do ccWithPackages etc in conjunction with 2.
By default only allow references (immediate, not filtering to depsHost* and depsTarget*. I.e. nativeBuildInputs and friends will not be allowed to be referenced, unless those derivations are also listed as those other types of deps. This might require Nix modifications for per-output whitelists to accommodate dev outputs. (@vcunat clued me into that problem.)
@shlevy Internally I've largely done the long-term implementation. 4 is sort of an anti-revert; I first rewrote stdenv/setup how it ought to be, more or less, and then added in some native-only hacks to avoid widespread breakage. 4 removes the stop gap hacks, bringing us closer to the ideal design.
Also important to know is the type of hacks in that commit I did can't readily be done with a legacy desugaring on top. If we rip the bandaid off I think we also need to fix a bunch of packages.
Right, but I mean the legacy wrapper can add extra things to PATH on top of what the core thing does. So we don't need to break things on the old setup.
@shlevy Well as I said above, I am a bit skeptical of being able to desugar. The PATH part is easy, for sure. The env hooks though.... I dunno. Not always sure if env hooks are effectively ideompotent if we end up running them on deps twice.
I've only seen the breakage in conjunction with other WIP cross stuff. Maybe if we set up a hydra job with just the rebuild it would be less bad than I fear. At the very least, it would be interesting to open a hydra job and then reevaluate the situation.
Activity
dtzWill commentedon Feb 25, 2018
Erm, generally the check for "is cross-compiling" is `hostPlatform != buildPlatform'.
The Nixpkgs manual helps explain these, although even so they're a bit hard to follow 😇.
However, from the manual,
nativeBuildInputs:So, for building perl that runs on RISC-V (host=riscv, build=x86_64), nativeBuildInputs will give you packages that are:
host == (new derivation's build) == x86_64 -- that is, it will run on the current builder
target == (new derivation's host) == RISC-V -- that is, the compiler will generate code for RISC-V.
So the fact that
nativeBuildInputs = [ ...compiler-package ];gives you a cross-compiler is not surprising.What is surprising is that
depsBuildBuild = [ ... ];doesn't work., since according to docs depsBuildBuild is:Actually, would
depsBuildBuild = [ gcc6 ]work? I think that's the intended usage?Anyway I think this is clearly a source of confusion and we should try to sort this out. Hopefully @Ericson2314 will be by soon :).
Ericson2314 commentedon Feb 26, 2018
Hi @shlevy. @dtzWill has it it right. Cross compilation adds not one but two extra stages: https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/cross/default.nix, giving us in total
You've a few times told me that I'm too trepid about extra rebuilds, but maybe this a good reason why :). By making as few packages as possible know about the target platform, I make stage 3 very small. (Vanilla final stage, crucially, is its own
buildPackages, which allows the cross tools stage target-platform-agnostic packages to be identical since `f (fix f) = f``.)Yeah it should work; if it doesn't that's a bug. One needs the
buildPackagesindepsBuildBuild = [ buildPackages.stdenv.cc ]only becausestdenvis a one a few attributes on a blacklist not to be spliced.dtzWill commentedon Feb 26, 2018
In my testing
depsBuildBuild = [ gcc6 ]did fix the perl problem, FWIW.(before the patch for
-fwrapvwas tracked down)Ericson2314 commentedon Feb 26, 2018
@shlevy
Elaborating on what I said above, this is actually not a hack.
stdenvis a very weird because all the packages in it (except forstdenv.libc) are actually drawn from the previous stage. Pretending we only havegcc:stdenv.cc == buildPackages.ccbuildPackages.stdenv.cc == buildPackages.buildPackages.ccEricson2314 commentedon Feb 26, 2018
@dtzWill sounds like it is working, then?
shlevy commentedon Feb 26, 2018
OK, this makes a lot more sense now. I've also been reading from the 17.09 manual, not the unstable manual, which made things even more confusing 😀
So yes, things are all working as expected and this is fine. A few things that I think might be better than the status quo:
targetPackagesnot actually being "packages which target your target" is very confusing.depsBuildBuildis a really confusing name.nativeBuildInputsshould mean "target-unaware" stuff and something new, likecrossBuildInputs, should be used if you need to explicitly include a cross-compiler whose host is the build-system.Proposal:
buildSystemInfo,systemInfo, andcrossSystemInfocorresponding tobuildPackages,pkgs, andcrossPackageswhich are selected fromnativeBuildInputs,buildInputs, andcrossBuildInputs. Ideally I'd like to make the latter setbuildInputs,inputs, andcrossBuildInputs.Ericson2314 commentedon Feb 26, 2018
Mmmm there is some symmetry / other logic in the existing names I want to lay out first before thinking about improvements:
depsBuildBuildis because there would be all combinations ofdeps{Build,Host,Target}{Build,Host,Target}satisfying the restriction that the second build/host/target is less than or equal the first, given the orderBuild < Host, Target. That gives us:depsBuildBuilddepsBuildHostdepsBuildTargetdepsHostHostdepsHostTargetdepsTargetTargetIts unfortunate, but unavoidable that there really is two axes here.
buildInputs == depsHostTargetandnativeBuildInputs == depsBuildHost. Only the legacy names are supports cause I need only one name in bash and it would be weird to rename.Ericson2314 commentedon Feb 26, 2018
It's "packages that run on your target.
buildPackagesis packages that run on your build.Ericson2314 commentedon Feb 26, 2018
Agreed, I hate splicing. I just didn't know an easier way to be backwards compatible.
But also, to be clear, we still need to distinguish the inputs for reasons other than splicing, namely env hooks and similar deps-processing-other-deps stuff. The only good thing about splicing besides back compat is it makes it sorta avoids using the wrong package set for the wrong dep since its (lamely) automatic.
Ericson2314 commentedon Feb 26, 2018
Ah so this would be like
depsBuildWhatever, in my naming scheme? I thought about that. Indeed the vast majority of packages don't care about the second axis. But I didn't want to make even more deps. andtarget = host + 1(of whichdepsBuildHostanddepsHostTargetare examples) is the sanest default if one has to be chosen.Ericson2314 commentedon Feb 26, 2018
To be clear,
depsBuildBuilddepsBuildHostanddepsBuildTargetall have the compiler's host as the current package's build. They differ in what the compiler's target is (the second axis).10 remaining items
shlevy commentedon Feb 27, 2018
Thanks for this summary! I think there are two action items here:
buildCPackage,buildHaskellPackage, etc. to be built on top of the new core design but with the per-package cross-compilation concerns more easily visible (and the handling of the cross-compiler itself abstracted away).Thoughts? Do you have a clear vision for 1? I can take a look at 2.
shlevy commentedon Feb 27, 2018
I definitely think we should use the
build/run/emitterms in the new infra, by the way.Ericson2314 commentedon Feb 27, 2018
That sounds good. I have a clear vision for 1, and some WIP work for Haskell you may be interested. I'd also like to brainstorm about how to do
ccWithPackagesetc in conjunction with 2.shlevy commentedon Feb 27, 2018
@Ericson2314 Can you outline your vision somewhere so we can start looking at 2 in parallel?
Ericson2314 commentedon Feb 27, 2018
For 1:
Make
mkDerivationa wrapper that desugars the legacy input names as proposed above.Move away from autoconf terminology (isomorphic renaming).
Make env hooks more coarse-grained, I see no use for the second axis for them.
Revert 469fd89#diff-7a1764865f30c6cb4c22c2654ebe9a38, ripping off the bandaid that makes packages with miscategorized dependencies work for native.
By default only allow references (immediate, not filtering to
depsHost*anddepsTarget*. I.e.nativeBuildInputsand friends will not be allowed to be referenced, unless those derivations are also listed as those other types of deps. This might require Nix modifications for per-output whitelists to accommodatedevoutputs. (@vcunat clued me into that problem.)shlevy commentedon Feb 28, 2018
@Ericson2314 Why do we need 4 if we're going to a new interface?
Ericson2314 commentedon Feb 28, 2018
@shlevy Internally I've largely done the long-term implementation. 4 is sort of an anti-revert; I first rewrote stdenv/setup how it ought to be, more or less, and then added in some native-only hacks to avoid widespread breakage. 4 removes the stop gap hacks, bringing us closer to the ideal design.
Also important to know is the type of hacks in that commit I did can't readily be done with a legacy desugaring on top. If we rip the bandaid off I think we also need to fix a bunch of packages.
shlevy commentedon Feb 28, 2018
@Ericson2314 Can't the legacy wrapper just have a phase where it sets PATH etc.?
Ericson2314 commentedon Feb 28, 2018
@shlevy Sure (though nix-shell would annoy people). But deciding what deps go on the PATH seems like an orthogonal question to when the PATH is built?
shlevy commentedon Feb 28, 2018
Right, but I mean the legacy wrapper can add extra things to PATH on top of what the core thing does. So we don't need to break things on the old setup.
Ericson2314 commentedon Feb 28, 2018
@shlevy Well as I said above, I am a bit skeptical of being able to desugar. The PATH part is easy, for sure. The env hooks though.... I dunno. Not always sure if env hooks are effectively ideompotent if we end up running them on deps twice.
shlevy commentedon Feb 28, 2018
Ah, OK.
Ericson2314 commentedon Feb 28, 2018
I've only seen the breakage in conjunction with other WIP cross stuff. Maybe if we set up a hydra job with just the rebuild it would be less bad than I fear. At the very least, it would be interesting to open a hydra job and then reevaluate the situation.
shlevy commentedon Mar 2, 2018
Broke out action items into #36217 #36218 and #36219