Skip to content

Conversation

RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented May 22, 2025

Things done

Introduce ccCross and ccCrossChooser since #365057 will make it easier to switch elements of the toolchain out. By localizing it to a specific mechanism similar to libcCross and libcCrossChooser, it simplifies the addition of new CC's.

This is necessary for working on the new crossStdenvs which will be added in to replace nixpkgs internally calling variants/sub nixpkgs instances.

  • 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/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (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.

@github-actions github-actions bot added the 6.topic: stdenv Standard environment label May 22, 2025
@RossComputerGuy RossComputerGuy force-pushed the feat/cc-cross branch 3 times, most recently from 316a0bb to 3e8311b Compare May 22, 2025 18:54
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 22, 2025
@emilazy emilazy requested a review from alyssais May 22, 2025 20:35
@emilazy
Copy link
Member

emilazy commented May 22, 2025

Shouldn’t something like buildPackages.stdenv.cc work for this?

@RossComputerGuy
Copy link
Member Author

I'm not sure what you mean.

@Ericson2314
Copy link
Member

I'm very skeptical of anything with "cross" in the name. I would need to read more, but that feels to me like a similar problem as variants.

@RossComputerGuy
Copy link
Member Author

The difference with this is it is only the stdenv, there's a lot of packages (like Steam) which need some sort of cross environment to invoke. I'm currently working on the machinery for crossStdenv, currently testing the replacement for pkgsCross.arm-embedded.stdenv which is crossStdenv.libc.newlib.configs.arm-none-eabi. As you can see by that name, it follows what was brought up at #400351 (comment).

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label May 26, 2025
@RossComputerGuy RossComputerGuy changed the title pkgs/top-level/all-packages.nix: add ccCross & ccCrossChooser pkgs/top-level/all-packages.nix: add cc & ccChooser May 26, 2025
@RossComputerGuy
Copy link
Member Author

I'm very skeptical of anything with "cross" in the name.

Cross is no longer in the name, this is now adding cc and ccChooser. This is aligning more with toolchain attrs and the stdenv redesign design doc.

@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 26, 2025
@nix-owners nix-owners bot requested a review from toonn May 26, 2025 03:33
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Oh I realized we shouldn't do this as is, because cc has the wrong host/target platform cross wise to be a tool in this package set. We should find some idiom to distinguish the tools for a package set from the packages in the package set .

@github-project-automation github-project-automation bot moved this to In Progress in Stdenv May 26, 2025
@RossComputerGuy
Copy link
Member Author

What makes the host/target platforms wrong for it to be used? I see it just needing to be pulled in like stdenv. We could have a cc and ccTarget. cc itself is meant to go from build -> target while ccTarget runs on the target.

@Ericson2314
Copy link
Member

stdenv.cc is already wrong in this regard, but stdenv is at least grandfathered in as a weird thing.

If I see cc, I assume we have something like cc = clang or cc = gcc, but in fact what we have is (after simplifying) cc = buildPackages.clang or cc = buildPackages.gcc. That is unlike, for example, how bintools is an alias.

@RossComputerGuy
Copy link
Member Author

Ok, that's fixed. It was actually quite simple to do that. You can verify this by looking at what pkgsCross.mingwW64.cc is versus cc versus stdenv.cc in the cross and host.

@Ericson2314
Copy link
Member

OK now it is consistent, but we have another problem, which is that there is not supposed to be just a single next stage. We want as few things to be "target" sensitive" as possible: so it doesn't really make sense to choose cc in the previous stage.

We do in fact want to choose it in the next stage, but not have it be part of that stage.

@RossComputerGuy
Copy link
Member Author

I'm not sure what you mean or how to fix that.

@Ericson2314
Copy link
Member

https://github.com/NixOS/nixpkgs/pull/21268/files#diff-7f30042ab97e5e7b73fd0e1f2fc383f9d373f70f48e4fa52e9e348eb7db9e2fe this is not quite the same, but basically I was thinking that each bootstrapping could be not a single package set, but a pair of package sets:

  1. Choosing tools/libraries from the previous stage, and applying wrappers to put them all together
  2. The packages built with those wrappers

The ideal goal would be for every proper package set (2) to be target-agnostic, and the only target-specific bits would be the wrappers that are in (1). At that point, we could get rid of stdenv.targetPlatform, since for (1) we are operating from the perspective of the "next" package set and can use stdenv.{build,host}Platform (which would be the host and target platforms of the wrappers themselves.

We won't get there quite a way, so we will have to keep stdenv.targetPlatform around for GCC and other single-target compilers, but we should be using it as little as possible. For things which are multi-target, (1) should be the only time targets are chosen.

If we do this, I believe your idea of making more cross stdenvs boils down to making a bunch of (1) on top of the last stage without a corresponding (2). That might be possible, though building libraries without a full (2) is a challenge.

As a practical matter, we might call (1) a __tools makeScope / sub-package set within the main stage for now, with the obscure name making clear that these are things with morally belong in the previous stage. splicedPackages would have to be updated so __tools is properly spliced (e.g. pkgsHostTarget.__tools overrides pkgsBuildHost for depsBuildHost).

@@ -8227,6 +8227,43 @@ with pkgs;
else
null;

# We can choose:
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment looks potentially incomplete? Or at least I don't understand what it is trying to convey beyond the rest of the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not incomplete, copies what libcCrossChooser says:

# We can choose:
libcCrossChooser =
name:

# NOTE: we shouldn't imply GCC, ideally we should either fallback, null, or error.
pkgs.gcc or fallback;

# The C compiler to use
Copy link
Contributor

Choose a reason for hiding this comment

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

"The C compiler to use" -- under what circumstances exactly? Is it a statement about the present or aspirational?

Do I understand that this takes precedence over what's in the standard stdenv? Does it actually do that on linux? I still see for example this (below), did it get missed?

cc = prevStage.gcc;

Copy link
Member Author

Choose a reason for hiding this comment

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

We will be dropping CC from the stdenv in the future so this is one of those steps. All future use of stdenv.cc should be replaced with cc. It is a part of the stdenv and CC wrapper redesign which has been discussed on the stdenv team Matrix.

Copy link
Contributor

@pwaller pwaller Jun 1, 2025

Choose a reason for hiding this comment

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

👍, I understand all that prior to making my comment and have read through the plan and the matrix chat - and I'm generally in favour.

My review comment follows from my belief that ideally, the code and its comments should reflect "the present" -- how things are at the point it is merged. It is confusing if someone is trying to understand how nixpkgs is wired, and they find a comment like this, but it does not currently reflect reality.

I understand the work has to be staged, but I hold a concern that if the work gets interrupted after the merge of this, the commentary in the code remain wrong/incomplete/misleading potentially for a long time. So the commit which makes the statement in the comment true should be the one adding the comment. Before that time, the comment should try to reflect what is true 'in the present', if that can be clarified.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so what should be changed then?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest either removing the comments (I don't think they're adding much as it is?) or elaborate them so that they precisely reflect the intent of the behaviour as it is currently on the master branch once this lands.

You could even include a reference to the design doc so that the intended development trajectory is clear - that would also lead to it being discoverable by those reading the sources, leading to increased collaboration/support/testing on the project.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the comment.

@RossComputerGuy RossComputerGuy mentioned this pull request Jun 5, 2025
13 tasks
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 9, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 10, 2025
@@ -8197,6 +8197,44 @@ with pkgs;
null;

# We can choose:
ccChooser =
platform: pkgs: fallback:
Copy link
Member

Choose a reason for hiding this comment

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

Rename to make this more self-explanatory.

Suggested change
platform: pkgs: fallback:
targetPlatform: hostPkgs: fallback:
  • pkgs.ccChooser (pkgs.stdenv.targetPlatform) pkgs null (where pkgs is what the returned CC targets)

or

Suggested change
platform: pkgs: fallback:
hostPlatform: buildPkgs: fallback:
  • pkgs.ccChooser (pkgs.stdenv.hostPlatform) pkgs.buildPackages null (where pkgs is what the returned CC will be running on)

Copy link
Member

@axelkar axelkar Aug 5, 2025

Choose a reason for hiding this comment

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

Is all-packages.nix really the place for this? Could there be a "Nixpkgs-specific lib"? This function doesn't reference outside variables but takes in pkgs so it's not really a fit for lib.

Or don't take pkgs as a parameter and do what libcCrossChooser does by referencing the with pkgs; at the top of the file.

libcCrossChooser could be simpler, here's how I picture it:

  • Currently: hello to buildPackages.clang to buildPackages.libcCross to buildPackages.targetPackages.bionic to buildPackages.targetPackages.stdenvNoCC
  • What it could be: hello to buildPackages.clang to buildPackages.targetPackages.libc to buildPackages.targetPackages.bionic to buildPackages.targetPackages.stdenvNoCC

Can someone explain this?

Edit: I was looking at a two-month old Nixpkgs clone.. But asking on the stdenv team's Matrix channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: stdenv Standard environment 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

6 participants