Skip to content

buildPackages should not know about the top-level targetPlatform #35543

Closed

Description

@shlevy

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.

Activity

  1. added
    0.kind: bug
    6.topic: cross-compilation
    6.topic: developer experience
    on Feb 25, 2018
  2. dtzWill commented on Feb 25, 2018

    @dtzWill
    Member

    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 :).

  3. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    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

    1. Vanilla bootstrap stages: build=native, host=native, target=native
    2. Vanilla final stage: build=native, host=native, target=native
    3. Cross tools stage: build=native, host=native, target=foreign
    4. Cross packages stage: build=native, host=target, target=target

    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.

  4. dtzWill commented on Feb 26, 2018

    @dtzWill
    Member

    In my testing depsBuildBuild = [ gcc6 ] did fix the perl problem, FWIW.

    (before the patch for -fwrapv was tracked down)

  5. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    @shlevy

    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:

    1. stdenv.cc == buildPackages.cc
    2. buildPackages.stdenv.cc == buildPackages.buildPackages.cc
  6. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    @dtzWill sounds like it is working, then?

  7. shlevy commented on Feb 26, 2018

    @shlevy
    MemberAuthor

    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:

    1. We need better names for these stages, despite their ubiquity. Especially targetPackages not actually being "packages which target your target" is very confusing.
    2. depsBuildBuild is a really confusing name.
    3. 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.

  8. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    Mmmm there is some symmetry / other logic in the existing names I want to lay out first before thinking about improvements:

    1. 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.
    2. 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.
  9. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    Especially targetPackages not actually being "packages which target your target" is very confusing.

    It's "packages that run on your target. buildPackages is packages that run on your build.

  10. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    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.

  11. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    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.

  12. Ericson2314 commented on Feb 26, 2018

    @Ericson2314
    Member

    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, depsBuildBuild depsBuildHost 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).

  13. 10 remaining items

  14. shlevy commented on Feb 27, 2018

    @shlevy
    MemberAuthor

    Thanks for this summary! I think there are two action items here:

    1. 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.
    2. 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.

  15. shlevy commented on Feb 27, 2018

    @shlevy
    MemberAuthor

    I definitely think we should use the build/run/emit terms in the new infra, by the way.

  16. Ericson2314 commented on Feb 27, 2018

    @Ericson2314
    Member

    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.

  17. shlevy commented on Feb 27, 2018

    @shlevy
    MemberAuthor

    @Ericson2314 Can you outline your vision somewhere so we can start looking at 2 in parallel?

  18. Ericson2314 commented on Feb 27, 2018

    @Ericson2314
    Member

    For 1:

    1. Make mkDerivation a wrapper that desugars the legacy input names as proposed above.

    2. Move away from autoconf terminology (isomorphic renaming).

    3. Make env hooks more coarse-grained, I see no use for the second axis for them.

    4. Revert 469fd89#diff-7a1764865f30c6cb4c22c2654ebe9a38, ripping off the bandaid that makes packages with miscategorized dependencies work for native.

    5. 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.)

  19. shlevy commented on Feb 28, 2018

    @shlevy
    MemberAuthor

    @Ericson2314 Why do we need 4 if we're going to a new interface?

  20. Ericson2314 commented on Feb 28, 2018

    @Ericson2314
    Member

    @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.

  21. shlevy commented on Feb 28, 2018

    @shlevy
    MemberAuthor

    @Ericson2314 Can't the legacy wrapper just have a phase where it sets PATH etc.?

  22. Ericson2314 commented on Feb 28, 2018

    @Ericson2314
    Member

    @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?

  23. shlevy commented on Feb 28, 2018

    @shlevy
    MemberAuthor

    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.

  24. Ericson2314 commented on Feb 28, 2018

    @Ericson2314
    Member

    @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.

  25. shlevy commented on Feb 28, 2018

    @shlevy
    MemberAuthor

    Ah, OK.

  26. Ericson2314 commented on Feb 28, 2018

    @Ericson2314
    Member

    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.

  27. shlevy commented on Mar 2, 2018

    @shlevy
    MemberAuthor

    Broke out action items into #36217 #36218 and #36219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

0.kind: bug6.topic: cross-compilation6.topic: developer experience

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions