rustdoc is built for native builds, because it's used to run doctests,
but it wasn't built for cross builds, since they don't run doctests.
This inconsistency led to wrapRustc not working for cross-compiled
rustc, because it expected there to be a rustdoc binary.
In the interests of consistency, let's instruct the build system to
always build rustdoc.
Link: https://github.com/NixOS/nixpkgs/pull/292777#issuecomment-2048071969
Fixes: 6f8fa05acf ("wrapRustc: wrap rustdoc")
The nixpkgs-unstable channel's programs.sqlite was used to identify
packages producing exactly one binary, and these automatically added
to their package definitions wherever possible.
Previously, trying to use `.override {}` on one of the hooks,
specifically `bindgenHook` would yield in an error.
By replacing `callPackage` with `callPackages`, this error is fixed and
the overrides are propagated to the hooks.
Co-Authored-By: Atemu <atemu.main+nixpkgs@gmail.com>
We need to set -crt-static on musl for rustdoc as well, so let's unify
the wrappers. Ideally, rather than wrapping rustdoc, we'd have
rustdoc use the wrapped rustc, but that's currently only possible with
an unstable option (--test-builder).
The options set by the wrapper, -C target-feature and --sysroot, are
supported by both rustdoc and rustc, but other flags maybe not be
supported by both, so I've introduced different environment
variables (the existing NIX_RUSTFLAGS and a new NIX_RUSTDOCFLAGS) to
allow those to be set independently.
This fixes cargo-auditable in pkgsMusl., which broke because its
doctests stopped working when -crt-static was moved to the wrapper.
Fixes: 79156bf13a ("rustc: move crt-static default override to wrapper (#291829)")
Previously, when cross compiling from non-musl to musl, the crt-static
default override wouldn't be applied, because the compiler wouldn't
have been built with it due to fastCross. Moving it to the wrapper
fixes this without having to introduce extra compiler rebuilds. And
because the wrapper is applied even to the bootstrap rustc, we no
longer need special handling of crt-static in the Cargo expression.
Unlike --sysroot, rustc allows -C target-feature= to be passed
multiple times, with later instances taking precedence over earlier
ones. This means that it's very easy to set the default in the
wrapper, just by our overridden default before any other arguments.
This fixes pkgsCross.aarch64-multiplatform-musl.mesa from x86_64-linux.
The unwrapped version doesn't know where to look for libraries, so
this is required to e.g. build anything that uses openssl-sys with
OPENSSL_NO_VENDOR. A randomly chosen example package that's fixed by
this change is pkgsStatic.gitoxide.
We're already using pkgsBuildBuild, and we'll soon be using
pkgsBuildTarget, so for consistency, change buildPackages and
targetPackages to their corresponding two-component names.
When building a cross-compiler, the rustc derivation does some tricks to
only build the standard library and reuse the host's compiler, leading
to much faster build time.
Unfortunately, the way the build system was invoked, it would always
build the `std` crate, whether or not the target supports it. Some
bare-metal targets only support building the `core` and `alloc` crates.
By being more vague about the build command, using `library` instead of
`library/std`, Rust's build system is able to figure out exactly which
crates to build:
https://github.com/rust-lang/rust/blob/1.74.1/src/bootstrap/compile.rs#L370-L412
Oddly enough, the install command still needs to use `library/std`, even
if building just a subset:
https://github.com/rust-lang/rust/blob/1.74.1/src/bootstrap/install.rs#L207
The following command was used to reproduce the original issue. Without
this patch, it leads to a build failure when trying to compile one of
std's dependencies. With the patch it completes succesfully and produces
a working cross-compiler.
nix build --impure --expr '(import ./. {
crossSystem = {
config = "riscv32-none-elf";
rustc.config = "riscv32imc-unknown-none-elf";
};
}).buildPackages.rustc'
Without the change `cargo` tests fail the eval as:
$ nix build --no-link -f. cargo.tests
error: attribute 'tests' missing
at pkgs/development/compilers/rust/cargo.nix:22:15:
21|
22| passthru = {
| ^
23| rustc = rustc;
The test teried to pull `tests` attribute from `rustc`, which is a
wrapper without `tests`. Pull tests from unwrapped rust instead.
Since wasm32-unknown-unknown doesn't require any extra
platform-specific dependencies (e.g. libc), we might as well just
always include in with rustc. We could also include other targets
fitting these criteria, but I wasn't able to find any others that
actually build (not even wasm64-unknown-unknown).
The old rustc-wasm32 package disabled documentation, but we don't
actually need to do that — we just need to allow for some broken links
in the wasm32-unknown-unknown documentation. Broken links in
documentation are an upstream issue anyway. There's no need we need
to fail our build for them.
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.
The BOOTSTRAP_ARGS patch is no longer necessary since
863d2fddd79 ("Pass `-jN` from Make to `BOOTSTRAP_ARGS`").
We now have to set sysconfdir, because since
350ead87205 ("add sanity checks for user write access on `x install`"),
the build system will check it can write there, even though nothing
actually gets installed there. (Previously it defaulted to /etc.)
This commit adds the machinery required to get our `rustc.nix` to
work using upstream's git repository, directly, without them waving
dead chickens over it and performing whatever other occult rituals
are involved in creating a release tarball.
No chickens, live or dead, were harmed in the creation of this
commit.
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.
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
The hash for pytensor is not correct, but that's also the case in
master, so a merge commit isn't the place to fix it.
Conflicts:
pkgs/development/python-modules/faadelays/default.nix
pkgs/development/python-modules/pytensor/default.nix
pkgs/tools/admin/rset/default.nix