2023-04-29 22:34:39 +03:00
|
|
|
{ binaryen
|
|
|
|
, buildDepsOnly
|
|
|
|
, crateNameFromCargoToml
|
|
|
|
, mkCargoDerivation
|
2023-08-11 03:38:14 +03:00
|
|
|
, dart-sass
|
2023-05-25 05:17:57 +03:00
|
|
|
, removeReferencesToVendoredSourcesHook
|
2023-04-29 22:34:39 +03:00
|
|
|
, 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
|
2023-05-03 03:23:35 +03:00
|
|
|
export TRUNK_TOOLS_SASS=$(sass --version | head -n1)
|
2023-04-29 22:34:39 +03:00
|
|
|
export TRUNK_TOOLS_WASM_BINDGEN=$(wasm-bindgen --version | cut -d' ' -f2)
|
2023-06-07 06:54:50 +03:00
|
|
|
export TRUNK_TOOLS_WASM_OPT="version_$(wasm-opt --version | cut -d' ' -f3)"
|
2023-04-29 22:34:39 +03:00
|
|
|
|
|
|
|
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}"
|
|
|
|
'';
|
|
|
|
|
2023-05-25 05:17:57 +03:00
|
|
|
installPhaseCommand = args.installPhaseCommand or ''
|
2023-04-29 22:34:39 +03:00
|
|
|
cp -r "$(dirname "${trunkIndexPath}")/dist" $out
|
|
|
|
'';
|
|
|
|
|
2023-05-25 05:17:57 +03:00
|
|
|
# Installing artifacts on a distributable dir does not make much sense
|
|
|
|
doInstallCargoArtifacts = args.doInstallCargoArtifacts or false;
|
|
|
|
|
2023-04-29 22:34:39 +03:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
|
|
|
binaryen
|
2023-08-11 03:38:14 +03:00
|
|
|
dart-sass
|
2023-04-29 22:34:39 +03:00
|
|
|
trunk
|
|
|
|
wasm-bindgen-cli
|
2023-05-25 05:17:57 +03:00
|
|
|
# Store references are certainly false positives
|
|
|
|
removeReferencesToVendoredSourcesHook
|
2023-04-29 22:34:39 +03:00
|
|
|
];
|
|
|
|
})
|