Commit graph

393 commits

Author SHA1 Message Date
John Ericson 8890f3b893
Merge pull request #203766 from obsidiansystems/build-rust-crate-link-flags
buildRustCrate: Support `cargo:rustc-link-arg` and some friends from build.rs
2022-12-06 21:48:07 -05:00
figsoda ff93685724
Merge pull request #199371 from figsoda/fetchCrate
fetchCrate: rewrite in terms of fetchzip
2022-12-05 18:15:33 -05:00
Sandro 4484c12d81
Merge pull request #196449 from natto1784/crate-overrides 2022-12-05 22:00:51 +01:00
John Ericson fde3b57055 buildRustCrate: Support cargo:rustc-link-arg and some friends from build.rs
See https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-link-argfor details. We are supporting:

 - `cargo:rustc-link-arg`
 - `cargo:rustc-link-arg-bins`
 - `cargo:rustc-link-arg-lib`

at this time.

`cargo:rustc-link-arg-bin` is left as future work because the per-binary
flag keeping is more difficult.
2022-11-30 11:40:50 -05:00
figsoda d3eb606296 rustPlatform.buildRustPackage: add useNextest option to check with cargo-nextest 2022-11-28 17:00:17 -05:00
figsoda 0643540f97 rustPlatform.cargoNextestHook: init 2022-11-28 16:59:52 -05:00
figsoda 82fe76d1cd carnix,cratesIO: remove 2022-11-22 14:10:25 -05:00
Artturin 341e6fd558 splice.nix: start deprecating nativeDrv and crossDrv 2022-11-19 00:04:54 +02:00
Aaron Andersen adbe2f532c
Merge pull request #199300 from Fuuzetsu/escape-rust-exports
rustBuildCrate: properly handle cargo env pragmas with spaces
2022-11-16 07:15:25 -05:00
github-actions[bot] 020ea91183
Merge master into staging-next 2022-11-10 00:02:27 +00:00
John Ericson e94d54dd86 build-support/rust/lib: Add toTargetFamily
Taken from https://github.com/kolloch/crate2nix/pull/255/files, it
belongs in Nixpkgs not crate2nix.

I have been using that P.R. for a few months without incident.
2022-11-09 15:52:01 -05:00
figsoda 9508a4ac68 fetchCrate: rewrite in terms of fetchzip 2022-11-03 12:33:27 -04:00
Mateusz Kowalczyk 233205c464
rustBuildCrate: properly handle cargo env pragmas with spaces
There are two problems: first that we end up splitting on spaces in the
loop. Even when that is fixed, we still would split on spaces in the
`export` inside the loop. We need to guard against both.

Fixes #199298

Confirmed that it fixes the case mentioned in the ticket:

```console
[nix-develop]$ $(nix-build -I nixpkgs=/home/shana/programming/nixpkgs Cargo.nix -A rootCrate.build  --no-out-link)/bin/nix-rustc-env-escape-repro
Expecting three words, got: first second third
```

I think this is going to cause a rebuild of every Rust package even if
they were unaffected, not much we can do here.
2022-11-03 14:49:24 +09:00
Yureka c2eaaae50d cargoSetupHook: pass host config flags 2022-10-30 18:55:47 +01:00
Amneesh Singh 74de121572
default-crate-overrides: add alsa-lib for alsa-sys crate
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-10-18 00:03:14 +05:30
Vladimír Čunát 6565abc264
Merge branch 'master' into staging-next 2022-10-08 10:20:07 +02:00
Alex Martens bac7ee3208 rustc: fix build for no_std targets 2022-10-07 07:35:29 -07:00
github-actions[bot] e879e7d54e
Merge master into staging-next 2022-10-02 00:04:43 +00:00
Vladimír Čunát 292756e9ff
Merge #190093: rustc: propagate libiconv on darwin
...into staging
2022-09-28 09:45:11 +02:00
figsoda dc19b95eff rustPlatform.buildRustPackage: remove unused function 2022-09-26 21:53:37 -04:00
Ivar Scholten 987d32bbac buildRustPackage: dont rely on NIX_BUILD_TOP in cargoSetupPostPatchHook
This breaks the builder when a nix-shell or keepBuildTree is used. The
issue occurs because paths to cargo lockfiles are read with NIX_BUILD_TOP,
which is not reliable.

This breaks a nix-shell because NIX_BUILD_TOP simply is not set, causing
an invalid path to be used. This can be worked around using
NIX_BUILD_TOP=$PWD, but that obviously is not great.

This breaks keepBuildTree because it changes the working directory to a
different path than NIX_BUILD_TOP. Since the lockfiles are copied based
on the working directory, but read based on NIX_BUILD_TOP, this causes
the hook to not be able to find them.

This was solved by both reading these files based on the working directory,
using absolute paths to avoid having to traverse back in the directory tree.

Fixes: #138554
2022-09-25 16:17:36 +02:00
Benjamin Hipple 1066f0ef92
Merge pull request #178964 from linsui/cargo
fetch-cargo-tarball: allow use index mirror
2022-09-17 12:04:27 -04:00
Winter b6fc00b8f4 rustc: propagate libiconv on darwin
Rust binaries are unconditionally linked to libiconv on Darwin (see https://github.com/rust-lang/libc/issues/2870). We already add it as a dependency in `buildRustPackage`, so let's go a step further and propagate it.
2022-09-06 23:17:56 -04:00
John Ericson 6a0d3815a3
Merge pull request #187975 from marius851000/rustRequiredFeatures
buildRustCrate: Do not compile binaries if all the requiredFeatures aren't enabled.
2022-08-25 17:45:52 -04:00
Bernardo Meurer fbd067fef0
Merge pull request #187841 from amjoseph-nixpkgs/pr/rust/toTargetArch
build-support/rust: toTargetArch: strip off endianness
2022-08-25 10:22:34 -03:00
marius david 3291bda7b6 buildRustCrate: Do not compile binaries if all the requiredFeatures aren't enabled. 2022-08-23 13:09:33 +02:00
Adam Joseph 8682bd0a81 build-support/rust: toTargetArch: strip off endianness
`toTargetArch` in `pkgs/build-support/rust/lib/default.nix` is used to
set `CARGO_CFG_TARGET_ARCH`.  This environment variable is supposed to
be the `<arch>` portion of an LLVM-style platform name:

```
<arch><sub>-<kernel>-<libc><abi>
```

Note that the pointer-width (the "64" in "x86_64" and "mips64") is
part of `<arch>`, but the endianness (the `_be` in `aarch64_be`) is
*not*.

Unfortunately at the moment nixpkgs' parsed `cpuType` has no way to
query for the three subparts (name, pointer-width, and
subarch/endianness), nor any way to ask for just the first two parts.

For now, this commit simply fixes the problem in the two cases that
matter: `mips64el` and `powerpc64le`, which I believe are the only two
platforms supported by both rust and nixpkgs which have a
"subarchitecture".
2022-08-22 02:27:06 -07:00
linsui 7d8f9ee62e build-rust-package: cargoSha256 and cargoHash must not be null 2022-08-21 17:09:09 +08:00
linsui 51a6ac79d2 fetch-cargo-tarball: fix for packages without dep 2022-08-21 16:28:28 +08:00
linsui 656e3022f4 fetch-cargo-tarball: allow use index mirror 2022-08-21 16:28:28 +08:00
github-actions[bot] 4e717ab958
Merge staging-next into staging 2022-08-15 06:01:47 +00:00
Adam Joseph 58e5bd56d6 default-crate-overrides.nix: add libevdev for evdev-rs 2022-08-14 21:20:55 -07:00
Yureka 51c62063e3 cargoSetupHook: set crt-static
Tell rust if we want our binaries linked statically or dynamically.
Otherwise the compiler will always produce statically linked binaries for musl
targets, as this is the default.
2022-08-13 15:25:41 +02:00
Yureka 66ac47bdf6 cargoSetupHook: remove unneeded rustflags for aarch64+static cross
The linked issue was resolved upstream and the `-lgcc` is no longer required
since https://github.com/rust-lang/compiler-builtins/pull/377 was merged.
2022-08-13 15:24:14 +02:00
John Ericson cc29693a09 buildRustCrate: Add support for standard library deps
We are replicating one mechanism behind `-Z build-std`.

There isn't yet crate2nix support for this, but one can (and I do) add
the missing stdlib deps (for this feature to pick up) with overrides.
2022-08-01 15:34:49 -04:00
Martin Weinelt b4988e25b5 maturin: 0.12.9 -> 0.13.0 2022-07-21 22:35:32 +02:00
John Ericson 39811b1da9 build-support/rust/lib: make arch and os functions respect target JSON 2022-07-18 22:54:19 -04:00
Ben Wolsieffer 882741f632 tests.buildRustCrate: add rcgen test
rcgen depends on ring, and therefore exercises support for static libraries
2022-06-14 20:09:33 -04:00
Ben Wolsieffer a6bbe3f794 buildRustCrate: pass link flags when building libraries
With Rust 1.61, it is necessary to link to external static/dynamic libaries
when building the rlib that uses them, rather than when linking the final
binary. In fact, it is no longer necessary to specify the libraries to link
when building the final binary, but the library search path flags must still
be included.
2022-06-14 20:09:33 -04:00
Artturin 9ca1379bdf fetchCargoTarball: allow adding nativeBuildInputs 2022-05-28 21:55:39 +03:00
Artturin 36ad5b9b96 buildRustPackage: add missing attr to remove
cargoUpdateHook is used in cargoDeps
2022-05-28 21:06:27 +03:00
sternenseemann 357da6c296 buildRustPackage: make cargoDeps logic easier to follow
The old logic flow had the structure

  if ( … ) {
    if ( … ) {
      …
    } else {
      …
    }
  } else {
    …
  }

which is quite hard to follow in Nix. Instead we ensure that no if
expression is inside a then branch.

This change is zero rebuild, as no logic was changed.
2022-05-13 08:18:39 +10:00
ilkecan d6bd313f07 buildRustCrate: set meta.mainProgram to crateName 2022-05-05 14:25:27 +00:00
David Scherer 13a9006ec3 Fix determinism by defaulting codegenUnits to 1, not NIX_BUILD_CORES 2022-05-01 11:48:32 -04:00
Mateusz Kowalczyk f6897d23f4 buildRustCrate: make codegen-units configurable
This parameter is being set to `$NIX_BUILD_CORES` by default. This is a
standard practice but there's a suspicion that this can produce broken
builds. For some details see
https://github.com/cargo2nix/cargo2nix/issues/184 . As a
work-around/test, it'd be good if codegen-units can be set to something
constant, such as `1`. This PR allows it.

Note that the default of `$NIX_BUILD_CORES` is preserved so this MR
causes no change in default behaviour and no rebuilds.
2022-05-01 11:48:32 -04:00
Yusuf Bera Ertan e2a3a3c690
default-crate-overrides: only add Security to propagatedBuildInputs on darwin for security-framework-sys 2022-04-28 21:24:46 +03:00
Faye Duxovni bc5e8ae506 buildRustCrate: don't try to set CARGO_FEATURE_ variables for dep: features
These features are internal-only, have special characters that bash
doesn't support in variable names, and aren't normally given
environment variables by cargo as far as I can tell.
2022-04-16 06:53:45 -04:00
sohalt 3619ffaeb6 rust: fix importCargoLock for repositories without toplevel Cargo.toml
Some crates do not have a Cargo.toml at the top-level, but only in
nested directories. Before this change importCargoLock used to fail with:

error: manifest path `/nix/store/some-store-path/Cargo.toml` does not exist
2022-03-17 00:15:56 -04:00
Guillaume Girol bedabfbcef rustPlatform.bindgenHook: init 2022-02-22 19:37:07 +01:00
github-actions[bot] b74b591fbe
Merge master into staging-next 2022-01-20 00:01:46 +00:00