819 Commits

Author SHA1 Message Date
Florian Klink
0f69ec1866 buildRustCrate: parallelize build_bin via Makefile jobserver (#503809) 2026-05-29 16:45:33 +00:00
Philip Taron
0c469218f3 build-support: remove assertMsg, throwIf, and throwIfNot usage (#524535) 2026-05-28 18:09:32 +00:00
Ryan Lahfa
d556754720 fetchCrate: download crates from static.crates.io (#525067) 2026-05-28 10:22:46 +00:00
Erin
e37f43a408 fetchCrate: download crates from static.crates.io 2026-05-27 18:32:45 -05:00
Philip Taron
e03d0a783d various: reduce // merges, optimize ++ chains across hot paths (#506793) 2026-05-27 22:06:37 +00:00
Philip Taron
f830e6112b rustPlatform.importCargoLock: download crates from static.crates.io
The crates.io API server's 1 req/sec rate limit currently surfaces as
intermittent HTTP 403 errors when vendoring lockfiles. Switch to the CDN
endpoint as recommended by upstream (rust-lang/crates.io#13482), mirroring
the fix already applied to fetchCargoVendor in #512735.

fetchurl is content-addressed by sha256, so the URL change does not affect
any downstream store paths.

Fixes #524979
2026-05-27 12:47:02 -07:00
Eman Resu
fded120b25 build-support/rust: remove assertMsg usage 2026-05-26 14:14:55 -04:00
Sigmanificient
0bbc8dffae treewide: set meta.license on hooks 2026-05-25 13:48:20 +02:00
K900
ef86c70442 rust.lib: restore required trailing \ (#519017) 2026-05-20 08:03:26 +00:00
Jörg Thalheim
c8abc5ea25 buildRustCrate: add extraRustcOptsForProcMacro (#512632) 2026-05-19 14:17:05 +00:00
Bernardo Meurer
127a52082d buildRustCrate: add extraRustcOptsForProcMacro
Proc-macro crates are host dylibs that rustc dlopen()s. Instrumentation
flags passed via extraRustcOpts (e.g. -Zsanitizer=address,
-Cinstrument-coverage) leave unresolved runtime symbols in those dylibs
and break the build. Cargo avoids this by not applying RUSTFLAGS to host
artifacts; buildRustCrate already has extraRustcOptsForBuildRs for build
scripts, so add the analogous knob for proc-macros.

Defaults to null, which falls back to extraRustcOpts so existing callers
are unchanged. Set to [] to opt proc-macros out when applying
sanitizer/coverage flags tree-wide via crateOverrides.
2026-05-19 14:09:04 +00:00
Aliaksandr
fbfe0b610e rust/hooks: replace // optionalAttrs with nullable attr names
Convert 5 identical optionalAttrs (stdenv.isLinux) for testCross
in cargo{Build,Check,Install,Nextest,Setup}Hook passthru.tests.
2026-05-18 03:54:27 +03:00
Gilberto Bertin
42955023b2 rust.lib: restore required trailing \
Commit c4f5dfad0d was intended as a stylistic cleanup, but the trailing \ it
removed from pkgs/build-support/rust/lib/default.nix was not stylistic: it is a
shell line continuation that joins the cross-only env var block to the cargo
command added by consumers. Without it, `CC_*`, `CXX_*`, and
`CARGO_TARGET_*_LINKER` are silently not passed to cargo when
rustTargetPlatform != rustHostPlatform.

This in turn can break cross compilation of Rust packages.

Fix it by adding back the trailing \

Fixes: #497857

Signed-off-by: Gilberto Bertin <me@jibi.io>
2026-05-11 14:02:03 +02:00
Ben Siraphob
869d641281 treewide: replace stdenv.is* with stdenv.hostPlatform.is* 2026-05-10 10:06:35 -07:00
Florian Klink
a2449ae281 buildRustCrate: support propagatedBuildInputs in crate overrides (#503956) 2026-05-09 11:50:38 +00:00
adisbladis
9e00f0c852 rustPlatform.fetchCargoVendor: Don't recompute internal data
Calling nix-prefetch-git.override on every call to fetchCargoVendor is bad for performance.
2026-04-29 23:01:43 +12:00
Colin
259aa5b226 rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding (#435239) 2026-04-28 16:07:38 +00:00
André Silva
46c5952578 rustPlatform.fetchCargoVendor: use static.crates.io in v2 2026-04-24 10:05:09 +01:00
André Silva
8209ba2bc6 rustPlatform.fetchCargoVendor: set custom User-Agent in v2 2026-04-24 10:04:37 +01:00
André Silva
6b5d6889f5 rustPlatform.fetchCargoVendor: copy fetch-cargo-vendor-util.py for v2 2026-04-24 10:03:05 +01:00
nixpkgs-ci[bot]
dcaefd38ef Merge master into staging-next 2026-04-21 00:32:14 +00:00
Ben Siraphob
5fadc89f02 treewide: remove empty buildInputs assignments 2026-04-20 10:34:26 -07:00
Luka Blašković
6f12c48b93 build-rust-crate: support propagatedBuildInputs in crate overrides
Add completePropagatedBuildInputs that collects propagatedBuildInputs
from a crate and all its transitive Rust dependencies, analogous to how
completeDeps chains .rlib paths. The collected inputs are appended to
buildInputs so native library deps (e.g. boost) declared on a library
crate automatically propagate to binary crates that depend on it,
without requiring repetition in every downstream crate override.
2026-04-10 06:46:36 +00:00
Jörg Thalheim
4d5eb32921 build-rust-crate: use synthetic .PHONY targets in generated Makefile
The Makefile generated for parallel binary builds used the binary names
directly as make targets. This caused make to silently skip a build
whenever a file or directory with the same name existed in the crate
source root — e.g. a crate with a `cli` binary and a `cli/` directory
would "succeed" without producing the binary.

Using the binary name as a target also risked collision with the `all`
meta-target and with make metacharacters (`$`, `:`, `#`) in user-supplied
crateName or bin.path values.

Switch to synthetic numeric targets (b0, b1, …) declared .PHONY, and
escape `$` in the recipe arguments.
2026-04-10 05:20:36 +00:00
Luka Blaskovic
365abadbdd build-rust-crate: parallelize build_bin via Makefile jobserver
Collect binary targets into a bash associative array (name→path), then
generate a Makefile on the fly and pipe it to `make -j`. Make handles
parallel execution and the jobserver protocol natively, so rustc
invocations share the same token pool via MAKEFLAGS.

Also fix build_bin error propagation: add `|| return 1` to the rustc
invocation so failures are not silently swallowed when the crate name
has no hyphens and the mv rename is skipped.
2026-04-10 05:20:32 +00:00
Randy Eckenrode
2a071a0471 Merge branch 'master' into staging-next 2026-04-07 21:13:06 -04:00
Winter
7cfe03948d buildRustCrate: set CARGO_BIN_EXE_<name> for integration tests (#502752) 2026-04-07 20:27:43 +00:00
Winter
e196301655 buildRustCrate: support Cargo.toml [lints] table (#502755) 2026-04-07 19:31:38 +00:00
Philip Taron
48c8b6fa40 rustPlatform.importCargoLock: use structuredAttrs instead of passAsFile (#502718) 2026-03-27 20:24:14 +00:00
Bernardo Meurer Costa
9fd2b8c767 buildRustCrate: set CARGO_BIN_EXE_<name> for integration tests
Cargo sets `CARGO_BIN_EXE_<name>` when compiling integration tests so
they can locate the crate's own binaries via `env!()` and exec them
as subprocesses. buildRustCrate previously compiled bin targets as
test harnesses only (via `--test`) when buildTests=true, so the real
binary never existed and the env var was never set.

When buildTests is set, now first build the real (non-test) binaries
to `target/cargo-bin-exe/`, install them to `$out/bin/`, and expose
`CARGO_BIN_EXE_<name>` to subsequent rustc invocations via an `env`
prefix. Using `env` rather than bash `export` is necessary because
hyphenated binary names (`CARGO_BIN_EXE_my-crate`) produce env var
names that bash rejects as invalid identifiers; `env` sets them via
execve's envp array directly and has no such restriction.

The env array is populated by iterating `target/cargo-bin-exe/` at
build time, so it covers all binary-target shapes: explicit `crateBin`
entries, auto-detected `src/main.rs`, and auto-detected `src/bin/*.rs`.
`build_bin` in lib.sh gains an optional third argument for the output
directory so the real binary and the `--test` harness can coexist
without colliding in `target/bin/`. The lib-test build is reordered to
after the real-bin build so its compilation also sees the env vars.
2026-03-24 19:28:20 +00:00
nixpkgs-ci[bot]
0ee1ac7a2c Merge staging-next into staging 2026-03-24 18:21:27 +00:00
Winter
48e5bec36d buildRustCrate: name tests/<dir>/main.rs binaries as <dir> to match cargo (#502733) 2026-03-24 17:49:09 +00:00
Michael Daniels
58d09c8cda Merge branch 'staging-next' into staging 2026-03-23 17:22:18 -04:00
Winter M
e71e4cae34 build-support/rust/build-rust-crate/configure-crate: fix using features that aren't valid Bash variable names
`cxx` has feature names like `c++20` [0], which are valid Cargo feature
names, but not valid Bash variable names.

[0]: https://docs.rs/crate/cxx/latest/features

Co-authored-by: davidscherer <dscherer1@gmail.com>
2026-03-23 16:48:07 -04:00
Winter M
9f65d4e778 build-support/rust/build-rust-crate/test: also test that we don't get the other crate's feature(s) in the environment 2026-03-23 16:36:00 -04:00
Bernardo Meurer Costa
7a399bb746 buildRustCrate: support Cargo.toml [lints] table
Cargo's `[lints]` table is a cargo-only feature: cargo translates the
entries into `-A`/`-W`/`-D`/`-F` rustc flags before invoking the
compiler. Since buildRustCrate calls rustc directly, these lints were
silently ignored, forcing users to duplicate them as raw flags in
`extraRustcOpts`.

Accept a `lints` attr with the same shape as the Cargo.toml section
(tool → lint name → level string or `{ level, priority }` attrset),
translate it to rustc flags in Nix, and append to the rustc command
line. Entries are sorted by ascending priority so lower-priority lint
groups are emitted first and can be overridden by more specific lints,
matching cargo's behaviour.

The `capLints` default changes from `"allow"` to `null`, resolved to
`"allow"` when `lints` is empty (the usual case for third-party
dependencies) and `"forbid"` when `lints` is set — otherwise a
`deny`/`forbid` lint would be silently capped and the table would be a
no-op. Explicit `capLints` still overrides. This is the same model
cargo uses: your own crate's `[lints]` always apply; only
dependencies get `--cap-lints allow`.

Generators like crate2nix can populate `lints` directly from the
manifest at generation time.
2026-03-23 18:26:40 +00:00
Bernardo Meurer Costa
4464997b95 buildRustCrate: name tests/<dir>/main.rs binaries as <dir> to match cargo
build_bin_test_file derives the test binary name by replacing `/` with
`_`, stripping the `tests_` prefix and `.rs` suffix. For the
subdirectory integration-test layout `tests/<dir>/main.rs`, this
produces `<dir>_main`, but cargo names that binary `<dir>` per its
auto-discovery rules. Tools that expect the cargo convention
(cargo-nextest binaries-metadata, IDE test runners) cannot find the
binaries.

Strip the trailing `_main` when the source file is `*/main.rs`. The
guard is needed so a flat-style `tests/<name>_main.rs` keeps its
suffix.

Add `expectedTestBinaries` to the test harness so binary naming can be
asserted, and cover both the subdir case (suffix stripped) and the
flat case with a literal `_main` in the filename (suffix kept). Also
fix a typo in `removeAttrs` that leaked `expectedTestOutputs` into the
crate args.
2026-03-23 17:25:43 +00:00
Winter
7a0d898a49 buildRustCrate: remap rustc store path to break rust-src closure leak (#502714) 2026-03-23 17:14:34 +00:00
Stefan Frijters
c3f361772d rustPlatform.importCargoLock: switch if/else statements
Now they are in the same order as the same check above
2026-03-23 18:03:30 +01:00
Stefan Frijters
4f9eda21d9 rustPlatform.importCargoLock: use structuredAttrs instead of passAsFile 2026-03-23 18:03:27 +01:00
Bernardo Meurer Costa
a523dd74ac buildRustCrate: make --cap-lints configurable
lib.sh previously hardcoded `--cap-lints allow` in both build_lib and
build_bin. Since rustc only honours the first `--cap-lints` it sees,
appending a different level via `extraRustcOpts` had no effect, making
it impossible to run clippy (or any lint-based tooling) through
buildRustCrate without wrapper scripts that strip the argument.

This adds a `capLints` parameter (default `"allow"`, preserving current
behaviour) that can be set per-crate or via `.override`:

    (myCrate { }).override { capLints = "warn"; }
2026-03-23 16:56:09 +00:00
Bernardo Meurer Costa
e85060f58c buildRustCrate: remap rustc store path to break rust-src closure leak
When the rust-src component is installed (common with rust-overlay
toolchains via rust-toolchain.toml), rustc unvirtualises libstd source
paths. Panic locations from monomorphised generic std code
(BTreeMap, VecDeque, sync primitives, etc.) then embed the toolchain
store path in .rodata, pulling the entire multi-GB toolchain into the
runtime closure.

This is not an RPATH issue — stdenv's patchelf --shrink-rpath already
cleans that. The reference is a core::panic::Location string.

Remap the rustc store path to /rustc so panic messages stay readable
but no longer create a store-path dependency. This is a no-op for
toolchains without rust-src (the prefix simply never matches).
2026-03-23 16:39:28 +00:00
Alyssa Ross
588ea6972e build-support/rustc-wrapper: use explicit substitution instead of substituteAll (#485294) 2026-03-23 13:48:09 +00:00
Victor Engmark
c4f5dfad0d treewide: Remove continuation escape at end of commands
To avoid confusion and spurious newlines in the output.

Found by searching for a backslash followed by a newline, some
indentation, and then the end of multi-line string marker, using the
following extended regex:

```regex
\\\n +'';
```
2026-03-17 16:47:55 +01:00
Stefan Frijters
499232e57b build-support/rustc-wrapper: use explicit substitution instead of substituteAll
The use of substituteAll is to be avoided and this fixes the wrapper
when structuredAttrs are enabled.
2026-03-13 14:56:45 +01:00
nixpkgs-ci[bot]
dee0edb980 Merge master into staging-next 2026-03-08 06:13:52 +00:00
Sandro
dfc5200370 rustPlatform.fetchCargoVendor: use gitMinimal; nix-prefetch-git: use normal git (#493713) 2026-03-08 02:07:06 +00:00
nixpkgs-ci[bot]
2286e14398 Merge staging-next into staging 2026-02-24 18:21:44 +00:00
Sandro Jäckel
45dc03c164 rustPlatform.fetchCargoVendor: use gitMinimal 2026-02-24 15:03:51 +01:00
Bryce Berger
92a51cfbfe rust: hooks: avoid fancy progress reporting by nextest
In [0.9.109], nextest added a `--show-progress=running` mode that
shows an interactive view of currently running tests. This is nice in
interactive use. However, it's very annoying when viewing logs after the
fact, such as through `nix log ...`.

`--show-progress=none` reverts to the simple interface, reporting a
single line for each test run with no control codes.

[0.9.109]: https://github.com/nextest-rs/nextest/releases/tag/cargo-nextest-0.9.109
2026-02-24 07:13:35 -05:00