2020-05-07 01:03:41 +00:00
|
|
|
{ stdenv
|
2021-01-24 00:40:18 +00:00
|
|
|
, lib
|
2020-05-07 01:03:41 +00:00
|
|
|
, buildPackages
|
|
|
|
, cacert
|
2021-02-11 16:32:47 +00:00
|
|
|
, cargoBuildHook
|
2021-02-15 09:26:40 +00:00
|
|
|
, cargoCheckHook
|
2021-02-15 05:54:18 +00:00
|
|
|
, cargoInstallHook
|
2021-02-09 10:38:25 +00:00
|
|
|
, cargoSetupHook
|
2020-05-07 01:03:41 +00:00
|
|
|
, fetchCargoTarball
|
2020-10-08 21:32:49 +00:00
|
|
|
, runCommandNoCC
|
|
|
|
, rustPlatform
|
|
|
|
, callPackage
|
|
|
|
, remarshal
|
2020-05-07 01:03:41 +00:00
|
|
|
, git
|
|
|
|
, rust
|
|
|
|
, rustc
|
|
|
|
, windows
|
|
|
|
}:
|
2018-11-21 12:38:49 +00:00
|
|
|
|
2019-03-02 02:45:12 +00:00
|
|
|
{ name ? "${args.pname}-${args.version}"
|
2020-11-08 07:47:12 +00:00
|
|
|
|
|
|
|
# SRI hash
|
|
|
|
, cargoHash ? ""
|
|
|
|
|
|
|
|
# Legacy hash
|
|
|
|
, cargoSha256 ? ""
|
|
|
|
|
2021-02-15 06:06:31 +00:00
|
|
|
# Name for the vendored dependencies tarball
|
|
|
|
, cargoDepsName ? name
|
|
|
|
|
2015-05-29 17:35:31 +00:00
|
|
|
, src ? null
|
|
|
|
, srcs ? null
|
2019-12-02 21:24:40 +00:00
|
|
|
, unpackPhase ? null
|
2018-08-13 05:44:30 +00:00
|
|
|
, cargoPatches ? []
|
|
|
|
, patches ? []
|
2015-05-29 17:35:31 +00:00
|
|
|
, sourceRoot ? null
|
2016-05-28 13:03:59 +00:00
|
|
|
, logLevel ? ""
|
2015-05-29 17:35:31 +00:00
|
|
|
, buildInputs ? []
|
2018-11-21 01:47:45 +00:00
|
|
|
, nativeBuildInputs ? []
|
2015-05-29 17:35:31 +00:00
|
|
|
, cargoUpdateHook ? ""
|
2016-12-03 22:36:48 +00:00
|
|
|
, cargoDepsHook ? ""
|
2019-02-26 05:52:01 +00:00
|
|
|
, buildType ? "release"
|
2019-07-21 05:00:00 +00:00
|
|
|
, meta ? {}
|
2018-02-20 09:59:26 +00:00
|
|
|
, cargoVendorDir ? null
|
2020-05-12 23:15:23 +00:00
|
|
|
, checkType ? buildType
|
2020-09-23 10:01:05 +00:00
|
|
|
, depsExtraArgs ? {}
|
2020-09-09 11:39:23 +00:00
|
|
|
|
2020-10-08 21:32:49 +00:00
|
|
|
# Toggles whether a custom sysroot is created when the target is a .json file.
|
|
|
|
, __internal_dontAddSysroot ? false
|
|
|
|
|
2020-05-12 23:28:24 +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
|
2015-05-29 17:35:31 +00:00
|
|
|
, ... } @ args:
|
2014-10-10 14:59:37 +00:00
|
|
|
|
2020-11-08 07:47:12 +00:00
|
|
|
assert cargoVendorDir == null -> !(cargoSha256 == "" && cargoHash == "");
|
2019-02-26 05:52:01 +00:00
|
|
|
assert buildType == "release" || buildType == "debug";
|
2018-02-20 09:59:26 +00:00
|
|
|
|
2014-10-10 14:59:37 +00:00
|
|
|
let
|
2020-01-12 16:21:23 +00:00
|
|
|
|
2018-02-20 09:59:26 +00:00
|
|
|
cargoDeps = if cargoVendorDir == null
|
2020-09-23 10:01:05 +00:00
|
|
|
then fetchCargoTarball ({
|
2021-02-15 06:06:31 +00:00
|
|
|
inherit src srcs sourceRoot unpackPhase cargoUpdateHook;
|
|
|
|
name = cargoDepsName;
|
2020-11-08 07:47:12 +00:00
|
|
|
hash = cargoHash;
|
2018-08-13 05:44:30 +00:00
|
|
|
patches = cargoPatches;
|
2018-02-20 09:59:26 +00:00
|
|
|
sha256 = cargoSha256;
|
2020-09-23 10:01:05 +00:00
|
|
|
} // depsExtraArgs)
|
2018-02-20 09:59:26 +00:00
|
|
|
else null;
|
|
|
|
|
2020-03-19 00:43:07 +00:00
|
|
|
# If we have a cargoSha256 fixed-output derivation, validate it at build time
|
|
|
|
# against the src fixed-output derivation to check consistency.
|
2020-11-08 07:47:12 +00:00
|
|
|
validateCargoDeps = !(cargoHash == "" && cargoSha256 == "");
|
2020-01-12 16:21:23 +00:00
|
|
|
|
2021-02-11 16:32:47 +00:00
|
|
|
target = rust.toRustTargetSpec stdenv.hostPlatform;
|
2021-01-24 00:40:18 +00:00
|
|
|
targetIsJSON = lib.hasSuffix ".json" target;
|
2020-10-17 07:45:27 +00:00
|
|
|
useSysroot = targetIsJSON && !__internal_dontAddSysroot;
|
2020-10-08 21:32:49 +00: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 00:40:18 +00:00
|
|
|
(lib.removeSuffix ".json" (builtins.baseNameOf "${target}"))
|
2020-10-08 21:32:49 +00:00
|
|
|
else target;
|
2014-10-10 14:59:37 +00:00
|
|
|
|
2020-10-08 21:32:49 +00:00
|
|
|
sysroot = (callPackage ./sysroot {}) {
|
|
|
|
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 07:47:14 +00: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);
|
|
|
|
|
2021-01-24 00:40:18 +00:00
|
|
|
stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs useSysroot {
|
2020-10-17 07:48:38 +00:00
|
|
|
RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or "");
|
|
|
|
} // {
|
2021-02-15 05:54:18 +00:00
|
|
|
inherit buildAndTestSubdir cargoDeps;
|
2021-02-11 16:32:47 +00:00
|
|
|
|
2021-02-15 05:54:18 +00:00
|
|
|
cargoBuildType = buildType;
|
2014-10-10 14:59:37 +00:00
|
|
|
|
2021-02-26 10:51:31 +00:00
|
|
|
cargoCheckType = checkType;
|
|
|
|
|
2015-04-23 14:37:52 +00:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
|
|
|
|
2021-02-15 09:26:40 +00:00
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [
|
|
|
|
cacert
|
|
|
|
git
|
|
|
|
cargoBuildHook
|
|
|
|
cargoCheckHook
|
|
|
|
cargoInstallHook
|
|
|
|
cargoSetupHook
|
|
|
|
rustc
|
|
|
|
];
|
2021-02-11 16:32:47 +00:00
|
|
|
|
2021-01-24 00:40:18 +00:00
|
|
|
buildInputs = buildInputs ++ lib.optional stdenv.hostPlatform.isMinGW windows.pthreads;
|
2014-10-10 14:59:37 +00:00
|
|
|
|
2018-08-13 05:44:30 +00:00
|
|
|
patches = cargoPatches ++ patches;
|
|
|
|
|
2019-03-12 13:07:36 +00:00
|
|
|
PKG_CONFIG_ALLOW_CROSS =
|
|
|
|
if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
|
|
|
|
2014-10-10 14:59:37 +00:00
|
|
|
postUnpack = ''
|
2016-12-03 22:36:48 +00:00
|
|
|
eval "$cargoDepsHook"
|
|
|
|
|
2019-07-25 16:48:18 +00:00
|
|
|
export RUST_LOG=${logLevel}
|
2020-02-16 07:33:02 +00:00
|
|
|
'' + (args.postUnpack or "");
|
|
|
|
|
2019-07-25 16:48:18 +00:00
|
|
|
configurePhase = args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
2018-11-21 01:47:45 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2015-04-21 18:34:26 +00:00
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2020-03-18 13:50:12 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
2017-10-26 16:43:17 +00:00
|
|
|
passthru = { inherit cargoDeps; } // (args.passthru or {});
|
2019-07-21 05:00:00 +00:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
# default to Rust's platforms
|
|
|
|
platforms = rustc.meta.platforms;
|
|
|
|
} // meta;
|
2014-10-10 14:59:37 +00:00
|
|
|
})
|