forked from dfinity/nns-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-rs.sh
executable file
·47 lines (42 loc) · 1.26 KB
/
build-rs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -euo pipefail
###############
# Hjelpe meg!
###############
print_help() {
cat <<-EOF
Builds a canister wasm file from Rust source code.
Usage:
$(basename "$0") <canister_name> [cargo_flags]
EOF
}
[[ "${1:-}" != "--help" ]] || {
print_help
exit 0
}
###############
# Set working dir, canister name and build args
###############
cd "$(dirname "$0")"
canister_name="$1"
cargo_args=(--target wasm32-unknown-unknown --release --package "$@")
###############
# cargo build # (output: target/release/.../${canister_name}.wasm)
###############
echo "Compiling rust package ${canister_name}"
cargo build "${cargo_args[@]}"
####################
# ic-wasm shrink # (output: ${canister_name}.wasm.gz)
####################
echo Optimising wasm
wasm_path="$(canister_name="$canister_name" jq -r '.canisters[env.canister_name].wasm' dfx.json)"
[[ "$wasm_path" != "${wasm_path%.wasm.gz}" ]] || {
echo "ERROR: dfx.json should have a wasm path ending in .wasm.gz for $canister_name. It's the new standard..."
exit 1
} >&2
mkdir -p "$(dirname "$wasm_path")"
ic-wasm "./target/wasm32-unknown-unknown/release/${canister_name}.wasm" -o "${wasm_path%.gz}" shrink
gzip -f -n "${wasm_path%.gz}"
rm -f "${wasm_path%.gz}"
ls -sh "${wasm_path}"
sha256sum "${wasm_path}"