-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathbuild-wasm.sh
More file actions
executable file
·136 lines (114 loc) · 3.68 KB
/
Copy pathbuild-wasm.sh
File metadata and controls
executable file
·136 lines (114 loc) · 3.68 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
# misc/build-wasm.sh — Build gno.wasm and root.zip from gnovm/cmd/gno
#
# Requirements: go (GOARCH=wasm GOOS=js), zip
# For --push: gh (GitHub CLI) with write access to gnolang/gno
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
usage() {
cat <<USAGE
Usage: $(basename "$0") <tag> [--push] [output-dir]
tag Git tag or ref to build (use HEAD for current checkout)
--push Publish assets to the GitHub release for the given tag
output-dir Where to write gno.wasm and root.zip (default: gnovm/build/)
Examples:
$(basename "$0") chain/gnoland1.0
$(basename "$0") chain/gnoland1.0 --push
$(basename "$0") HEAD --push
$(basename "$0") chain/gnoland1.0 --push ./out/
USAGE
}
if [ $# -eq 0 ]; then
usage
exit 0
fi
TAG=""
PUSH=false
OUTPUT_DIR=""
for arg in "$@"; do
case "$arg" in
--push) PUSH=true ;;
--help|-h) usage; exit 0 ;;
*)
if [ -z "$TAG" ]; then
TAG="$arg"
else
OUTPUT_DIR="$arg"
fi
;;
esac
done
if [ -z "$TAG" ]; then
echo "ERROR: <tag> is required."
echo ""
usage
exit 1
fi
OUTPUT_DIR="${OUTPUT_DIR:-$REPO_ROOT/gnovm/build}"
mkdir -p "$OUTPUT_DIR"
# Resolve tag: if not HEAD, checkout the tag (detached) then restore
ORIG_HEAD="$(git -C "$REPO_ROOT" symbolic-ref --short HEAD 2>/dev/null || git -C "$REPO_ROOT" rev-parse HEAD)"
NEEDS_RESTORE=false
if [ "$TAG" != "HEAD" ]; then
echo "==> Checking out $TAG..."
git -C "$REPO_ROOT" checkout --quiet "$TAG"
NEEDS_RESTORE=true
fi
restore() {
if $NEEDS_RESTORE; then
echo "==> Restoring $ORIG_HEAD..."
git -C "$REPO_ROOT" checkout --quiet "$ORIG_HEAD"
fi
}
trap restore EXIT
echo "==> Building gno.wasm (tag: $TAG)..."
cd "$REPO_ROOT/gnovm"
GOARCH=wasm GOOS=js go build \
-ldflags "-X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=$REPO_ROOT/" \
-o "$OUTPUT_DIR/gno.wasm" \
./cmd/gno
echo " $(du -sh "$OUTPUT_DIR/gno.wasm" | cut -f1) $OUTPUT_DIR/gno.wasm"
echo "==> Creating root.zip..."
cd "$REPO_ROOT"
zip -qq -i "*.toml" -i "*.gno" \
-x "*_test.gno" -x "*_filetest.gno" \
-r "$OUTPUT_DIR/root.zip" \
gnovm/stdlibs gnovm/tests/stdlibs examples
echo " $(du -sh "$OUTPUT_DIR/root.zip" | cut -f1) $OUTPUT_DIR/root.zip"
if ! $PUSH; then
echo "==> Done. (pass --push to publish to GitHub release)"
exit 0
fi
RELEASE_TAG="$TAG"
if [ "$TAG" = "HEAD" ]; then
RELEASE_TAG="$(git -C "$REPO_ROOT" describe --exact-match HEAD 2>/dev/null || true)"
if [ -z "$RELEASE_TAG" ]; then
echo "ERROR: HEAD is not on a tag. Use an explicit tag name with --push."
exit 1
fi
fi
ENCODED_TAG="$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$RELEASE_TAG")"
echo "==> Publishing to GitHub release: $RELEASE_TAG"
if gh release view "$RELEASE_TAG" --repo gnolang/gno &>/dev/null; then
echo " Release exists, uploading assets..."
else
echo " Creating release..."
gh release create "$RELEASE_TAG" \
--repo gnolang/gno \
--title "GnoVM $RELEASE_TAG" \
--notes "GnoVM WebAssembly build for tag \`$RELEASE_TAG\`.
Built from [gnovm/cmd/gno](https://github.com/gnolang/gno/tree/$RELEASE_TAG/gnovm/cmd/gno).
## Assets
- \`gno.wasm\` — GnoVM WebAssembly binary (GOOS=js GOARCH=wasm)
- \`root.zip\` — Standard libraries and examples (stdlibs + tests/stdlibs + examples)"
fi
gh release upload "$RELEASE_TAG" \
--repo gnolang/gno \
--clobber \
"$OUTPUT_DIR/gno.wasm" \
"$OUTPUT_DIR/root.zip"
echo ""
echo "==> Done!"
echo " gno.wasm: https://github.com/gnolang/gno/releases/download/${ENCODED_TAG}/gno.wasm"
echo " root.zip: https://github.com/gnolang/gno/releases/download/${ENCODED_TAG}/root.zip"