Commit Graph

148 Commits

Author SHA1 Message Date
Sam Pointon
bd6051aa5f systems: also rename pkgsCross.wasi32, leaving aliases 2026-07-28 19:50:03 +01:00
Ilan Joselevich
1c56877f68 buildRustCrate: add useClippy parameter to lint with clippy-driver (#521993) 2026-06-16 16:08:42 +00:00
Bernardo Meurer
735734474f buildRustCrate: add useClippy parameter to lint with clippy-driver
buildRustCrate calls rustc directly, so there is no built-in equivalent
of `cargo clippy`. The capLints doc already hints at the existing
workaround — overriding the `rust` attribute with a wrapper script that
sniffs argv for build_script_build and routes everything else to
clippy-driver. That works because clippy-driver IS rustc internally
(rustc_driver plus lint passes) and produces compatible rlibs and
metadata, but the wrapper is fragile and every downstream reinvents it.

Add a `useClippy` boolean (default false) that swaps the lib/bin/test
compilation to clippy-driver while keeping plain rustc for build.rs —
the same lib-vs-build-script split as extraRustcOptsForBuildRs, since
build scripts are typically auto-generated and clippy noise there is
not actionable. The clippy-driver binary comes from a new `clippy`
parameter, auto-filled from pkgs.clippy by callPackage and overridable
alongside `rust` for toolchain bundles that ship their own.

Implemented by introducing a RUSTC_DRIVER shell variable in
build-crate.nix that lib.sh's build_lib/build_bin consume; the
build_script_build path in configure-crate.nix never sees it.

Note that the default `capLints = "allow"` cap suppresses clippy lints
along with everything else, so `useClippy` is usually paired with
`capLints = "warn"` and `-W clippy::*`/`-D warnings` flags via
extraRustcOpts. Documented in the manual.

Test fixtures cover the three load-bearing properties: a denied clippy
lint fails the build (proving clippy-driver ran), the default capLints
silences clippy lints just like rustc lints, and an rlib emitted by
clippy-driver is link-compatible with a plain-rustc dependent.
2026-05-19 13:46:16 -04: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
Alyssa Ross
b22e919f17 pkgsCross.wasi32.buildPackages.rustc: fix build (#463720) 2026-04-20 11:33:52 +00:00
PerchunPak
72b5a1c0e6 doc: add wasip1 rust package example 2026-04-20 11:31:28 +01: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
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
dramforever
8920a83327 doc/rust: Use rustcTargetSpec everywhere
Cargo uses the basename of a JSON target specification in various places
to refer to targets, cc-rs parses the basename to grab target
information. There may be other examples where the basename is relevant.

Instead of fighting these existing conventions, let's just recommend
users provide a rustcTargetSpec, either as a standard name or as a
custom JSON file with the right basename
2026-02-27 14:06:55 +08:00
Ben Siraphob
cc5b731ed3 doc: fix typos 2025-08-27 11:46:26 -07:00
Wolfgang Walther
62fe016519 treewide: run treefmt with mdcr/nixfmt 2025-07-24 13:52:31 +02:00
TomaSajt
8e87675994 doc/rust: pass cargoRoot to fetcher in example 2025-06-03 02:20:39 +02:00
awwpotato
76c5b6cc00 doc: remove useFetchCargoVendor 2025-04-26 15:26:20 -07:00
Pol Dellaiera
3218a4204f doc: do not reuse pname 2025-04-21 07:02:49 +02:00
Pol Dellaiera
ac04a5c492 doc: replace rev with tag 2025-04-21 07:02:49 +02:00
Pol Dellaiera
b4515ff6c2 doc: use finalAttrs pattern 2025-04-21 07:02:49 +02:00
Pol Dellaiera
bcea0cf344 doc: update Nix code snippets format
Command: `mdcr --config doc/tests/mdcr-config.toml doc/`
2025-04-17 01:30:34 +02:00
Winter
a19cd4ffb1 Revert "treewide: replace rev with tag"
This reverts commit 65a333600d.

This wasn't tested for correctness with something like fodwatch [0],
and should not have been (self-)merged so quickly, especially without
further review.

It also resulted in the breakage of at least one package [1] (and that's
the one we know of and was caught).

A few packages that were updated in between this commit and this revert
were not reverted back to using `rev`, but other than that, this is a
1:1 revert.

[0]: https://codeberg.org/raphaelr/fodwatch
[1]: https://github.com/NixOS/nixpkgs/pull/396904 / 758551e458
2025-04-08 02:57:25 -04:00
Pol Dellaiera
65a333600d treewide: replace rev with tag 2025-04-07 16:57:22 +02:00
Matt Sturgeon
39706cd65f doc: remove redundant fetchCargoVendor section
Was made redundant by 3e5b235146
2025-02-15 13:15:17 +01:00
Alyssa Ross
3e5b235146 doc: recommend fetchCargoVendor
Cargo 1.84.0 broke fetchCargoTarball hashes, so fetchCargoTarball is
not long for this world.  Tell people to use fetchCargoVendor, which
Nixpkgs is currently in the process of switching to across the tree.
2025-01-28 11:52:55 +01:00
TomaSajt
66855adbbf docs: mention fetchCargoVendor 2024-11-15 13:09:16 +01:00
jopejoe1
b0fecbaa2c docs: rust: Improve wording about adding Cargo.lock to src (#340287) 2024-11-07 00:44:16 +01:00
Bobby Rong
c0a9799ad1 tinysparql: Renamed from tracker
The project renamed in 3.8.

This commit is done by hand.
2024-10-14 20:54:11 +08:00
éclairevoyant
5c38beb516 doc/rust: prefer pname+version over name in fetchCargoTarball 2024-09-07 01:10:01 -04:00
Daniel Baker
3275f1af7d docs: rust: Improve wording about adding Cargo.lock to src
Improved the wording about adding the Cargo.lock file to src. It was not
clear when this operation was necessary.
2024-09-06 12:26:47 -07:00
Aleksana
fb3d86ee0d Merge pull request #330176 from raboof/docs-show-pyproject-instead-of-format
docs: show `pyproject = true;` instead of `format = "pyproject";`
2024-07-31 10:09:20 +08:00
Sigmanificient
aab1113d4a treewide: normalize maintainers list formatting
grep -rP 'maintainers = \[\];'
2024-07-30 16:26:22 +02:00
Arnout Engelen
b2d53203f2 docs: show pyproject = true; instead of format = "pyproject";
every other format is deprecated, so to imply that people should be setting it is misleading

(`pyproject = true` should also go away eventually, but is the way until
then)
2024-07-26 16:11:17 +02:00
Vladimír Čunát
577f40b8a9 Merge branch 'staging' into staging-next 2024-07-20 16:12:24 +02:00
Alexis Hildebrandt
ab42ca141a doc: Remove indefinite article and ending period from example meta.description
so that meta.description examples shown in the documentation
align with recommendations given in the "Meta attributes" section
in pkgs/README.md.

The changes were made with the following commands:
nix run nixpkgs#silver-searcher -- -l0 'description\s*=\s*"([Aa]n?|[Tt]he)\s' doc \
  | xargs -0 nix run nixpkgs#gnused -- -i '' -Ee '/description/s/"([Aa]n?|[Tt]he)\s(.)/"\U\2/'
nix run nixpkgs#silver-searcher -- -l0 'description\s*=\s*".*\."' doc \
  | xargs -0 nix run nixpkgs#gnused -- -i '' -Ee '/description/s/\."/"/'
2024-07-20 09:18:42 +02:00
aleksana
cb93149275 doc/rust: deprecate cargoSha256 2024-07-03 21:54:33 +08:00
Florian Klink
50261c0602 config.rust: update references from rustc
`rustc.config` is called `rust.rustcTarget` now, and
`{rustc -> rust}.platform`.

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

This updates both.
2024-06-13 21:08:48 +03:00
Janne Heß
fcc95ff817 treewide: Fix all Nix ASTs in all markdown files
This allows for correct highlighting and maybe future automatic
formatting. The AST was verified to work with nixfmt only.
2024-03-28 09:28:12 +01:00
Janne Heß
bc77c7a973 treewide: Mark Nix blocks in markdown as Nix
This should help us with highlighting and future formatting.
2024-03-28 09:28:12 +01:00
Aleksana
5616042a51 doc: add build rust package with meson example (#298881) 2024-03-25 21:45:19 +01:00
Anderson Torres
e671d3bbbd Nix docs: remove with lib; from example code
Following [Best Practices](https://nix.dev/guides/best-practices#with-scopes),
`with` is a problematic language construction and should be avoided.

Usually it is employed like a "factorization": `[ X.A X.B X.C X.D ]` is written
`with X; [ A B C D ]`.

However, as shown in the link above, the syntatical rules of `with` are not so
intuitive, and this "distributive rule" is very selective, in the sense that
`with X; [ A B C D ]` is not equivalent to `[ X.A X.B X.C X.D ]`.

However, this factorization is still useful to "squeeze" some code, especially
in lists like `meta.maintainers`.

On the other hand, it becomes less justifiable in bigger scopes. This is
especially true in cases like `with lib;` in the top of expression and in sets
like `meta = with lib; { . . . }`.

That being said, this patch removes most of example code in the current
documentation.

The exceptions are, for now
- doc/functions/generators.section.md
- doc/languages-frameworks/coq.section.md

because, well, they are way more complicated, and I couldn't parse them
mentally - yet another reason why `with` should be avoided!
2024-03-06 11:40:09 -03:00
Leon
0bb74f147b doc: small fix for nightly in derivation snippet (#292688) 2024-03-04 15:44:39 -08:00
Justin "J.R." Hill
0f7d690e48 doc: consistently prefer and lead with cargoHash over cargSha256 2024-02-08 15:41:32 -08:00
github-actions[bot]
dc4a7c97b0 Merge master into staging-next 2024-01-18 18:00:55 +00:00
Peder Bergebakken Sundt
e07a2fab7f stdenv: substituteStream: deprecate --replace in favor of --replace-{fail,warn,quiet} 2024-01-14 22:07:58 +01:00
Gabriel Lopes Rodrigues
d3a7f45716 doc: update buildRustPackage documentation
Fixes some mistakes regarding the references to cargoHash in the codes referenced.
Fixes a typo for cargoSha256.
States that cargoHash should be preferred.
2023-12-21 22:01:17 -03:00
Alyssa Ross
8b51cdd3be rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work.  (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)

So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.

Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable.  As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-11-30 09:23:06 +00:00
Adam Joseph
d43e8d5549 Update doc/languages-frameworks/rust.section.md
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2023-11-12 09:31:39 +00:00
Adam Joseph
ae7b2678f3 rust: add tutorial on git-bisecting rustc
This commits adds to the manual a tutorial showing how to
troubleshoot breakage caused by a rustc upgrade in *downstream*
packages.
2023-11-11 22:12:58 -08:00
Valentin Gagarin
61fa1255f8 link to documentation on IFD in the Nix manual 2023-10-09 23:57:03 +02:00
nicoo
fe138d36c9 doc: Replace sha256 with hash where appropriate 2023-09-13 17:24:49 +00:00
Jan Malakhovski
ccbb065c88 doc: make sourceRoot and setSourceRoot documentation match the implementation, fix examples 2023-08-03 16:32:05 +00:00
Paul Colomiets
366404a9d3 Remove tailhook from maintainers 2023-07-22 14:11:29 +03:00
Alyssa Ross
5e06b3cb19 treewide: don't use rustPlatform.rust
This will be deprecated in the next commit.
2023-05-12 15:31:21 +00:00