mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-17 19:19:47 +00:00
Move away from subflakes
This commit is contained in:
67
nix/rust-helpers/default.nix
Normal file
67
nix/rust-helpers/default.nix
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
rustPlatform,
|
||||
jq,
|
||||
rsync,
|
||||
stdenv,
|
||||
fenix,
|
||||
}:
|
||||
{
|
||||
buildRustPackage =
|
||||
{
|
||||
target,
|
||||
src,
|
||||
cargoLock ? {
|
||||
lockFile = "${src}/Cargo.lock";
|
||||
},
|
||||
release ? true,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
# Setup a toolchain for the the host system targeting `target`.
|
||||
toolchain =
|
||||
let
|
||||
inherit (fenix) stable targets combine;
|
||||
in
|
||||
combine [
|
||||
stable.rustc
|
||||
stable.cargo
|
||||
targets.${target}.stable.rust-std
|
||||
];
|
||||
|
||||
# Create `vendor` folder with all dependencies.
|
||||
vendoredDependencies = rustPlatform.importCargoLock cargoLock;
|
||||
|
||||
rustcTargetDir = "target/${target}/${if release then "release" else "debug"}";
|
||||
in
|
||||
stdenv.mkDerivation (
|
||||
(removeAttrs args [ "cargoLock" ])
|
||||
// {
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
||||
toolchain
|
||||
jq
|
||||
rsync
|
||||
];
|
||||
dontConfigure = true;
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
cargo build \
|
||||
--config 'source.crates-io.replace-with="vendored-sources"' \
|
||||
--config 'source.vendored-sources.directory="${vendoredDependencies}"' \
|
||||
--offline \
|
||||
--target ${target} ${if release then "-r" else ""}
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall;
|
||||
mkdir -p $out
|
||||
|
||||
find ${rustcTargetDir} -type f -maxdepth 1 | \
|
||||
xargs -I ___X -n1 cp ___X $out
|
||||
|
||||
runHook postInstall;
|
||||
'';
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user