Commit Graph

572 Commits

Author SHA1 Message Date
Ahmad Sattar
1cf6e5eaa1 buildRustCrate: add support for cargo::rustc-cdylib-link-arg 2024-07-01 09:29:46 +02:00
Ilan Joselevich
b561a29e4d
defaultCrateOverrides: add missing protobuf to crates 2024-06-21 18:21:39 +03:00
Ilan Joselevich
d9e5089751
Merge pull request #321220 from thehabbos007/cargo-colon
buildRustCrate: support new cargo invocation syntax for build script outputs
2024-06-21 14:21:47 +03:00
Ahmad Sattar
95bb410817 buildRustCrate: support cargo:: invocation syntax for build script outputs
In order to allow for the new `cargo::` prefix for build script outputs
we have to adjust the configure-crate bash scripts in buildRustCrate to
properly parse the new additional syntax.

These changes don't affect existing build scripts configured with the
old `cargo:` prefix.

For more information, see https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
2024-06-21 08:29:24 +02:00
Ahmad Sattar
fb927d5019
BuildRustCrate: proc macros must be built for build's platform
When cross compiling proc macros, the proc macro needs to be built for the
build platform's architecture.

Without this change cross compiling from Darwin to Linux would simply
fail because it tries to link to a library with a file extension that
doesn't exist on the builder's platform.
2024-06-20 14:35:49 +03:00
Ahmad Sattar
c730e033ca build-rust-crate: quote build script output env var 2024-06-14 10:23:28 +02:00
github-actions[bot]
14aa6e8765
Merge master into staging-next 2024-06-11 12:01:16 +00:00
Ilan Joselevich
de9a49c390 buildRustCrate: extensions.sharedLibrary -> extensions.library
Switched to a common attribute for library file extensions:
de70971c90

This makes buildRustCrate evaluate successfully when using
pkgsCross/pkgsStatic.
2024-06-11 11:27:17 +01:00
Alyssa Ross
4816a73bb5 rustPlatform: --frozen -> --offline
--frozen is stricter than we need in Nixpkgs.  If a Cargo.lock is
slightly wrong, or (in my use case) if building a subproject that is
not a member of the top-level workspace, but the correct Cargo.lock
can be entirely resolved from the existing top-level Cargo.lock, it
should be deterministic, and shouldn't cause any problems, to let
cargo generate the new Cargo.lock.  This should result in less need to
bother upstreams about fixing their Cargo.lock files in cases where
they could have been automatically fixed.
2024-05-18 11:18:59 +02:00
K900
f80228a805 build-support/rust: rewrite workspace dependency inheritance
This fixes at least one bug with default-features, and also
just aligns us more with what Cargo actually does.

Also some Python style fixes and a bit less mutating state.
2024-05-10 20:55:39 +03: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
lassulus
55205ec1a1
Merge pull request #302926 from helsinki-systems/fix/buildrustpackage-structuredattrs
cargoBuildHook: Fix features with __structuredAttrs
2024-04-16 23:10:26 +02:00
Olivia Crain
1348195416
tests.importCargoLock: fix self-inclusive src listings in .nix files
Replace `src = ./.` instances with more explicit source listings.
Otherwise, derivations will be rebuilt on any change to the files
defining them (e.g. formatting via nixfmt-rfc-style).
2024-04-10 10:27:12 -05:00
Janne Heß
6486868c28
cargoBuildHook: Fix features with __structuredAttrs 2024-04-10 09:24:17 +02:00
Alyssa Ross
6f8fa05acf
wrapRustc: wrap rustdoc
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)")
2024-03-02 13:09:07 +01:00
Alyssa Ross
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.
2024-02-28 23:10:07 +01:00
github-actions[bot]
6a27b0be74
Merge staging-next into staging 2024-01-29 18:01:37 +00:00
Ryan Lahfa
ec84d47ff6
Merge pull request #274440 from bouk/missing-build-rust-env
build-rust-crate: add missing CARGO_PKG env variables
2024-01-29 17:31:54 +01:00
Bouke van der Bijl
34ad6be1cd build-rust-crate: add missing CARGO_PKG env variables
See https://doc.rust-lang.org/cargo/reference/environment-variables.html
for supported variables
2024-01-28 18:59:53 +01:00
Ryan Lahfa
c34dd88211
Merge pull request #284307 from alyssais/rustc-sysroot=
wrapRustc: handle --sysroot=
2024-01-28 00:30:51 +01:00
Alyssa Ross
42b05f1c6d
wrapRustc: handle --sysroot=
This form is used by Linux 6.8.
2024-01-27 19:01:40 +01:00
Alyssa Ross
3bf20e5bf8
rust.envVars: use wrapped LLD for aarch64 musl
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.
2024-01-23 17:25:50 +01:00
Alyssa Ross
f3a07da669
rust: use pkgsBuildHost/pkgsTargetTarget
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.
2024-01-23 17:25:23 +01:00
Yureka
0eed8836c5 buildRustPackage: disable cargo-auditable on pkgsStatic aarch64 2024-01-15 22:34:02 +01:00
Yureka
48a6213611 rust: use lld on pkgsStatic aarch64 2024-01-15 22:34:02 +01:00
Yureka
b8076b893e rust: allow linker to be different from compiler 2024-01-15 22:34:02 +01:00
github-actions[bot]
28d4a2210a
Merge master into staging-next 2024-01-11 06:01:20 +00:00
Peter Kolloch
597f3d31d8 build-rust-crate: Allow missing hostPlatform.extensions.sharedLibrary
If you cross-build, sharedLibrary might not be set. E.g. for this
nixpkgs instance:

```nix
pkgs = import <nixpkgs> {
    config = { };
    crossSystem = {
        config = "riscv32-unknown-none-elf";
        rustc = {
            config = "riscv32i-unknown-none-elf";
        };
    };
}
```
2024-01-04 12:15:32 +01:00
K900
887e96e875 Merge remote-tracking branch 'origin/master' into staging-next 2024-01-02 10:55:23 +03:00
Lily Foster
5a8c65e118
rustPlatform.importCargoLock: fix workspace_root detection
Prior to this change, the `importCargoLock` git dependency builder
assumed that the workspace root that needed to be passed to
`replace-workspace-values` will always be the root directory of the git
repository.

This is not always the case as independent workspace roots may be used
from subdirectories, and packages be referenced via paths. An example of
this is [1], where the `iced` subdirectory is its own independent
workspace, and workspace values for packages within it should be pulled
from the `iced` subdirectory as the workspace root, not from the
top-level of the fetched repository.

[1]: b8f1a366dd/Cargo.toml
2023-12-21 19:40:43 -05:00
Martin Weinelt
8742c0cd2e
maturinBuildHook: use dist dir relative to cargoRoot
With `cargoRoot` set to a subdirectory of the source, where the
Cargo.{lock,toml} are found, the final mv would previously fail, since
the build results appear relative to cargoRoot, not to the original
build directory.
2023-12-20 20:46:08 +01:00
Alyssa Ross
ca8a6d8c19 wrapRustcWith: allow --sysroot to be overridden
It turns out that unlike a normal Unix program, if the --sysroot
option is given more than once, rustc will error rather than using the
last value given.  Therefore, we need to ensure we only add our
default --sysroot argument if one hasn't been given explicitly on the
wrapper's command line.

This fixes cross compilation of rustc.

Closes: https://github.com/NixOS/nixpkgs/issues/271736
Fixes: 8b51cdd3be ("rustc: add a compiler wrapper")
2023-12-19 11:34:02 +01:00
Artemis Tosini
285216aceb
rustPlatform.importCargoLock: copy lints from workspace
Rust 1.74 added support for configuring lints with cargo in a new
"lints" table. This also adds a new possible position to reference the
host workspace.

Fixes #273835
2023-12-16 05:36:59 +00:00
Alyssa Ross
8929ba838f rustc: use the wrapper for fastCross sysroot
This avoids having two layers of wrapper for cross rustc.
2023-11-30 09:23:06 +00: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
Ryan Lahfa
7e869d89ee
Merge pull request #266787 from tvbeat/cargo-manifest-links 2023-11-19 16:14:58 +01:00
Luka Blaskovic
8ffe19c099 build-rust-crate: set CARGO_MANIFEST_LINKS if links is set 2023-11-11 06:29:50 +00: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]
2fd5f8dd7a
Merge master into staging-next 2023-10-31 12:01:11 +00:00
Ryan Lahfa
b10994c38c
Merge pull request #220429 from amjoseph-nixpkgs/pr/build-rust-crate/cross/linker 2023-10-31 12:12:17 +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
Adam Joseph
3bd3809d0e buildRustCrate: 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 buildRustCrate.

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
github-actions[bot]
7909827752
Merge staging-next into staging 2023-10-12 00:02:50 +00:00
Alyssa Ross
7262026f0f
rustPlatform.cargoSetupHook: fix platform check (#260068)
Cargo will never need to link for the target platform — that'd be for
the package being built to do at runtime.  Cargo should know about the
build and host linkers.

This fixes e.g. pkgsCross.musl64.fd from x86_64-linux.

Fixes: 67a4f828b4 ("rust: hooks: fix cross compilation")
2023-10-11 23:36:56 +02: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
Fabián Heredia Montiel
2f0e87732c Merge remote-tracking branch 'origin/master' into staging-next 2023-10-08 10:14:51 -06: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
figsoda
14d44173e4
Merge pull request #256949 from andresilva/build-rust-package-profiles
buildRustPackage: support custom cargo profiles
2023-09-29 15:54:49 -04:00
Adam Joseph
67a4f828b4 rust: hooks: fix cross compilation
Currently there is a state of severe confusion in
pkgs/build-support/rust/hooks/ regarding host vs target; right now
there is only "host" defined, but whether it means "host" or
"target" seems to fluctuate.

This commit corrects that, ensuring that all variables come in all
three flavors (build, host, target) and are used consistently with
the nixpkgs convention.

This also fixes the cross-compilation of packages which use
`maturinBuildHook` -- hooks go in `nativeBuildInputs` and are
phase-shifted backwards by one platform, so they need to be careful
about distinguishing between build and host.

Closes #247441
2023-09-26 06:30:44 +00:00