2021-10-19 19:59:28 -04:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
importCargoLock,
|
|
|
|
fetchCargoTarball,
|
2024-10-21 22:21:06 +02:00
|
|
|
fetchCargoVendor,
|
2021-10-19 19:59:28 -04:00
|
|
|
stdenv,
|
|
|
|
callPackage,
|
2021-02-11 17:32:47 +01:00
|
|
|
cargoBuildHook,
|
2021-02-15 10:26:40 +01:00
|
|
|
cargoCheckHook,
|
2021-02-15 06:54:18 +01:00
|
|
|
cargoInstallHook,
|
2022-11-28 17:00:17 -05:00
|
|
|
cargoNextestHook,
|
2021-02-09 11:38:25 +01:00
|
|
|
cargoSetupHook,
|
2023-01-12 12:22:07 -05:00
|
|
|
cargo,
|
2022-12-04 20:52:06 -05:00
|
|
|
cargo-auditable,
|
2023-04-24 17:30:05 +00:00
|
|
|
buildPackages,
|
2020-05-06 21:03:41 -04:00
|
|
|
rustc,
|
2021-05-07 23:36:21 +02:00
|
|
|
libiconv,
|
2020-05-06 21:03:41 -04:00
|
|
|
windows,
|
|
|
|
}:
|
2018-11-21 12:38:49 +00:00
|
|
|
|
2025-02-16 05:15:39 +08:00
|
|
|
lib.extendMkDerivation {
|
|
|
|
constructDrv = stdenv.mkDerivation;
|
|
|
|
|
|
|
|
excludeDrvArgNames = [
|
|
|
|
"depsExtraArgs"
|
|
|
|
"cargoUpdateHook"
|
|
|
|
"cargoDeps"
|
|
|
|
"cargoLock"
|
|
|
|
];
|
|
|
|
|
|
|
|
extendDrvArgs =
|
|
|
|
finalAttrs:
|
2019-03-01 21:45:12 -05:00
|
|
|
{
|
|
|
|
name ? "${args.pname}-${args.version}",
|
2020-11-08 08:47:12 +01:00
|
|
|
|
2021-02-15 07:06:31 +01:00
|
|
|
# Name for the vendored dependencies tarball
|
|
|
|
cargoDepsName ? name,
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2015-05-29 19:35:31 +02:00
|
|
|
src ? null,
|
|
|
|
srcs ? null,
|
2022-09-30 21:09:03 +00:00
|
|
|
preUnpack ? null,
|
2019-12-02 21:24:40 +00:00
|
|
|
unpackPhase ? null,
|
2022-09-30 21:09:03 +00:00
|
|
|
postUnpack ? null,
|
2018-08-13 14:44:30 +09:00
|
|
|
cargoPatches ? [ ],
|
|
|
|
patches ? [ ],
|
2015-05-29 19:35:31 +02:00
|
|
|
sourceRoot ? null,
|
2024-10-22 20:05:09 +02:00
|
|
|
cargoRoot ? null,
|
2016-05-28 15:03:59 +02:00
|
|
|
logLevel ? "",
|
2015-05-29 19:35:31 +02:00
|
|
|
buildInputs ? [ ],
|
2018-11-21 01:47:45 +00:00
|
|
|
nativeBuildInputs ? [ ],
|
2015-05-29 19:35:31 +02:00
|
|
|
cargoUpdateHook ? "",
|
2023-06-18 09:27:44 +00:00
|
|
|
cargoDepsHook ? "",
|
2019-02-26 00:52:01 -05:00
|
|
|
buildType ? "release",
|
2019-07-21 00:00:00 -05:00
|
|
|
meta ? { },
|
2024-10-21 22:21:06 +02:00
|
|
|
useFetchCargoVendor ? false,
|
2024-11-16 11:41:05 -08:00
|
|
|
cargoDeps ? null,
|
2021-05-08 07:44:31 +02:00
|
|
|
cargoLock ? null,
|
2018-02-20 09:59:26 +00:00
|
|
|
cargoVendorDir ? null,
|
2020-05-13 01:15:23 +02:00
|
|
|
checkType ? buildType,
|
2021-10-26 22:41:37 -04:00
|
|
|
buildNoDefaultFeatures ? false,
|
|
|
|
checkNoDefaultFeatures ? buildNoDefaultFeatures,
|
|
|
|
buildFeatures ? [ ],
|
|
|
|
checkFeatures ? buildFeatures,
|
2022-11-28 17:00:17 -05:00
|
|
|
useNextest ? false,
|
2024-10-07 21:16:04 +09:00
|
|
|
auditable ? !cargo-auditable.meta.broken,
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2020-09-23 06:01:05 -04:00
|
|
|
depsExtraArgs ? { },
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2020-05-13 01:28:24 +02:00
|
|
|
# Needed to `pushd`/`popd` into a subdir of a tarball if this subdir
|
|
|
|
# contains a Cargo.toml, but isn't part of a workspace (which is e.g. the
|
|
|
|
# case for `rustfmt`/etc from the `rust-sources).
|
|
|
|
# Otherwise, everything from the tarball would've been built/tested.
|
|
|
|
buildAndTestSubdir ? null,
|
2015-05-29 19:35:31 +02:00
|
|
|
...
|
|
|
|
}@args:
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
let
|
2020-01-12 11:21:23 -05:00
|
|
|
|
2024-11-16 11:41:05 -08:00
|
|
|
cargoDeps' =
|
2022-05-12 21:33:02 +02:00
|
|
|
if cargoVendorDir != null then
|
|
|
|
null
|
2024-11-16 11:41:05 -08:00
|
|
|
else if cargoDeps != null then
|
|
|
|
cargoDeps
|
2022-05-12 21:33:02 +02:00
|
|
|
else if cargoLock != null then
|
|
|
|
importCargoLock cargoLock
|
2025-02-16 04:58:10 +08:00
|
|
|
else if (args.cargoHash or null == null) && (args.cargoSha256 or null == null) then
|
|
|
|
throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set"
|
2024-11-26 08:47:40 +01:00
|
|
|
else if useFetchCargoVendor then
|
|
|
|
fetchCargoVendor (
|
|
|
|
{
|
2024-10-22 20:05:09 +02:00
|
|
|
inherit
|
|
|
|
src
|
|
|
|
srcs
|
|
|
|
sourceRoot
|
|
|
|
cargoRoot
|
|
|
|
preUnpack
|
|
|
|
unpackPhase
|
|
|
|
postUnpack
|
|
|
|
;
|
2024-10-21 22:21:06 +02:00
|
|
|
name = cargoDepsName;
|
|
|
|
patches = cargoPatches;
|
|
|
|
hash = args.cargoHash;
|
|
|
|
}
|
|
|
|
// depsExtraArgs
|
|
|
|
)
|
2021-05-08 07:44:31 +02:00
|
|
|
else
|
|
|
|
fetchCargoTarball (
|
|
|
|
{
|
2024-10-22 20:05:09 +02:00
|
|
|
inherit
|
|
|
|
src
|
|
|
|
srcs
|
|
|
|
sourceRoot
|
|
|
|
cargoRoot
|
|
|
|
preUnpack
|
|
|
|
unpackPhase
|
|
|
|
postUnpack
|
|
|
|
cargoUpdateHook
|
|
|
|
;
|
2021-05-08 07:44:31 +02:00
|
|
|
name = cargoDepsName;
|
|
|
|
patches = cargoPatches;
|
2021-10-18 19:21:43 -04:00
|
|
|
}
|
|
|
|
// lib.optionalAttrs (args ? cargoHash) {
|
|
|
|
hash = args.cargoHash;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (args ? cargoSha256) {
|
2024-07-03 20:52:14 +08:00
|
|
|
sha256 = lib.warn "cargoSha256 is deprecated. Please use cargoHash with SRI hash instead" args.cargoSha256;
|
2022-05-12 21:33:02 +02:00
|
|
|
}
|
|
|
|
// depsExtraArgs
|
|
|
|
);
|
2018-02-20 09:59:26 +00:00
|
|
|
|
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-05-09 13:38:32 +00:00
|
|
|
target = stdenv.hostPlatform.rust.rustcTargetSpec;
|
2021-01-24 01:40:18 +01:00
|
|
|
targetIsJSON = lib.hasSuffix ".json" target;
|
2019-08-14 09:13:19 +00:00
|
|
|
in
|
2025-02-16 05:15:39 +08:00
|
|
|
lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") {
|
2025-01-30 16:04:08 +01:00
|
|
|
RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or "");
|
2020-10-17 00:48:38 -07:00
|
|
|
}
|
|
|
|
// {
|
2024-11-16 11:41:05 -08:00
|
|
|
cargoDeps = cargoDeps';
|
|
|
|
inherit buildAndTestSubdir;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-02-15 06:54:18 +01:00
|
|
|
cargoBuildType = buildType;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-02-26 11:51:31 +01:00
|
|
|
cargoCheckType = checkType;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-10-26 22:41:37 -04:00
|
|
|
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-10-26 22:41:37 -04:00
|
|
|
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-10-26 22:41:37 -04:00
|
|
|
cargoBuildFeatures = buildFeatures;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-10-26 22:41:37 -04:00
|
|
|
cargoCheckFeatures = checkFeatures;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2022-12-07 00:18:58 -05:00
|
|
|
nativeBuildInputs =
|
|
|
|
nativeBuildInputs
|
|
|
|
++ lib.optionals auditable [
|
2023-04-24 17:30:05 +00:00
|
|
|
(buildPackages.cargo-auditable-cargo-wrapper.override {
|
2023-01-12 12:22:07 -05:00
|
|
|
inherit cargo cargo-auditable;
|
2022-12-07 00:18:58 -05:00
|
|
|
})
|
|
|
|
]
|
|
|
|
++ [
|
2021-02-15 10:26:40 +01:00
|
|
|
cargoBuildHook
|
2022-11-28 17:00:17 -05:00
|
|
|
(if useNextest then cargoNextestHook else cargoCheckHook)
|
2021-02-15 10:26:40 +01:00
|
|
|
cargoInstallHook
|
|
|
|
cargoSetupHook
|
|
|
|
rustc
|
rust: fix splicing for rust hooks
This fixes a long standing issue where rust hooks behave differently when used inside buildRustPackage vs inside mkDerivation, which lead to surprising behavior, like for example the package being built for the wrong paltform or the linker not being found especially in cross compilation scenarios.
The reason for this inconsitency was, that buildRustPackage consumed the hooks in a non-spliced form, via [this inherit statement](https://github.com/NixOS/nixpkgs/blob/4506ece030a0c82d078edd0360ea8af6b4d94035/pkgs/development/compilers/rust/make-rust-platform.nix#L60), and therefore the usual platform shift on the hooks introduced by putting them in `nativeBuildInputs` was not applied here.
Thoug whenever the hook was used inside other builders like `mkDerivation` the platform shift did apply correctly as the hook was consumed via the spliced package set, introducing the inconsitecy.
Because of the wrong (non-spliced) use in buildRustPackage, most rust hooks have been designed with the wrong build/host/target shift in mind which is fixed by this change.
Due to the inconsitent behavior between different builders, workarounds like `rust.envVars`, which were previously introduced, likely become obsolete by this change.
This likely fixes a bunch of cross compilation issues for rust packages that are not based on `buildRustPackage` but instead consume the hooks directly.
Done:
- ensure that `buildRustPackage` consumes spliced hooks by using makeScopeWithSplicing' in make-rust-platform.nix.
- refactor hooks to make them refer to correct build/host/target packages.
- remove `rust.envVars` workaround from all rust hooks
- implement tests for most rust hooks in /pkgs/test/rut-hooks
The newly added tests can be executed for native as well as cross compilation via:
```
nix-build -A tests.rust-hooks -A pkgsCross.riscv64.tests.rust-hooks
```
2025-01-01 02:40:34 +07:00
|
|
|
cargo
|
2021-02-15 10:26:40 +01:00
|
|
|
];
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2021-05-07 23:36:21 +02:00
|
|
|
buildInputs =
|
|
|
|
buildInputs
|
2022-12-15 18:38:33 -05:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
|
2021-05-07 23:36:21 +02:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isMinGW [ windows.pthreads ];
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2018-08-13 14:44:30 +09:00
|
|
|
patches = cargoPatches ++ patches;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2019-03-12 09:07:36 -04:00
|
|
|
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
postUnpack =
|
|
|
|
''
|
2016-12-03 23:36:48 +01:00
|
|
|
eval "$cargoDepsHook"
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2019-07-26 00:48:18 +08:00
|
|
|
export RUST_LOG=${logLevel}
|
2020-02-16 02:33:02 -05:00
|
|
|
''
|
|
|
|
+ (args.postUnpack or "");
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2019-07-26 00:48:18 +08:00
|
|
|
configurePhase =
|
|
|
|
args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
2018-11-21 01:47:45 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2015-04-21 20:34:26 +02:00
|
|
|
doCheck = args.doCheck or true;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2020-03-18 13:50:12 +00:00
|
|
|
strictDeps = true;
|
2024-12-10 20:23:58 +01:00
|
|
|
|
2024-06-09 16:41:19 +01:00
|
|
|
meta = meta // {
|
2024-08-15 11:05:15 +02:00
|
|
|
badPlatforms = meta.badPlatforms or [ ] ++ rustc.badTargetPlatforms;
|
2024-06-09 16:41:19 +01:00
|
|
|
# default to Rust's platforms
|
|
|
|
platforms = lib.intersectLists meta.platforms or lib.platforms.all rustc.targetPlatforms;
|
|
|
|
};
|
2025-02-16 05:15:39 +08:00
|
|
|
};
|
|
|
|
}
|