82 Commits

Author SHA1 Message Date
Eman Resu fded120b25 build-support/rust: remove assertMsg usage 2026-05-26 14:14:55 -04:00
Colin 259aa5b226 rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding (#435239) 2026-04-28 16:07:38 +00:00
Yueh-Shun Li 04c3e0defa rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding
Make `<rust-package>.cargoDeps` reference the overridden
`<rust-package>.src` and other attributes.

Let `stdenv.mkDerivation` handle the name of `<rust-package>.cargoDeps`.

Make Rust package overriding *possible*
before making further design decisions about the
`<pkg>.overrideAttrs` interface.
2025-12-18 19:23:12 +08:00
Yueh-Shun Li 978d298b4b rustPlatform.buildRustPackage: Pass env.RUSTFLAGS only when specified 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>
2025-11-27 07:39:59 +08:00
Yueh-Shun Li cdb722fa01 rustPlatform: run cargoDepsHook inside cargoSetupPostUnpackHook 2025-11-04 05:25:30 +08:00
Yueh-Shun Li 56a5fc5c78 rustPlatform.buildRustPackage: specify environment variables via the env attribute 2025-11-04 05:25:30 +08:00
Niklas Korz 8e59ce1e26 buildRustPackage: warn on explicit useFetchCargoVendor 2025-07-26 12:29:36 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
TomaSajt bca30d8653 rustPlatform.buildRustPackage: don't pass down useFetchCargoVendor
This way we can remove all usages in a treewide without having
mass rebuilds
2025-07-01 19:46:57 +02:00
Winter 1000a826eb buildRustPackage: remove redundant libiconv dependency on darwin 2025-05-15 15:44:20 -04:00
Emily 7cf0473ccd rustPlatform.fetchCargoTarball: drop 2025-03-28 15:09:52 +00:00
Yueh-Shun Li 21b547670c buildRustPackage: simplify the cargoDeps specification and remove dead code (#384345) 2025-02-25 14:42:12 +08:00
Yueh-Shun Li 89c72ca6a2 buildRustPackage: simplify the cargoDeps specification 2025-02-25 00:27:11 +08:00
Yueh-Shun Li 57793b8ca7 rustPlatform.buildRustPackage: drop cargoSha256 2025-02-24 02:59:04 +08:00
Yueh-Shun Li d84d1eeb22 buildRustPackage: remove ineffective extendDrvArgs element
cargoDeps gets shadowed in the implementation
whether or not it is excluded.
2025-02-23 04:57:01 +08:00
Yueh-Shun Li ef987dba19 buildRustPackage: remove dead codes 2025-02-23 04:55:52 +08:00
Yueh-Shun Li 721751bd23 buildRustPackage: reformat after refactoring 2025-02-21 00:44:21 +08:00
Yueh-Shun Li 7609cbad7c buildRustPackage: restructure with lib.extendMkDerivation
Support fixed-point arguments with lib.extendMkDerivation

Postpone formatting for more concise diff.
2025-02-21 00:42:27 +08:00
Yueh-Shun Li 016ba92a43 buildRustPackage: avoid global assertions
Move assertions down to the corresponding attribute value.

Avoid adding assertions to the whole argument set.
2025-02-21 00:42:27 +08:00
nixpkgs-ci[bot] 9e06c2d43e Merge staging-next into staging 2025-02-02 00:15:30 +00:00
DavHau db4cf6cb1d rust: fix splicing for rust hooks
This fixes a long standing issue where rust hooks behave differently when used inside buildRustPackage vs inside mkDerivation, which lead to surprising behavior, like for example the package being built for the wrong paltform or the linker not being found especially in cross compilation scenarios.

The reason for this inconsitency was, that buildRustPackage consumed the hooks in a non-spliced form, via [this inherit statement](https://github.com/NixOS/nixpkgs/blob/4506ece030a0c82d078edd0360ea8af6b4d94035/pkgs/development/compilers/rust/make-rust-platform.nix#L60), and therefore the usual platform shift on the hooks introduced by putting them in `nativeBuildInputs` was not applied here.

Thoug whenever the hook was used inside other builders like `mkDerivation` the platform shift did apply correctly as the hook was consumed via the spliced package set, introducing the inconsitecy.

Because of the wrong (non-spliced) use in buildRustPackage, most rust hooks have been designed with the wrong build/host/target shift in mind which is fixed by this change.

Due to the inconsitent behavior between different builders, workarounds like `rust.envVars`, which were previously introduced, likely become obsolete by this change.

This likely fixes a bunch of cross compilation issues for rust packages that are not based on `buildRustPackage` but instead consume the hooks directly.

Done:
- ensure that `buildRustPackage` consumes spliced hooks by using makeScopeWithSplicing' in make-rust-platform.nix.
- refactor hooks to make them refer to correct build/host/target packages.
- remove `rust.envVars` workaround from all rust hooks
- implement tests for most rust hooks in /pkgs/test/rut-hooks

The newly added tests can be executed for native as well as cross compilation via:
```
nix-build -A tests.rust-hooks -A pkgsCross.riscv64.tests.rust-hooks
```
2025-01-31 18:18:46 +07:00
Alyssa Ross c8127fc287 build-support/rust/sysroot: remove
The sysroot derivation used by buildRustPackage hasn't built since
c263e0b33b ("cargo,clippy,rustc,rustfmt: 1.81.0 -> 1.82.0").  That
means that it's never built on 24.11, so there can't be anybody
relying on it working on any supported version Nixpkgs.  In the
meantime, it's causing maintenance friction — I've spent a lot of time
trying to figure out how to build it as part of the transition away
from fetchCargoTarball, before realising that it doesn't work anyway
and must be unused.  It can come back in the future if somebody wants
to maintain it.
2025-01-30 16:24:14 +01:00
Silvan Mosberger 84d4f874c2 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 78e9caf153
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:23:58 +01:00
github-actions[bot] df7560310e Merge staging-next into staging 2024-12-03 12:06:35 +00:00
TomaSajt 16f30cf210 {buildRustPackage,fetchCargoTarball,fetchCargoVendor}: respect cargoRoot 2024-12-02 22:10:23 +01:00
github-actions[bot] 8cfd862ce8 Merge staging-next into staging 2024-11-27 12:06:39 +00:00
TomaSajt 455241a036 buildRustPackage: fix passing depsExtraArgs to fetchCargoVendor 2024-11-26 08:48:06 +01:00
github-actions[bot] 468547492b Merge staging-next into staging 2024-11-22 18:05:01 +00:00
Robert Schütz 6c4d710b94 rustPlatform.buildRustPackage: allow specifying cargoDeps 2024-11-19 10:47:22 -08:00
github-actions[bot] 357e63084b Merge staging-next into staging 2024-11-17 12:05:34 +00:00
Masum Reza e13831335f treewide: stdenv.is -> stdenv.hostPlatform.is (#356363)
* treewide: stdenv.is -> stdenv.hostPlatform.is

* treewide: nixfmt due to ci error
2024-11-17 16:11:54 +05:30
github-actions[bot] c18163d1b3 Merge staging-next into staging 2024-11-16 06:04:43 +00:00
TomaSajt 37ce479c7b buildRustPackage: add useFetchCargoVendor flag 2024-11-15 13:09:16 +01:00
TomaSajt 4b712c8f6f buildRustPackage: remove unused patchRegistryDeps 2024-11-11 19:53:33 +01:00
Julius Michaelis c4c95cac81 Revert "buildRustPackage: disable cargo-auditable on pkgsStatic aarch64"
This reverts commit 0eed8836c5.
2024-10-17 22:17:39 +02:00
Jörg Thalheim a50dabe867 rustPlatform.buildRustPackage: provide debug symbols on darwin (#327136) 2024-09-21 18:30:46 +02:00
Alyssa Ross 0852f8eb84 rustc: expose platform lists
Previously, it wasn't possible to access the list of platforms we can
build Rust programs for outside of buildRustPackage.  This was a
problem for packages that have optional Rust components, like
gstreamer or Meson, as there was no way to only build the Rust parts
for supported platforms.  Now it's possible to get that information
from rustc's passthru.
2024-09-03 17:47:27 +02:00
Alyssa Ross 2ade30b7af rustPlatform.buildRustPackage: merge custom platforms
We should constrain the set of supported platforms to the platforms
supported by the compiler.  Otherwise we run into the unfortunate
situation where setting meta.platforms in a Rust package to
platforms.unix or platforms.linux will reintroduce CPU architectures
unsupported by the compiler.
2024-09-02 08:58:07 +02:00
Nathan Henrie 16f3c7ebcb rustPlatform.buildRustPackage: provide debug symbols on darwin
Currently we cannot debug rust binaries on darwin (via lldb).

The debug symbols seem to be provided by default in a number of files
in `target/debug/deps/*.rcgu.o`. As far as I can tell these have
hardcoded paths referring to the ephemeral build directory. However,
`split-debuginfo=packed` conveniently produces a `.dSYM` file that can
be copied to `$out/bin/` and immediately provide debugging information.

Fixes https://github.com/NixOS/nixpkgs/issues/262131
2024-08-23 13:07:16 -06:00
aleksana 07fddc62e4 buildRustPackage: deprecate cargoSha256 in favor of cargoHash 2024-07-03 21:54:26 +08:00
aleksana a9709c299b treewide: change cargoSha256 with SRI hash to cargoHash 2024-07-03 21:53:11 +08:00
Alyssa Ross 6d4a14504e buildRustPackage: add new supported platforms
The new NetBSD platforms have appeared since last time I updated this
list, but it looks like I just missed the MIPS linux ones last time.
2024-05-10 10:18:20 +02:00
Yureka 0eed8836c5 buildRustPackage: disable cargo-auditable on pkgsStatic aarch64 2024-01-15 22:34:02 +01:00
Alyssa Ross e3e57b8f18 lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.

This has a couple of other advantages:

 - It makes Rust less special.  Now figuring out what Rust calls a
   platform is the same as figuring out what Linux or QEMU call it.

 - We can unify the schema used to define Rust targets, and the schema
   used to access those values later.  Just like you can set "config"
   or "system" in a platform definition, and then access those same
   keys on the elaborated platform, you can now set "rustcTarget" in
   your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
   in your code.

"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized.  The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.

The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.

The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11.  We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-11-09 10:02:24 +01:00
github-actions[bot] 2c2c0379b7 Merge staging-next into staging 2023-10-23 12:02:04 +00:00
Adam Joseph 4fc0e33698 buildRustPackage: add isMips64n32 to badPlatforms
Rust is not yet able to target the n32 ABI on mips64.

Let's add `isMips64n32` to the `meta.badPlatforms` of all
derivations created by buildRustPackage.

I use this to automatically detect which packages on my system can
be built for n32 (almost all of them) and build those using n32, and
the few packages (mainly those that depend on boost or rust) that
can't for n64.
2023-10-23 08:38:25 +00:00
Alyssa Ross c11cb00a1e rustc: 1.72.1 -> 1.73.0
This upgrade unfortunately removes MIPS support, as it has been
dropped to Tier 3[1] and so bootstrap tarballs are no longer provided.

It looks like it was dropped due to multiple codegen bugs, and lack of
maintenance, so bringing it back would probably involve engaging with
Rust/LLVM upstream on those.

[1]: https://github.com/rust-lang/compiler-team/issues/648
2023-10-10 14:42:30 +00:00
Alyssa Ross 1cbe5c3e8b rust.toRustTargetForUseInEnvVars: support custom targets
> If using a target spec JSON file, the <triple> value is the filename
> stem. For example --target foo/bar.json would match [target.bar].

- https://doc.rust-lang.org/cargo/reference/config.html#target

I've also exposed toRustTargetSpecShort as a public function, because
it's useful to be able to know what the target subdirectory will be.
2023-10-03 12:30:04 +00:00
André Silva 8674922276 buildRustPackage: support custom cargo profiles 2023-09-24 18:40:24 +01:00
Guillaume Girol f8602fa508 Revert "build-rust-{crate,package}: cleanups" 2023-06-18 09:27:44 +00:00