Skip to content

Commit

Permalink
chore: update build scripts (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jun 26, 2023
1 parent 4f1fed8 commit c79d0e9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "acvm-simulator"
name = "acvm_simulator"
description = "Typescript wrapper around the ACVM allowing execution of ACIR code"
version = "0.0.0" # x-release-please-version
authors = ["The Noir Team <team@noir-lang.org>"]
Expand Down
34 changes: 32 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
#!/usr/bin/env bash

function require_command {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Error: $1 is required but not installed." >&2
exit 1
fi
}
function check_installed {
if ! command -v "$1" >/dev/null 2>&1; then
echo "$1 is not installed. Please install it." >&2
return 1
fi
return 0
}
function run_or_fail {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "Command '$*' failed with exit code $status" >&2
exit $status
fi
}

require_command toml2json
require_command jq
require_command cargo
require_command wasm-bindgen
check_installed wasm-opt

export pname=$(toml2json < Cargo.toml | jq -r .package.name)

rm -rf ./outputs >/dev/null 2>&1
rm -rf ./result >/dev/null 2>&1

Expand All @@ -10,7 +40,7 @@ else
echo "Will install package to $out"
fi

./buildPhaseCargoCommand.sh
./installPhase.sh
run_or_fail ./buildPhaseCargoCommand.sh
run_or_fail ./installPhase.sh

ln -s $out ./result
32 changes: 24 additions & 8 deletions buildPhaseCargoCommand.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
#!/usr/bin/env bash

function run_or_fail {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "Command '$*' failed with exit code $status" >&2
exit $status
fi
}
function run_if_available {
if command -v "$1" >/dev/null 2>&1; then
"$@"
else
echo "$1 is not installed. Please install it to use this feature." >&2
fi
}

# Clear out the existing build artifacts as these aren't automatically removed by wasm-pack.
if [ -d ./pkg/ ]; then
rm -rf ./pkg/
fi

WASM_BINARY=./target/wasm32-unknown-unknown/release/acvm_simulator.wasm
NODE_WASM=./pkg/nodejs/acvm_simulator_bg.wasm
BROWSER_WASM=./pkg/nodejs/acvm_simulator_bg.wasm
WASM_BINARY=./target/wasm32-unknown-unknown/release/${pname}.wasm
NODE_WASM=./pkg/nodejs/${pname}_bg.wasm
BROWSER_WASM=./pkg/nodejs/${pname}_bg.wasm

# Build the new wasm package
cargo build --lib --release --target wasm32-unknown-unknown
wasm-bindgen $WASM_BINARY --out-dir ./pkg/nodejs --typescript --target nodejs
wasm-bindgen $WASM_BINARY --out-dir ./pkg/web --typescript --target web
wasm-opt $NODE_WASM -o $NODE_WASM -O
wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
run_or_fail cargo build --lib --release --target wasm32-unknown-unknown
run_or_fail wasm-bindgen $WASM_BINARY --out-dir ./pkg/nodejs --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir ./pkg/web --typescript --target web
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
GIT_DIRTY = if (self ? rev) then "false" else "true";

commonArgs = {
pname = "acvm-simulator";
pname = "acvm_simulator";
version = "0.0.0"; # x-release-please-version

src = pkgs.lib.cleanSourceWith {
Expand Down Expand Up @@ -181,6 +181,7 @@
which
git
jq
toml2json
rustToolchain
wasm-bindgen-cli
nodejs
Expand Down

0 comments on commit c79d0e9

Please sign in to comment.