blob: 7f7de7fe7d1c4b441d22a1a3304ee9e395343359 [file]
#!/bin/bash
# Builds the distributable wamrc: static against a trimmed LLVM (AArch64 +
# X86 backends only), no dylib dependencies, shippable beside the editor.
# Usage: build_wamrc_dist.sh <work_dir> [wamr_source_dir]
# On Windows run it from Git Bash inside an x64 MSVC developer environment.
set -e
WINDOWS=
case "$(uname -s)" in
MINGW* | MSYS*) WINDOWS=1 ;;
esac
# Windows has no system zlib, and the CRT links statically so wamrc.exe ships
# alone. wamr-compiler predates CMP0091, which the runtime library needs.
ZLIB=ON
PLATFORM_FLAGS=()
if [[ -n $WINDOWS ]]; then
ZLIB=OFF
PLATFORM_FLAGS=(
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW
)
fi
WORK="${1:?work dir required}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Default to the vendored, patched clone two packages over; CI passes its own.
WAMR_SRC="${2:-$(ls -d "$SCRIPT_DIR"/../../rive-cli/dependencies/bytecodealliance_wasm-micro-runtime_WAMR-* 2>/dev/null | head -1)}"
[ -d "$WAMR_SRC/wamr-compiler" ] || {
echo "wamr source not found: $WAMR_SRC" >&2
exit 1
}
mkdir -p "$WORK"
cd "$WORK"
# WAMR 2.4.x builds against LLVM release/18.x.
if [ ! -d llvm ]; then
git clone --depth 1 --branch release/18.x \
https://github.com/llvm/llvm-project.git llvm
fi
cmake -S llvm/llvm -B llvm-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
-DLLVM_BUILD_LLVM_DYLIB=OFF \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_ZLIB=$ZLIB \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_UTILS=OFF \
-DLLVM_APPEND_VC_REV=OFF \
-DLLVM_TOOL_LTO_BUILD=OFF \
-DLLVM_TOOL_REMARKS_SHLIB_BUILD=OFF \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
"${PLATFORM_FLAGS[@]}"
cmake --build llvm-build
cmake -S "$WAMR_SRC/wamr-compiler" -B wamrc-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DWAMR_BUILD_WITH_CUSTOM_LLVM=1 \
-DLLVM_DIR="$PWD/llvm-build/lib/cmake/llvm" \
"${PLATFORM_FLAGS[@]}"
cmake --build wamrc-build
if [[ -n $WINDOWS ]]; then
cp wamrc-build/wamrc.exe wamrc.exe
# The dist contract: only system DLLs, no CRT redistributable or LLVM.
if dumpbin -nologo -dependents wamrc.exe |
grep -iE "vcruntime|msvcp|api-ms-win-crt|llvm|zlib"; then
echo "wamrc.exe links non-system DLLs" >&2
exit 1
fi
./wamrc.exe --version
ls -la wamrc.exe | awk '{print "dist wamrc size:", $5, "bytes"}'
exit 0
fi
strip -x wamrc-build/wamrc -o wamrc
# The dist contract: no non-system dylibs, or it cannot ship in a bundle.
if otool -L wamrc | grep -vE "wamrc:|/usr/lib/" | grep -q .; then
echo "wamrc links non-system dylibs:" >&2
otool -L wamrc >&2
exit 1
fi
./wamrc --version
ls -la wamrc | awk '{print "dist wamrc size:", $5, "bytes"}'