mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-27 12:36:51 +03:00
1b8653ad52
Replace the javascript version of dart-sass with a native binary version. Should improve built times and reduce disk usage. --------- Co-authored-by: Ivan Petkov <ivanppetkov@gmail.com>
82 lines
2.4 KiB
Nix
82 lines
2.4 KiB
Nix
{ binaryen
|
|
, buildDepsOnly
|
|
, crateNameFromCargoToml
|
|
, mkCargoDerivation
|
|
, dart-sass
|
|
, removeReferencesToVendoredSourcesHook
|
|
, trunk
|
|
, vendorCargoDeps
|
|
, wasm-bindgen-cli
|
|
}:
|
|
|
|
{ trunkExtraArgs ? ""
|
|
, trunkExtraBuildArgs ? ""
|
|
, trunkIndexPath ? "./index.html"
|
|
, ...
|
|
}@origArgs:
|
|
let
|
|
cleanedArgs = builtins.removeAttrs origArgs [
|
|
"installPhase"
|
|
"installPhaseCommand"
|
|
"trunkExtraArgs"
|
|
"trunkExtraBuildArgs"
|
|
"trunkIndexPath"
|
|
];
|
|
|
|
crateName = crateNameFromCargoToml cleanedArgs;
|
|
|
|
# Avoid recomputing values when passing args down
|
|
args = cleanedArgs // {
|
|
pname = cleanedArgs.pname or crateName.pname;
|
|
version = cleanedArgs.version or crateName.version;
|
|
cargoVendorDir = cleanedArgs.cargoVendorDir or (vendorCargoDeps cleanedArgs);
|
|
};
|
|
in
|
|
mkCargoDerivation (args // {
|
|
pnameSuffix = "-trunk";
|
|
|
|
cargoArtifacts = args.cargoArtifacts or (buildDepsOnly (args // {
|
|
CARGO_BUILD_TARGET = args.CARGO_BUILD_TARGET or "wasm32-unknown-unknown";
|
|
installCargoArtifactsMode = args.installCargoArtifactsMode or "use-zstd";
|
|
doCheck = args.doCheck or false;
|
|
}));
|
|
|
|
# Force trunk to not download dependencies, but set the version with
|
|
# whatever tools actually make it into the builder's PATH
|
|
preConfigure = ''
|
|
echo configuring trunk tools
|
|
export TRUNK_TOOLS_SASS=$(sass --version | head -n1)
|
|
export TRUNK_TOOLS_WASM_BINDGEN=$(wasm-bindgen --version | cut -d' ' -f2)
|
|
export TRUNK_TOOLS_WASM_OPT="version_$(wasm-opt --version | cut -d' ' -f3)"
|
|
|
|
echo "TRUNK_TOOLS_SASS=''${TRUNK_TOOLS_SASS}"
|
|
echo "TRUNK_TOOLS_WASM_BINDGEN=''${TRUNK_TOOLS_WASM_BINDGEN}"
|
|
echo "TRUNK_TOOLS_WASM_OPT=''${TRUNK_TOOLS_WASM_OPT}"
|
|
'';
|
|
|
|
buildPhaseCargoCommand = args.buildPhaseCommand or ''
|
|
local profileArgs=""
|
|
if [[ "$CARGO_PROFILE" == "release" ]]; then
|
|
profileArgs="--release"
|
|
fi
|
|
|
|
trunk ${trunkExtraArgs} build $profileArgs ${trunkExtraBuildArgs} "${trunkIndexPath}"
|
|
'';
|
|
|
|
installPhaseCommand = args.installPhaseCommand or ''
|
|
cp -r "$(dirname "${trunkIndexPath}")/dist" $out
|
|
'';
|
|
|
|
# Installing artifacts on a distributable dir does not make much sense
|
|
doInstallCargoArtifacts = args.doInstallCargoArtifacts or false;
|
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
|
binaryen
|
|
dart-sass
|
|
trunk
|
|
wasm-bindgen-cli
|
|
# Store references are certainly false positives
|
|
removeReferencesToVendoredSourcesHook
|
|
];
|
|
})
|