Skip to content

Commit 7dcc97d

Browse files
committed
Add buildscript
Signed-off-by: Jakub Gonet <[email protected]>
1 parent f1e6fcc commit 7dcc97d

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ src/platforms/esp32/sdkconfig
3030
# Allow multiple build directories
3131
/build*/
3232
/src/platforms/emscripten/build*/
33+
34+
# FissionVM out dir
35+
out/

build-fission.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Color codes for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
usage() {
12+
echo "Usage: $0 [--clean] <build_mode>"
13+
echo "Options:"
14+
echo " --clean - Clean project before building"
15+
echo "Build modes:"
16+
echo " debug-unix - Debug build for Unix platforms"
17+
echo " debug-wasm - Debug build for WebAssembly"
18+
echo " release-unix - Release build for Unix platforms"
19+
echo " release-wasm - Release build for WebAssembly"
20+
exit 1
21+
}
22+
23+
log() {
24+
echo -e "${GREEN}[BUILD]${NC} $1"
25+
}
26+
27+
warn() {
28+
echo -e "${YELLOW}[WARN]${NC} $1"
29+
}
30+
31+
error() {
32+
echo -e "${RED}[ERROR]${NC} $1"
33+
exit 1
34+
}
35+
36+
check_tools() {
37+
local build_mode=$1
38+
local missing_tools=()
39+
40+
if ! command -v cmake &> /dev/null; then
41+
missing_tools+=("cmake")
42+
fi
43+
if ! command -v ninja &> /dev/null; then
44+
missing_tools+=("ninja")
45+
fi
46+
if ! command -v emcmake &> /dev/null; then
47+
missing_tools+=("emcmake")
48+
fi
49+
if ! command -v emmake &> /dev/null; then
50+
missing_tools+=("emmake")
51+
fi
52+
53+
# Only log/error if tools are missing
54+
if [ ${#missing_tools[@]} -gt 0 ]; then
55+
local tools_list=$(IFS=", "; echo "${missing_tools[*]}")
56+
error "Missing required tools: $tools_list. Please install them first."
57+
fi
58+
}
59+
60+
cleanup_output() {
61+
log "Cleaning previous outputs."
62+
[ -d "out" ] && rm -r out
63+
mkdir -p out
64+
}
65+
66+
67+
build_unix() {
68+
local build_type=$1
69+
local clean_flag=$2
70+
local build_dir="build"
71+
local cmake_args="-DAVM_BUILD_RUNTIME_ONLY=ON -GNinja"
72+
if [ "$build_type" = "release" ]; then
73+
cmake_args="$cmake_args -DCMAKE_BUILD_TYPE=Release -DAVM_RELEASE=ON"
74+
else
75+
cmake_args="$cmake_args -DCMAKE_BUILD_TYPE=Debug"
76+
fi
77+
78+
mkdir -p "$build_dir"
79+
pushd "$build_dir" >/dev/null
80+
81+
[ "$clean_flag" ] && (rm CmakeCache.txt || true)
82+
83+
log "Running 'cmake .. $cmake_args'\n\tin '$(pwd)'."
84+
local cmake_out="$(cmake .. $cmake_args 2>&1)"
85+
[[ $? -ne 0 ]] && error "cmake failed:\n$cmake_out"
86+
87+
[ "$clean_flag" ] && ninja clean
88+
ninja AtomVM
89+
popd >/dev/null
90+
91+
cp "$build_dir/src/AtomVM" out/
92+
}
93+
94+
build_wasm() {
95+
local build_type=$1
96+
local clean_flag=$2
97+
local build_dir="src/platforms/emscripten/build"
98+
local cmake_args="-DAVM_EMSCRIPTEN_ENV=web -GNinja"
99+
if [ "$build_type" = "release" ]; then
100+
cmake_args="$cmake_args -DCMAKE_BUILD_TYPE=Release -DAVM_RELEASE=ON"
101+
else
102+
cmake_args="$cmake_args -DCMAKE_BUILD_TYPE=Debug"
103+
fi
104+
105+
mkdir -p "$build_dir"
106+
pushd "$build_dir" >/dev/null
107+
108+
[ "$clean_flag" ] && (rm CmakeCache.txt || true)
109+
log "Running 'emcmake cmake .. $cmake_args'."
110+
local cmake_out="$(emcmake cmake .. $cmake_args 2>&1)"
111+
[[ $? -ne 0 ]] && error "emcmake failed:\n$cmake_out"
112+
113+
[ "$clean_flag" ] && ninja clean
114+
log "Running 'ninja AtomVM'."
115+
emmake ninja AtomVM
116+
popd >/dev/null
117+
118+
log "Compressing."
119+
for artifact in "AtomVM.mjs" "AtomVM.wasm"; do
120+
[ ! -f "$build_dir/src/$artifact" ] && error "Required WASM artifact $artifact not found in $build_dir/src/"
121+
122+
cp "$build_dir/src/$artifact" "out/"
123+
gzip -c "$build_dir/src/$artifact" > "out/$artifact.gz" || error "Failed to compress $artifact"
124+
done
125+
}
126+
127+
main() {
128+
local CLEAN_FLAG=""
129+
local BUILD_MODE=""
130+
131+
# Parse arguments
132+
while [[ $# -gt 0 ]]; do
133+
case $1 in
134+
--clean)
135+
CLEAN_FLAG="true"
136+
shift
137+
;;
138+
*)
139+
if [ -z "$BUILD_MODE" ]; then
140+
BUILD_MODE=$1
141+
shift
142+
else
143+
usage
144+
fi
145+
;;
146+
esac
147+
done
148+
149+
[ -z "$BUILD_MODE" ] && usage
150+
151+
# Get script directory and change to project root
152+
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
153+
cd "$SCRIPT_DIR"
154+
155+
check_tools
156+
cleanup_output
157+
case $BUILD_MODE in
158+
debug-unix)
159+
build_unix "debug" "$CLEAN_FLAG"
160+
;;
161+
release-unix)
162+
build_unix "release" "$CLEAN_FLAG"
163+
;;
164+
debug-wasm)
165+
build_wasm "debug" "$CLEAN_FLAG"
166+
;;
167+
release-wasm)
168+
build_wasm "release" "$CLEAN_FLAG"
169+
;;
170+
*)
171+
usage
172+
;;
173+
esac
174+
175+
log "Finished."
176+
}
177+
178+
main "$@"

0 commit comments

Comments
 (0)