2024-05-02 00:46:19 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
importCargoLock,
|
|
|
|
fetchCargoTarball,
|
|
|
|
stdenv,
|
|
|
|
callPackage,
|
|
|
|
cargoBuildHook,
|
|
|
|
cargoCheckHook,
|
|
|
|
cargoInstallHook,
|
|
|
|
cargoNextestHook,
|
|
|
|
cargoSetupHook,
|
|
|
|
cargo,
|
|
|
|
cargo-auditable,
|
|
|
|
buildPackages,
|
|
|
|
rustc,
|
|
|
|
libiconv,
|
|
|
|
windows,
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
|
|
|
name ? "${args.pname}-${args.version}",
|
|
|
|
|
|
|
|
# Name for the vendored dependencies tarball
|
|
|
|
cargoDepsName ? name,
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
src ? null,
|
|
|
|
srcs ? null,
|
|
|
|
preUnpack ? null,
|
|
|
|
unpackPhase ? null,
|
|
|
|
postUnpack ? null,
|
|
|
|
cargoPatches ? [ ],
|
|
|
|
patches ? [ ],
|
|
|
|
sourceRoot ? null,
|
|
|
|
logLevel ? "",
|
|
|
|
buildInputs ? [ ],
|
|
|
|
nativeBuildInputs ? [ ],
|
|
|
|
cargoUpdateHook ? "",
|
|
|
|
cargoDepsHook ? "",
|
|
|
|
buildType ? "release",
|
|
|
|
meta ? { },
|
|
|
|
cargoLock ? null,
|
|
|
|
cargoVendorDir ? null,
|
|
|
|
checkType ? buildType,
|
|
|
|
buildNoDefaultFeatures ? false,
|
|
|
|
checkNoDefaultFeatures ? buildNoDefaultFeatures,
|
|
|
|
buildFeatures ? [ ],
|
|
|
|
checkFeatures ? buildFeatures,
|
|
|
|
useNextest ? false,
|
|
|
|
# Enable except on aarch64 pkgsStatic, where we use lld for reasons
|
|
|
|
auditable ?
|
|
|
|
!cargo-auditable.meta.broken
|
|
|
|
&& !(
|
|
|
|
stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isAarch64 && !stdenv.hostPlatform.isDarwin
|
|
|
|
),
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
depsExtraArgs ? { },
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
# Toggles whether a custom sysroot is created when the target is a .json file.
|
|
|
|
__internal_dontAddSysroot ? false,
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00: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,
|
|
|
|
...
|
|
|
|
}@args:
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00: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";
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cargoDeps =
|
|
|
|
if cargoVendorDir != null then
|
|
|
|
null
|
|
|
|
else if cargoLock != null then
|
|
|
|
importCargoLock cargoLock
|
|
|
|
else
|
|
|
|
fetchCargoTarball (
|
|
|
|
{
|
|
|
|
inherit
|
|
|
|
src
|
|
|
|
srcs
|
|
|
|
sourceRoot
|
|
|
|
preUnpack
|
|
|
|
unpackPhase
|
|
|
|
postUnpack
|
|
|
|
cargoUpdateHook
|
|
|
|
;
|
|
|
|
name = cargoDepsName;
|
|
|
|
patches = cargoPatches;
|
2024-06-30 08:12:46 +00:00
|
|
|
}
|
2024-05-02 00:46:19 +00:00
|
|
|
// lib.optionalAttrs (args ? cargoHash) { hash = args.cargoHash; }
|
|
|
|
// lib.optionalAttrs (args ? cargoSha256) { sha256 = args.cargoSha256; }
|
|
|
|
// depsExtraArgs
|
|
|
|
);
|
|
|
|
|
|
|
|
target = stdenv.hostPlatform.rust.rustcTargetSpec;
|
|
|
|
targetIsJSON = lib.hasSuffix ".json" target;
|
|
|
|
useSysroot = targetIsJSON && !__internal_dontAddSysroot;
|
|
|
|
|
|
|
|
sysroot = callPackage ./sysroot { } {
|
|
|
|
inherit target;
|
|
|
|
shortTarget = stdenv.hostPlatform.rust.cargoShortTarget;
|
|
|
|
RUSTFLAGS = args.RUSTFLAGS or "";
|
|
|
|
originalCargoToml = src + /Cargo.toml; # profile info is later extracted
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
# 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);
|
|
|
|
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
(removeAttrs args [
|
|
|
|
"depsExtraArgs"
|
|
|
|
"cargoUpdateHook"
|
|
|
|
"cargoLock"
|
|
|
|
])
|
|
|
|
// lib.optionalAttrs useSysroot { RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); }
|
|
|
|
// {
|
|
|
|
inherit buildAndTestSubdir cargoDeps;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoBuildType = buildType;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoCheckType = checkType;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoBuildFeatures = buildFeatures;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
cargoCheckFeatures = checkFeatures;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
nativeBuildInputs =
|
|
|
|
nativeBuildInputs
|
|
|
|
++ lib.optionals auditable [
|
|
|
|
(buildPackages.cargo-auditable-cargo-wrapper.override { inherit cargo cargo-auditable; })
|
|
|
|
]
|
|
|
|
++ [
|
|
|
|
cargoBuildHook
|
|
|
|
(if useNextest then cargoNextestHook else cargoCheckHook)
|
|
|
|
cargoInstallHook
|
|
|
|
cargoSetupHook
|
|
|
|
rustc
|
|
|
|
];
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
buildInputs =
|
|
|
|
buildInputs
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isMinGW [ windows.pthreads ];
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
patches = cargoPatches ++ patches;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
postUnpack =
|
|
|
|
''
|
|
|
|
eval "$cargoDepsHook"
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
export RUST_LOG=${logLevel}
|
|
|
|
''
|
|
|
|
+ (args.postUnpack or "");
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
configurePhase =
|
|
|
|
args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
doCheck = args.doCheck or true;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
strictDeps = true;
|
2024-06-30 08:12:46 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
meta = {
|
|
|
|
# default to Rust's platforms
|
|
|
|
platforms = rustc.meta.platforms ++ [
|
|
|
|
# Platforms without host tools from
|
|
|
|
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
|
|
|
|
"armv7a-darwin"
|
|
|
|
"armv5tel-linux"
|
|
|
|
"armv7a-linux"
|
|
|
|
"m68k-linux"
|
|
|
|
"mipsel-linux"
|
|
|
|
"mips64el-linux"
|
|
|
|
"riscv32-linux"
|
|
|
|
"armv6l-netbsd"
|
|
|
|
"x86_64-redox"
|
|
|
|
"wasm32-wasi"
|
|
|
|
];
|
|
|
|
badPlatforms = [
|
|
|
|
# Rust is currently unable to target the n32 ABI
|
|
|
|
lib.systems.inspect.patterns.isMips64n32
|
|
|
|
];
|
|
|
|
} // meta;
|
|
|
|
}
|
|
|
|
)
|