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

Clean up cross bootstrapping #320852

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jun 18, 2024

Contains #320840, will recompute diff once that one is merged.

This will just be one commit then.

Description of changes

For a long time, we've had crossLibcStdenv, *Cross libc attributes, and *bsdCross pre-libc package sets. This was always bad because having "cross" things is "not declarative": the naming doesn't reflect what packages need but rather how we provide something. This is ugly, and creates needless friction between cross and native building.

Now, almost all of these *Cross attributes are gone: just these are kept:

  • Glibc's and Musl's are kept, because those packages are widely used and I didn't want to risk changing the native builds of those at this time.

  • generic libcCross, theadsCross, and friends, because these relate to the convolulted GCC bootstrap which still needs to be redone.

The BSD and obscure Linux or freestnanding libcs have conversely all been made to use a new stdenvNoLibc, which is like the old crossLibcStdenv except:

  1. It usable for native and cross alike

  2. It named according to what it is ("a standard environment without libc but with a C compiler"), rather than some non-compositional jargon ("the stdenv used for building libc when cross compiling", yuck).

I should have done this change long ago, but I was stymied because of "infinite recursions". The problem was that in too many cases we are overriding stdenv to remove things we don't need, and this risks cyles since those more minimal stdenvs are used to build things in the more maximal stdenvs.

The solution is to pass stage.nix stdenvNoCC, so we can override to build up rather than tear down. For now, the full stdenv is also passed, so I don't need to change the native bootstraps, but I can see this changing as we make things more uniform and clean those up.

Finally, the BSDs also had to be cleaned up, since they have a few pre-libc dependencies, demanding a systematic approach. I realized what @rhelmot did in 6120256 (specify what packages just need stdenvNoLibc) is definitely the right approach for this, and adjusted NetBSD and OpenBSD to likewise use it.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on label Jun 18, 2024
@github-actions github-actions bot added 6.topic: stdenv Standard environment 6.topic: lib The Nixpkgs function library and removed 6.topic: lib The Nixpkgs function library labels Jun 18, 2024
This is the most upstream one, and so to avoid infinite recursion we
should get the things from it. This isn't needed per-se now, but will be
after the next commit.
For a long time, we've had `crossLibcStdenv`, `*Cross` libc attributes,
and `*bsdCross` pre-libc package sets. This was always bad because
having "cross" things is "not declarative": the naming doesn't reflect
what packages *need* but rather how we *provide* something. This is
ugly, and creates needless friction between cross and native building.

Now, almost all of these `*Cross` attributes are gone: just these are
kept:

- Glibc's and Musl's are kept, because those packages are widely used
  and I didn't want to risk changing the native builds of those at this
  time.

- generic `libcCross`, `theadsCross`, and friends, because these relate
  to the convolulted GCC bootstrap which still needs to be redone.

The BSD and obscure Linux or freestnanding libcs have conversely all
been made to use a new `stdenvNoLibc`, which is like the old
`crossLibcStdenv` except:

1. It usable for native and cross alike

2. It named according to what it *is* ("a standard environment without
   libc but with a C compiler"), rather than some non-compositional
   jargon ("the stdenv used for building libc when cross compiling",
   yuck).

I should have done this change long ago, but I was stymied because of
"infinite recursions". The problem was that in too many cases we are
overriding `stdenv` to *remove* things we don't need, and this risks
cyles since those more minimal stdenvs are used to build things in the
more maximal stdenvs.

The solution is to pass `stage.nix` `stdenvNoCC`, so we can override to
*build up* rather than *tear down*. For now, the full `stdenv` is also
passed, so I don't need to change the native bootstraps, but I can see
this changing as we make things more uniform and clean those up.

Finally, the BSDs also had to be cleaned up, since they have a few
pre-libc dependencies, demanding a systematic approach. I realized what
rhelmot did in 6120256 (specify what
packages just need `stdenvNoLibc`) is definitely the right approach for
this, and adjusted NetBSD and OpenBSD to likewise use it.
Copy link
Contributor

@rhelmot rhelmot left a comment

Choose a reason for hiding this comment

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

This is so cool!

@@ -91,6 +88,9 @@ lib.makeOverridable (
// lib.optionalAttrs stdenv'.hasCC {
# TODO should CC wrapper set this?
CPP = "${stdenv'.cc.targetPrefix}cpp";

# Since STRIP below is the flag
Copy link
Contributor

Choose a reason for hiding this comment

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

The "below" here refers to makeFlags, should be changed now that it's not adjacent

@@ -81,6 +85,9 @@ lib.makeOverridable (
// lib.optionalAttrs stdenv'.hasCC {
# TODO should CC wrapper set this?
CPP = "${stdenv'.cc.targetPrefix}cpp";

# Since STRIP below is the flag
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

extraNativeBuildInputs = old.extraNativeBuildInputs
++ lib.optionals
(hostPlatform.isLinux && !buildPlatform.isLinux)
[ buildPackages.patchelf ]
Copy link
Contributor

Choose a reason for hiding this comment

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

What's up with this? I know it's just being moved, but who's asking for patchelf on literally everything?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose glass houses and so forth

@Ericson2314
Copy link
Member Author

In the interest of not waiting a long time for ofborg again, I will move those comments in a second PR.

@Ericson2314 Ericson2314 merged commit 2f20501 into NixOS:master Jun 20, 2024
26 checks passed
@Ericson2314 Ericson2314 deleted the fewer-cross-suffix-attrs branch June 20, 2024 14:44
@vcunat
Copy link
Member

vcunat commented Jun 21, 2024

@Ericson2314: how did you miss the ofBorg label that it rebuilds a stdenv?

@vcunat
Copy link
Member

vcunat commented Jun 21, 2024

51f1ecaa59a3 Clean up cross bootstrapping

This one rebuilds both *-darwin stdenvs. Let me revert the PR; you can redo it later.

vcunat added a commit to vcunat/nixpkgs that referenced this pull request Jun 21, 2024
It rebuilt stdenv on *-darwin; we can't do that in nixpkgs master.
This reverts commit 2f20501, reversing
changes made to fd469c2.
@Ericson2314
Copy link
Member Author

I am sorry @vcunat. I do not know how I missed that; there is no excuse.

71rd pushed a commit to 71rd/nixpkgs that referenced this pull request Jun 25, 2024
It rebuilt stdenv on *-darwin; we can't do that in nixpkgs master.
This reverts commit 2f20501, reversing
changes made to fd469c2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants