2021-10-19 19:59:28 -04:00
|
|
|
{ lib
|
|
|
|
, importCargoLock
|
|
|
|
, fetchCargoTarball
|
|
|
|
, rust
|
|
|
|
, 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
|
|
|
|
|
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
|
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 ? ""
|
2019-02-26 00:52:01 -05:00
|
|
|
, buildType ? "release"
|
2019-07-21 00:00:00 -05:00
|
|
|
, meta ? {}
|
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
|
2023-05-09 18:27:46 +00:00
|
|
|
, auditable ? !cargo-auditable.meta.broken
|
2022-12-05 18:43:06 -05:00
|
|
|
|
2020-09-23 06:01:05 -04:00
|
|
|
, depsExtraArgs ? {}
|
2020-09-09 21:39:23 +10: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
|
|
|
|
|
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:
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2022-08-21 17:09:09 +08:00
|
|
|
assert cargoVendorDir == null && cargoLock == null
|
|
|
|
-> !(args ? cargoSha256 && args.cargoSha256 != null) && !(args ? cargoHash && args.cargoHash != null)
|
|
|
|
-> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set";
|
2019-02-26 00:52:01 -05:00
|
|
|
assert buildType == "release" || buildType == "debug";
|
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
|
|
|
|
2021-05-08 07:44:31 +02:00
|
|
|
cargoDeps =
|
2022-05-12 21:33:02 +02:00
|
|
|
if cargoVendorDir != null then null
|
|
|
|
else if cargoLock != null then importCargoLock cargoLock
|
2021-05-08 07:44:31 +02:00
|
|
|
else fetchCargoTarball ({
|
2022-09-30 21:09:03 +00:00
|
|
|
inherit src srcs sourceRoot 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) {
|
|
|
|
sha256 = args.cargoSha256;
|
2022-05-12 21:33:02 +02:00
|
|
|
} // depsExtraArgs);
|
2018-02-20 09:59:26 +00:00
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
target = rust.toRustTargetSpec stdenv.hostPlatform;
|
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
|
|
|
|
|
|
|
# see https://github.com/rust-lang/cargo/blob/964a16a28e234a3d397b2a7031d4ab4a428b1391/src/cargo/core/compiler/compile_kind.rs#L151-L168
|
|
|
|
# the "${}" is needed to transform the path into a /nix/store path before baseNameOf
|
|
|
|
shortTarget = if targetIsJSON then
|
2021-01-24 01:40:18 +01:00
|
|
|
(lib.removeSuffix ".json" (builtins.baseNameOf "${target}"))
|
2020-10-08 14:32:49 -07:00
|
|
|
else target;
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2021-10-19 19:59:28 -04:00
|
|
|
sysroot = callPackage ./sysroot { } {
|
2020-10-08 14:32:49 -07:00
|
|
|
inherit target shortTarget;
|
|
|
|
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);
|
|
|
|
|
2022-05-28 21:06:27 +03:00
|
|
|
stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "cargoLock" ]) // lib.optionalAttrs useSysroot {
|
2020-10-17 00:48:38 -07:00
|
|
|
RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or "");
|
|
|
|
} // {
|
2021-02-15 06:54:18 +01:00
|
|
|
inherit buildAndTestSubdir cargoDeps;
|
2021-02-11 17:32:47 +01:00
|
|
|
|
2021-02-15 06:54:18 +01:00
|
|
|
cargoBuildType = buildType;
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2021-02-26 11:51:31 +01:00
|
|
|
cargoCheckType = checkType;
|
|
|
|
|
2021-10-26 22:41:37 -04:00
|
|
|
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
|
|
|
|
|
|
|
|
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
|
|
|
|
|
|
|
|
cargoBuildFeatures = buildFeatures;
|
|
|
|
|
|
|
|
cargoCheckFeatures = checkFeatures;
|
|
|
|
|
2015-04-23 16:37:52 +02:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
|
|
|
|
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
|
|
|
|
];
|
2021-02-11 17:32:47 +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 ];
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2018-08-13 14:44:30 +09:00
|
|
|
patches = cargoPatches ++ patches;
|
|
|
|
|
2019-03-12 09:07:36 -04:00
|
|
|
PKG_CONFIG_ALLOW_CROSS =
|
|
|
|
if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
postUnpack = ''
|
2016-12-03 23:36:48 +01:00
|
|
|
eval "$cargoDepsHook"
|
|
|
|
|
2019-07-26 00:48:18 +08:00
|
|
|
export RUST_LOG=${logLevel}
|
2020-02-16 02:33:02 -05:00
|
|
|
'' + (args.postUnpack or "");
|
|
|
|
|
2019-07-26 00:48:18 +08:00
|
|
|
configurePhase = args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
2018-11-21 01:47:45 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2015-04-21 20:34:26 +02:00
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2020-03-18 13:50:12 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
2019-07-21 00:00:00 -05:00
|
|
|
meta = {
|
|
|
|
# default to Rust's platforms
|
2023-04-24 17:35:35 +00:00
|
|
|
platforms = rustc.meta.platforms ++ [
|
|
|
|
# Platforms without host tools from
|
|
|
|
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
|
|
|
|
"armv7a-darwin"
|
2023-06-15 16:40:19 -04:00
|
|
|
"armv5tel-linux" "armv7a-linux" "m68k-linux" "riscv32-linux"
|
2023-04-24 17:35:35 +00:00
|
|
|
"armv6l-netbsd"
|
|
|
|
"x86_64-redox"
|
|
|
|
"wasm32-wasi"
|
|
|
|
];
|
2019-07-21 00:00:00 -05:00
|
|
|
} // meta;
|
2014-10-10 16:59:37 +02:00
|
|
|
})
|