Skip to content

lib.systems.elaborate: fix passing rust (more)#271707

Merged
yu-re-ka merged 1 commit intoNixOS:masterfrom
alyssais:rustcTarget
Dec 3, 2023
Merged

lib.systems.elaborate: fix passing rust (more)#271707
yu-re-ka merged 1 commit intoNixOS:masterfrom
alyssais:rustcTarget

Conversation

@alyssais
Copy link
Member

@alyssais alyssais commented Dec 2, 2023

Description of changes

An important idea around the rust stuff in lib.systems is that it's elaborated — this means that it should idempotently add to the values passed in, if any. But we missed that the names used for the parameter and the elaborated value for "rustcTarget"/"config" didn't line up. The intention was to use "rustcTarget" everywhere in the new interface, as a more descriptive name than "config".

This fixes setting the system in NixOS configuration, which results in an already elaborated system being elaborated again. Before, this wouldn't produce the correct result:

% nix-instantiate --eval -A stdenv.hostPlatform.rust.rustcTarget --system armv7l-linux
"armv7-unknown-linux-gnueabihf"
% NIX_PATH= nix-instantiate --eval -E '(import nixos/lib/eval-config.nix { system = "armv7l-linux"; modules = []; }).pkgs.stdenv.hostPlatform.rust.rustcTarget'
"arm-unknown-linux-gnueabihf"

Fixes: #271000


Very technically, this is a backwards-incompatible change, as for about a couple of weeks it was accidentally possible to pass rust.config (as opposed to the old interface, rustc.config, which has been supported for years and continues to be until it's eventually removed after a deprecation period). This was unintentional, undocumented (the documentation still points people towards the old interface for now), only possible for a couple of weeks, and there was no reason to do it. If we really had to, we could do a proper deprecation period for the accidentally rust.config as well, but I don't think there's any reason to, and it would extend this whole project by six more months. But if the RMs really think we have to, we can.

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.05 Release Notes (or backporting 23.05 and 23.11 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.

Priorities

Add a 👍 reaction to pull requests you find important.

@alyssais alyssais requested review from a team, misuzu and yu-re-ka December 2, 2023 16:19
@alyssais alyssais requested a review from Ericson2314 as a code owner December 2, 2023 16:19
@alyssais alyssais requested a review from a user December 2, 2023 16:19
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Dec 2, 2023
Copy link
Contributor

@yu-re-ka yu-re-ka left a comment

Choose a reason for hiding this comment

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

This fixes the build of an armv7l cross NixOS for me.
Thanks!

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Dec 2, 2023
@RaitoBezarius
Copy link
Member

We should check out of tree Rust builders to see what they do regarding that.

@alyssais
Copy link
Member Author

alyssais commented Dec 2, 2023

We should check out of tree Rust builders to see what they do regarding that.

Regarding what exactly?

Copy link
Contributor

@misuzu misuzu left a comment

Choose a reason for hiding this comment

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

LGTM! Fixes both armv7l & riscv64 issue for me

@RaitoBezarius
Copy link
Member

We should check out of tree Rust builders to see what they do regarding that.

Regarding what exactly?

Regarding whether they pass rust.config or rustc.config if they setup cross compilation.

@alyssais
Copy link
Member Author

alyssais commented Dec 2, 2023

Regarding whether they pass rust.config or rustc.config if they setup cross compilation.

If they pass rustc.config, everything is fine. If they pass rust.config, they'd have to have started doing that since 2023-11-16, when it made it into master.

Which out-of-tree things do you think we should be checking?

@delroth delroth added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Dec 2, 2023
@RaitoBezarius
Copy link
Member

Regarding whether they pass rust.config or rustc.config if they setup cross compilation.

If they pass rustc.config, everything is fine. If they pass rust.config, they'd have to have started doing that since 2023-11-16, when it made it into master.

Which out-of-tree things do you think we should be checking?

crane, cargo2nix, naersk (?) are the ones on the top of my mind.

@alyssais
Copy link
Member Author

alyssais commented Dec 2, 2023

cargo2nix and naersk haven't had any changes since rust.config made it into Nixpkgs master, and I don't see anything relevant in the few commits crane has had in that time period.

@RaitoBezarius
Copy link
Member

In this case, this breaking change is exceptionally allowed because of no "popular" out-of-tree consumers maybe depending upon it.

An important idea around the rust stuff in lib.systems is that it's
elaborated — this means that it should idempotently add to the values
passed in, if any.  But we missed that the names used for the
parameter and the elaborated value for "rustcTarget"/"config" didn't
line up.  The intention was to use "rustcTarget" everywhere in the new
interface, as a more descriptive name than "config".

This fixes setting the system in NixOS configuration, which results in
an already elaborated system being elaborated again.  Before, this
wouldn't produce the correct result:

% nix-instantiate --eval -A stdenv.hostPlatform.rust.rustcTarget --system armv7l-linux
"armv7-unknown-linux-gnueabihf"
% NIX_PATH= nix-instantiate --eval -E '(import nixos/lib/eval-config.nix { system = "armv7l-linux"; modules = []; }).pkgs.stdenv.hostPlatform.rust.rustcTarget'
"arm-unknown-linux-gnueabihf"

Fixes: e3e57b8 ("lib.systems: elaborate Rust metadata")
Fixes: NixOS#271000
@delroth delroth removed the 12.approvals: 2 This PR was reviewed and approved by two persons. label Dec 2, 2023
@ofborg ofborg 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. labels Dec 2, 2023
@yu-re-ka yu-re-ka merged commit 9731208 into NixOS:master Dec 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2023

Successfully created backport PR for release-23.11:

@andresilva
Copy link
Member

This change broke rustc-wasm32. Here's the error while trying to build rustc:

rustc> thread 'main' panicked at 'Target "wasm32-unknown-wasi" does not have a "wasi-root" key', compile.rs:295:17
rustc> note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
rustc> Build completed unsuccessfully in 0:00:11
rustc> make: *** [Makefile:12: all] Error 1

@alyssais
Copy link
Member Author

alyssais commented Dec 4, 2023

Ah yes, whoops, we had an in-tree use of rust.config.

@alyssais alyssais deleted the rustcTarget branch December 4, 2023 11:55
alyssais added a commit to alyssais/nixpkgs that referenced this pull request Dec 4, 2023
rust.config was never intended to exist, and has been removed.

Link: NixOS#271707 (comment)
Fixes: 9731208 ("lib.systems.elaborate: fix passing `rust` (more) (NixOS#271707)")
@alyssais alyssais mentioned this pull request Dec 4, 2023
13 tasks
github-actions bot pushed a commit that referenced this pull request Dec 4, 2023
rust.config was never intended to exist, and has been removed.

Link: #271707 (comment)
Fixes: 9731208 ("lib.systems.elaborate: fix passing `rust` (more) (#271707)")
(cherry picked from commit a449e06)
alyssais added a commit that referenced this pull request Dec 5, 2023
rust.config was never intended to exist, and has been removed.

Link: #271707 (comment)
Fixes: 9731208 ("lib.systems.elaborate: fix passing `rust` (more) (#271707)")
(cherry picked from commit a449e06)
@mikatammi mikatammi mentioned this pull request Dec 6, 2023
13 tasks
bendlas pushed a commit to bendlas/nixpkgs that referenced this pull request Dec 8, 2023
rust.config was never intended to exist, and has been removed.

Link: NixOS#271707 (comment)
Fixes: 9731208 ("lib.systems.elaborate: fix passing `rust` (more) (NixOS#271707)")
Kranzes added a commit to Kranzes/crate2nix that referenced this pull request Jun 11, 2024
flokli added a commit to flokli/nixpkgs that referenced this pull request Jun 13, 2024
`rustc.config` is called `rust.rustcTarget` now, and
`{rustc -> rust}.platform`.

This is the new way (tm), and is preferred since
NixOS#271707 -
though the documentation still is outdated, and some expressions in
nixpkgs were using the old interface.

This updates both.
@flokli
Copy link
Member

flokli commented Jun 13, 2024

I updated the docs and remaining references to rustc in #319624.

github-actions bot pushed a commit to nix-community/nixpkgs.lib that referenced this pull request Jun 16, 2024
`rustc.config` is called `rust.rustcTarget` now, and
`{rustc -> rust}.platform`.

This is the new way (tm), and is preferred since
NixOS/nixpkgs#271707 -
though the documentation still is outdated, and some expressions in
nixpkgs were using the old interface.

This updates both.
Kranzes added a commit to Kranzes/crate2nix that referenced this pull request Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 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

None yet

Development

Successfully merging this pull request may close these issues.

Different stdenv.hostPlatform.rust.rustcTarget with and without NixOS system

7 participants