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
|
|
|
|
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-10-08 14:32:49 -07:00
|
|
|
# Toggles whether a custom sysroot is created when the target is a .json file.
|
|
|
|
__internal_dontAddSysroot ? false,
|
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
|
|
|
|
2024-11-16 11:41:05 -08:00
|
|
|
assert
|
|
|
|
cargoVendorDir == null && cargoDeps == null && cargoLock == null
|
2022-08-21 17:09:09 +08:00
|
|
|
->
|
|
|
|
!(args ? cargoSha256 && args.cargoSha256 != null) && !(args ? cargoHash && args.cargoHash != null)
|
2024-11-16 11:41:05 -08:00
|
|
|
-> throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set";
|
2018-02-20 09:59:26 +00: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
|
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;
|
2020-10-17 00:45:27 -07:00
|
|
|
useSysroot = targetIsJSON && !__internal_dontAddSysroot;
|
2020-10-08 14:32:49 -07:00
|
|
|
|
2021-10-19 19:59:28 -04:00
|
|
|
sysroot = callPackage ./sysroot { } {
|
2023-09-26 07:37:57 +00:00
|
|
|
inherit target;
|
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
|
|
|
shortTarget = stdenv.hostPlatform.rust.cargoShortTarget;
|
2020-10-08 14:32:49 -07:00
|
|
|
RUSTFLAGS = args.RUSTFLAGS or "";
|
|
|
|
originalCargoToml = src + /Cargo.toml; # profile info is later extracted
|
|
|
|
};
|
2019-08-14 09:13:19 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2020-10-17 00:47:14 -07:00
|
|
|
# Tests don't currently work for `no_std`, and all custom sysroots are currently built without `std`.
|
|
|
|
# See https://os.phil-opp.com/testing/ for more information.
|
|
|
|
assert useSysroot -> !(args.doCheck or true);
|
|
|
|
|
2024-11-16 11:41:05 -08:00
|
|
|
stdenv.mkDerivation (
|
|
|
|
(removeAttrs args [
|
|
|
|
"depsExtraArgs"
|
|
|
|
"cargoUpdateHook"
|
|
|
|
"cargoDeps"
|
|
|
|
"cargoLock"
|
|
|
|
])
|
|
|
|
// lib.optionalAttrs useSysroot {
|
2020-10-17 00:48:38 -07:00
|
|
|
RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or "");
|
2024-11-17 16:11:54 +05:30
|
|
|
}
|
|
|
|
// lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") {
|
2024-07-14 09:14:59 -06:00
|
|
|
RUSTFLAGS =
|
|
|
|
"-C split-debuginfo=packed "
|
|
|
|
+ lib.optionalString useSysroot "--sysroot ${sysroot} "
|
|
|
|
+ (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
|
|
|
|
];
|
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;
|
|
|
|
};
|
2014-10-10 16:59:37 +02:00
|
|
|
}
|
|
|
|
)
|