11#! /bin/bash
2+ root_path=" ./binaryen/libbinaryen"
3+
4+ if grep -Fxq $BINARYEN_VERSION $root_path /version; then
5+ # Existing version found
6+ echo " Found existing binaryen installation, skipping."
7+ echo " You may need to clear the binaryen/libbinaryen folder if errors occur"
8+ exit 0
9+ fi
210
311arch=$( uname -m)
412
13+ # Set the platform = 'macos' | 'linux' | 'windows'
514case " $( uname -sr) " in
615
716Darwin* )
@@ -30,42 +39,44 @@ if [ -z ${BINARYEN_VERSION+x} ]; then
3039 exit 1
3140fi
3241
33- lib_path=" ./binaryen/libbinaryen /$arch -$platform "
42+ lib_path=" $root_path /$arch -$platform "
3443mkdir -p $lib_path
3544
36- if grep -Fxq $BINARYEN_VERSION $lib_path /version; then
37- # Existing version found
38- echo " Found existing binaryen installation, skipping."
39- echo " You may need to clear the binaryen/libbinaryen folder if errors occur"
40- exit 0
41- fi
42-
4345wildcards=" --wildcards"
4446
4547if [[ " $platform " == " macos" ]]; then
48+ # Wildcards are supported by default on macOS
4649 wildcards=" "
4750fi
4851
4952echo " Setting up binaryen for $arch $platform "
5053
5154if [[ " $platform " == " macos" ]]; then
52- echo " Building static binaryen for MacOS "
53- mkdir -p " ./binaryen/libbinaryen /src/"
55+ echo " Building static binaryen for macOS "
56+ mkdir -p " $root_path /src/"
5457
5558 file=" version_$BINARYEN_VERSION .tar.gz"
5659 url=" https://github.com/WebAssembly/binaryen/archive/refs/tags/$file "
5760
58- wget -q -nc --no-check-certificate --content-disposition $url -P " ./binaryen/libbinaryen "
61+ wget -q -nc --no-check-certificate --content-disposition $url -P " $root_path "
5962 echo " Downloaded source code"
6063
61- tar -xzf " . /binaryen/libbinaryen/binaryen -$file " -C " ./binaryen/libbinaryen /src" --strip-components=1
64+ tar -xzf " $root_path /binaryen-$file " -C " $root_path /src" --strip-components=1
6265 echo " Extracted source code"
6366
64- cmake -S " ./binaryen/libbinaryen/src" -B " ./binaryen/libbinaryen/build/" -G Ninja \
65- -DCMAKE_INSTALL_PREFIX=" $lib_path " -DCMAKE_OSX_ARCHITECTURES=$arch \
67+ echo " Building for Apple Silicon"
68+ cmake -S " $root_path /src" -B " $root_path /build/" -G Ninja \
69+ -DCMAKE_INSTALL_PREFIX=" " $root_path /arm64-macos" " -DCMAKE_OSX_ARCHITECTURES=" arm64" \
70+ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF \
71+ -DBUILD_STATIC_LIB=ON
72+ cmake --build " $root_path /build/" -v --config Release --target install
73+
74+ echo " Build for Intel"
75+ cmake -S " $root_path /src" -B " $root_path /build/" -G Ninja \
76+ -DCMAKE_INSTALL_PREFIX=" " $root_path /x86_64-macos" " -DCMAKE_OSX_ARCHITECTURES=" x86_64" \
6677 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF \
6778 -DBUILD_STATIC_LIB=ON
68- cmake --build " ./binaryen/libbinaryen /build/" -v --config Release --target install
79+ cmake --build " $root_path /build/" -v --config Release --target install
6980else
7081 file=" binaryen-version_$BINARYEN_VERSION -$arch -$platform .tar.gz"
7182 url=" https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION /$file "
@@ -84,4 +95,4 @@ echo "Generating C def file"
8495python3 ./scripts/create_cdef.py
8596echo " Successfully generated C def file"
8697
87- echo " $BINARYEN_VERSION " > | $lib_path /version
98+ echo " $BINARYEN_VERSION " > | $root_path /version
0 commit comments