Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Pull in weval branch of SpiderMonkey and add build. #17

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ jobs:
run: |
mkdir dist
sudo apt-get update -y
bash ./build-engine.sh release
tar -a -cf dist/spidermonkey-wasm-static-lib_release.tar.gz release
rm -rf release obj-release
bash ./build-engine.sh debug
tar -a -cf dist/spidermonkey-wasm-static-lib_debug.tar.gz debug
bash ./build-engine.sh release normal
tar -a -cf dist/spidermonkey-wasm-static-lib_release_normal.tar.gz release-normal
rm -rf release-normal obj-release-normal
bash ./build-engine.sh release weval
tar -a -cf dist/spidermonkey-wasm-static-lib_release_weval.tar.gz release-weval
rm -rf release-weval obj-release-weval
bash ./build-engine.sh debug normal
tar -a -cf dist/spidermonkey-wasm-static-lib_debug_normal.tar.gz debug-normal
rm -rf debug-normal obj-debug-normal
bash ./build-engine.sh debug weval
tar -a -cf dist/spidermonkey-wasm-static-lib_debug_weval.tar.gz debug-weval
rm -rf debug-weval obj-debug-weval

- name: Calculate tag name
run: |
Expand Down
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/gecko-dev
/obj-release
/obj-debug
/release
/debug
/obj-release-normal
/obj-debug-normal
/obj-release-weval
/obj-debug-weval
/release-normal
/debug-normal
/release-weval
/debug-weval
/dist
/mozconfig-*
.DS_Store
Expand Down
132 changes: 74 additions & 58 deletions build-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@
set -euo pipefail
set -x

if [ $# -lt 1 ]; then
echo "Usage: build.sh {release|debug} [{normal|weval}] [rebuild]"
exit 1
fi

if [ $# -eq 1 ]; then
$0 $1 normal
$0 $1 weval
exit 0
fi

if [ $# -eq 3 ]; then
rebuild=1
else
rebuild=0
fi

working_dir="$(pwd)"
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

mode="${1:-release}"
mozconfig="${working_dir}/mozconfig-${mode}"
objdir="obj-$mode"
outdir="$mode"

cat << EOF > "$mozconfig"
ac_add_options --enable-project=js
ac_add_options --enable-application=js
ac_add_options --target=wasm32-unknown-wasi
ac_add_options --without-system-zlib
ac_add_options --without-intl-api
ac_add_options --disable-jit
ac_add_options --disable-shared-js
ac_add_options --disable-shared-memory
ac_add_options --disable-tests
ac_add_options --disable-clang-plugin
ac_add_options --enable-jitspew
ac_add_options --enable-optimize
ac_add_options --enable-js-streams
# Add fake wasm-opt to PATH.
export PATH=$script_dir/fake-bin:$PATH

# Mode: release or debug
mode=$1
# Variant: normal or weval
variant=$2
mozconfig="${working_dir}/mozconfig-${mode}-${variant}"
objdir="obj-$mode-$variant"
outdir="$mode-$variant"

cat $script_dir/mozconfig.defaults > "$mozconfig"
cat << EOF >> "$mozconfig"
ac_add_options --prefix=${working_dir}/${objdir}/dist
mk_add_options MOZ_OBJDIR=${working_dir}/${objdir}
mk_add_options AUTOCLOBBER=1
EOF

if [ "$variant" == "weval" ]; then
cat $script_dir/mozconfig.weval >> "$mozconfig"
fi

target="$(uname)"
case "$target" in
Linux)
Expand Down Expand Up @@ -61,47 +76,48 @@ case "$mode" in
;;
esac


# Ensure the Rust version matches that used by Gecko, and can compile to WASI
rustup target add wasm32-wasi

fetch_commits=
if [[ ! -a gecko-dev ]]; then

# Clone Gecko repository at the required revision
mkdir gecko-dev

git -C gecko-dev init
git -C gecko-dev remote add --no-tags -t wasi-embedding \
origin "$(cat "$script_dir/gecko-repository")"

fetch_commits=1
if [ $rebuild -eq 0 ]; then
# Ensure the Rust version matches that used by Gecko, and can compile to WASI
rustup target add wasm32-wasi

fetch_commits=
if [[ ! -a gecko-dev ]]; then

# Clone Gecko repository at the required revision
mkdir gecko-dev

git -C gecko-dev init
git -C gecko-dev remote add --no-tags -t wasi-embedding \
origin "$(cat "$script_dir/gecko-repository")"

fetch_commits=1
fi

target_rev="$(cat "$script_dir/gecko-revision")"
if [[ -n "$fetch_commits" ]] || \
[[ "$(git -C gecko-dev rev-parse HEAD)" != "$target_rev" ]]; then
git -C gecko-dev fetch --depth 1 origin "$target_rev"
git -C gecko-dev checkout FETCH_HEAD
fi

# Use Gecko's build system bootstrapping to ensure all dependencies are
# installed
cd gecko-dev
./mach --no-interactive bootstrap --application-choice=js --no-system-changes

# ... except, that doesn't install the wasi-sysroot, which we need, so we do
# that manually.
cd ~/.mozbuild
python3 \
"${working_dir}/gecko-dev/mach" \
--no-interactive \
artifact \
toolchain \
--bootstrap \
--from-build \
sysroot-wasm32-wasi
fi

target_rev="$(cat "$script_dir/gecko-revision")"
if [[ -n "$fetch_commits" ]] || \
[[ "$(git -C gecko-dev rev-parse HEAD)" != "$target_rev" ]]; then
git -C gecko-dev fetch --depth 1 origin "$target_rev"
git -C gecko-dev checkout FETCH_HEAD
fi

# Use Gecko's build system bootstrapping to ensure all dependencies are
# installed
cd gecko-dev
./mach --no-interactive bootstrap --application-choice=js --no-system-changes

# ... except, that doesn't install the wasi-sysroot, which we need, so we do
# that manually.
cd ~/.mozbuild
python3 \
"${working_dir}/gecko-dev/mach" \
--no-interactive \
artifact \
toolchain \
--bootstrap \
--from-build \
sysroot-wasm32-wasi

cd "$working_dir"

# Build SpiderMonkey for WASI
Expand Down
9 changes: 3 additions & 6 deletions download-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# # Get github repository url
gh_url='https://github.'$(cd "$script_dir" && git remote get-url origin | cut -f2 -d. | tr ':' /)

mode="release"
if [[ $1 == "debug" ]]
then
mode="debug"
fi
mode=${1:release}
variant=${2:normal}

git_rev="$(git -C "$script_dir" rev-parse HEAD)"
file="spidermonkey-wasm-static-lib_${mode}.tar.gz"
file="spidermonkey-wasm-static-lib_${mode}_${variant}.tar.gz"
bundle_url="${gh_url}/releases/download/rev_${git_rev}/${file}"

curl --fail -L -O "$bundle_url"
Expand Down
3 changes: 3 additions & 0 deletions fake-bin/wasm-opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

true
2 changes: 1 addition & 1 deletion gecko-repository
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/bytecodealliance/gecko-dev
https://github.com/bytecodealliance/gecko-dev
2 changes: 1 addition & 1 deletion gecko-revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
69d3daaa3aa4589ac8e60a94c7c7e0592882d272
d29fd604c983d7267a322af9a7e1552debcc659f
13 changes: 13 additions & 0 deletions mozconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ac_add_options --enable-project=js
ac_add_options --enable-application=js
ac_add_options --target=wasm32-unknown-wasi
ac_add_options --without-system-zlib
ac_add_options --without-intl-api
ac_add_options --disable-jit
ac_add_options --disable-shared-js
ac_add_options --disable-shared-memory
ac_add_options --disable-tests
ac_add_options --disable-clang-plugin
ac_add_options --enable-jitspew
ac_add_options --enable-optimize
ac_add_options --enable-js-streams
3 changes: 3 additions & 0 deletions mozconfig.weval
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ac_add_options --enable-js-interp-native-callstack
ac_add_options --enable-js-interp-specialization
ac_add_options --enable-js-interp-weval
81 changes: 2 additions & 79 deletions rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,83 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
set -x

working_dir="$(pwd)"
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

mode="${1:-release}"
mozconfig="${working_dir}/mozconfig-${mode}"
objdir="obj-$mode"
outdir="$mode"

cat << EOF > "$mozconfig"
ac_add_options --enable-project=js
ac_add_options --enable-application=js
ac_add_options --target=wasm32-unknown-wasi
ac_add_options --without-system-zlib
ac_add_options --without-intl-api
ac_add_options --disable-jit
ac_add_options --disable-shared-js
ac_add_options --disable-shared-memory
ac_add_options --disable-tests
ac_add_options --disable-clang-plugin
ac_add_options --enable-jitspew
ac_add_options --enable-optimize
ac_add_options --enable-js-streams
ac_add_options --prefix=${working_dir}/${objdir}/dist
mk_add_options MOZ_OBJDIR=${working_dir}/${objdir}
mk_add_options AUTOCLOBBER=1
EOF

target="$(uname)"
case "$target" in
Linux)
echo "ac_add_options --disable-stdcxx-compat" >> "$mozconfig"
;;

Darwin)
echo "ac_add_options --host=aarch64-apple-darwin" >> "$mozconfig"
;;

*)
echo "Unsupported build target: $target"
exit 1
;;
esac

case "$mode" in
release)
echo "ac_add_options --disable-debug" >> "$mozconfig"
;;

debug)
echo "ac_add_options --enable-debug" >> "$mozconfig"
;;

*)
echo "Unknown build type: $mode"
exit 1
;;
esac

# Build SpiderMonkey for WASI
MOZCONFIG="${mozconfig}" \
MOZ_FETCHES_DIR=~/.mozbuild \
CC=~/.mozbuild/clang/bin/clang \
python3 "${working_dir}/gecko-dev/mach" \
--no-interactive \
build

# Copy header, object, and static lib files
rm -rf "$outdir"
mkdir -p "$outdir/lib"

cd "$objdir"
cp -Lr dist/include "../$outdir"

while read -r file; do
cp "$file" "../$outdir/lib"
done < "$script_dir/object-files.list"
variant="${2:-weval}"

cp js/src/build/libjs_static.a "wasm32-wasi/${mode}/libjsrust.a" "../$outdir/lib"
exec `dirname $0`/build-engine.sh $mode $variant rebuild