Skip to content

rustPlatform.buildRustPackage: Pass env.RUSTFLAGS only when specified or needed to fix builds#464707

Merged
alyssais merged 1 commit intoNixOS:stagingfrom
ShamrockLee:build-rust-package-rustflags-unshadow
Nov 30, 2025
Merged

rustPlatform.buildRustPackage: Pass env.RUSTFLAGS only when specified or needed to fix builds#464707
alyssais merged 1 commit intoNixOS:stagingfrom
ShamrockLee:build-rust-package-rustflags-unshadow

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 24, 2025

Prevent shadowing RUSTFLAGS-like variables with lower priorities, such as mint-mod-mamanager's CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS.

Fixes #435278 (comment)

Fixes #464392

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@ShamrockLee ShamrockLee requested a review from gepbird November 24, 2025 21:46
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. labels Nov 24, 2025
Copy link
Contributor

@gepbird gepbird left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix, I tested this with the previously failing build which works now :)

@ShamrockLee
Copy link
Contributor Author

@gepbird I just noticed that the package is an ou-of-tree NUR package. Is the shadowing mechanism part of the package definition or part of the rustc behavior?

@gepbird
Copy link
Contributor

gepbird commented Nov 24, 2025

@gepbird I just noticed that the package is an ou-of-tree NUR package. Is the shadowing mechanism part of the package definition or part of the rustc behavior?

I'm fairly confident it's a rustc behaviour, but I'm not sure how to fully confirm that.

The environment variable is not specific to the package, but for compiling to windows, see #139966 (comment). However in that issue it looks like people are compiling a package to only a single platform, while for mint-mod-manager most of it is compiled to x86_64-linux, and a crate gets compiled to windows. (This half cross compilation is necessary, because the binary of the package runs on Linux, but it creates a Windows DLL that will be injected to the game, which is usually running with Steam Proton.)

@ShamrockLee ShamrockLee requested a review from a team November 25, 2025 05:49
SFrijters added a commit to SFrijters/nix-qemu-esp32c3-rust-example that referenced this pull request Nov 25, 2025
Caused by NixOS/nixpkgs#435278

RUSTFLAGS is now always set and overrides whatever we specify in .cargo/config.toml

TODO: Keep an eye on

NixOS/nixpkgs#464707
NixOS/nixpkgs#464992

and possibly revert or adjust to the new status quo in nixpkgs.
@ShamrockLee ShamrockLee force-pushed the build-rust-package-rustflags-unshadow branch from 3dfd0be to 947fda0 Compare November 26, 2025 20:24
@ShamrockLee ShamrockLee requested a review from gepbird November 26, 2025 20:24
@gepbird gepbird added the backport staging-25.11 Backport PR automatically label Nov 26, 2025
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 26, 2025
@ShamrockLee ShamrockLee marked this pull request as ready for review November 26, 2025 22:43
@nixpkgs-ci nixpkgs-ci bot requested review from winterqt and zowoq November 26, 2025 22:51
… or needed

Prevent shadowing RUSTFLAGS-like variables with lower priorities,
such as mint-mod-mamanager's
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS

Co-authored-by: Gergő Gutyina <gutyina.gergo.2@gmail.com>
@ShamrockLee ShamrockLee force-pushed the build-rust-package-rustflags-unshadow branch from 947fda0 to 978d298 Compare November 26, 2025 23:40
@ShamrockLee ShamrockLee changed the base branch from staging-next to staging November 26, 2025 23:40
@nixpkgs-ci nixpkgs-ci bot closed this Nov 26, 2025
@nixpkgs-ci nixpkgs-ci bot reopened this Nov 26, 2025
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Nov 26, 2025

Rebased from staging-next to staging and rebased onto the tip of the staging branch.

@nixpkgs-ci nixpkgs-ci bot removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 28, 2025
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Nov 28, 2025
${if args ? RUSTFLAGS || isDarwinDebug then "RUSTFLAGS" else null} =
lib.optionalString isDarwinDebug "-C split-debuginfo=packed "
# Workaround the existing RUSTFLAGS specified as a list.
+ interpolateString (args.RUSTFLAGS or "");
Copy link
Member

Choose a reason for hiding this comment

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

This is a good fix, but if you feel like putting in a bit more, even better would be not doing this in buildRustPackage to begin with — it's not the right place for it because plenty of Rust builds don't go through it. The rustc wrapper would be a much better place — it's universally used and doesn't need any environment variables to be modified.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaning toward addressing the simplification in a subsequent PR, as such change could introduce new incompatibility. (The existing change is a partial revert )

Would it be okay if we merge and backport this fix as-is?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's okay, at least it shouldn't be worse than the previous situation

Copy link
Member

Choose a reason for hiding this comment

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

@ShamrockLee still feel like making that subsequent PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ShamrockLee still feel like making that subsequent PR?

After looking into the buildRustPackage, I found the RUSTFLAG for buildRustPackagesituation to be quite different from GOFLAG for buildGoModule.

buildGoModule invokes cgo to build, which is also where GOFLAGS apply. We could specify the flags directly with our own flag lists (such as goBuildFlags).

buildRustPackage invokes cargo to build, but RUSTFLAGS apply to rustc (invoked by cargo). We cannot replace it with a flag list without stringifying to RUSTFLAGS first.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion was to put it in the rustc wrapper. Cargo invokes rustc through that wrapper.

@alyssais alyssais added this pull request to the merge queue Nov 30, 2025
Merged via the queue into NixOS:staging with commit 1a1526e Nov 30, 2025
51 of 98 checks passed
@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented Nov 30, 2025

@github-actions github-actions bot added the 8.has: port to stable This PR already has a backport to the stable release. label Nov 30, 2025
@brianmcgillion brianmcgillion mentioned this pull request Dec 1, 2025
13 tasks
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 3, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
@brianmcgillion brianmcgillion mentioned this pull request Dec 5, 2025
13 tasks
github-merge-queue bot pushed a commit that referenced this pull request Dec 6, 2025
…flags"

This reverts commit d2c6221.

This is no longer needed in staging due to the proper fix #464707 having been merged
nixpkgs-ci bot pushed a commit that referenced this pull request Dec 6, 2025
…flags"

This reverts commit d2c6221.

This is no longer needed in staging due to the proper fix #464707 having been merged

(cherry picked from commit ea27ed7)
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 7, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 11, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
@brianmcgillion brianmcgillion mentioned this pull request Dec 11, 2025
13 tasks
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 13, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 16, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
brianmcgillion added a commit to tiiuae/nixpkgs that referenced this pull request Dec 31, 2025
…flags (NixOS#464981)"

This reverts commit d2c6221.

PR NixOS#464981 changed libcosmicAppHook to use the global RUSTFLAGS instead
of target-specific CARGO_TARGET_*_RUSTFLAGS as a workaround for issue
PR NixOS#464392. However, this broke cross-compilation for packages using the
crabtime procedural macro (like cosmic-initial-setup).

The root cause was that buildRustPackage was always setting env.RUSTFLAGS,
which shadowed the target-specific flags. This has been fixed in commit
PR NixOS#464707, which only sets RUSTFLAGS when explicitly
needed.

Fixes cross-compilation of cosmic-initial-setup and other cosmic
packages that use crabtime proc macros.

Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons. backport staging-25.11 Backport PR automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants