Last active
April 10, 2023 08:54
-
-
Save schickling/1e613344f9adab9529ba6b44168c1689 to your computer and use it in GitHub Desktop.
WASM Nix build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# nix run .#wasm-packages | |
apps.wasm-packages = { | |
type = "app"; | |
program = toString (pkgs.writeShellScript "wasm-packages" '' | |
${wasmPackScript { packageName = "somepkg-wasm"; }}/bin/wasmPackScript | |
''); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, stdenv, pkgs, rust }: | |
{ packageName }: | |
pkgs.writeShellApplication rec { | |
name = "wasmPackScript"; | |
text = '' | |
outdir="$WORKSPACE_ROOT/packages/@mytunes/${packageName}" | |
pushd "$WORKSPACE_ROOT/rust-packages/${packageName}" | |
rm -rf outdir | |
mkdir -p "$outdir" | |
# TODO remove workaround for https://github.com/rustwasm/wasm-pack/issues/1263 | |
mkdir -p "$outdir/tmpbin/bin" | |
cp "${pkgs.binaryen}/bin/wasm-opt" "$outdir/tmpbin/bin" | |
cp "${pkgs.binaryen}/bin/wasm-opt" "$outdir/tmpbin" | |
export PATH="$outdir/tmpbin:$PATH" | |
# TODO fix warning: (SSL certificate problem: unable to get local issuer certificate) | |
wasm-pack build --out-dir "$outdir" --scope "mytunes" --target web --release | |
# Add newline otherwise Yarn will try to reformat the `package.json` | |
printf "\n" >> "$outdir"/package.json | |
# Only git-ignore the wasm files | |
printf "*.wasm" > "$outdir"/.gitignore | |
echo "Contents of $outdir:" | |
ls -la "$outdir" | |
''; | |
runtimeInputs = [ | |
pkgs.wasm-pack | |
pkgs.wasm-bindgen-cli # needed for wasm-pack | |
pkgs.binaryen # needed for wasm-pack | |
pkgs.cargo | |
rust | |
]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment