mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
76 lines
1.7 KiB
Nix
76 lines
1.7 KiB
Nix
{
|
|
rustPlatform,
|
|
jq,
|
|
rsync,
|
|
lib,
|
|
stdenv,
|
|
# openssl,
|
|
pkg-config,
|
|
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
|
|
pkg-config
|
|
# (lib.getDev openssl)
|
|
];
|
|
buildInputs = [
|
|
# openssl
|
|
];
|
|
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;
|
|
'';
|
|
}
|
|
);
|
|
}
|