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 1 commit
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
49 changes: 30 additions & 19 deletions build-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,44 @@
set -euo pipefail
set -x

if (wasm-opt --version | grep -q "wasm-opt version" ); then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our js-compute-runtime build still assumes wasm-opt in path, so I think this may cause conflicts?

@elliottt maybe we should take an approach in js-compute-runtime of using different pathing finally here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check actually fails if you don't have wasm-opt in PATH, so it seems like it must be set to /bin/true for this to pass?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is the confusing nature of shell scripting: it's meant to fail (and does fail) if we do have wasm-opt in $PATH. The subshell (in parens) returns exit code 1 (failure) if wasm-opt doesn't exist or grep fails to find the text (and returns its own failure code). The if in the parent shell takes 0 as truthy, so this is saying "if success (wasm-opt exists and is real wasm-opt), then fail with message".

To the broader point of wasm-opt existing for the rest of the build... this indicates to me that perhaps the better approach is to actively mask wasm-opt with a wrapper and put that at the front of PATH for this build. I'll make that change; it's more general anyway!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this instead?

Suggested change
if (wasm-opt --version | grep -q "wasm-opt version" ); then
if command -v wasm-opt > /dev/null; then

Copy link

@elliottt elliottt May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The js-compute-runtime does use wasm-opt to strip builds, this might make it difficult to run both builds in the same machine. We worked around the use of wasm-opt by llvm by temporarily putting a shell script that exits immediately in the path earlier than the real wasm-opt. Would that be an option here?

You suggested this in an earlier comment, and I missed it completely :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some edits to this branch, in a different branch https://github.com/fastly/spidermonkey-wasi-embedding/tree/jake/weval-edits which has a similar change but only for CI and not the build.sh script itself

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I pulled in your updates to the gitignore list @JakeChampion and I've pushed an update that shadows wasm-opt with its own fake-bin directory in PATH. This avoids the need to move it out of the way during the CI build. I also went ahead and merged rebuild.sh with build-engine.sh (former calls later with an arg) because it was getting a little too unwieldy to duplicate logic.

echo "wasm-opt corrupts the SpiderMonkey build; please remove it or alias it to /bin/true!"
exit 1
fi

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

if [ $# -eq 1 ]; then
$0 $1 normal
$0 $1 weval
exit 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
# 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
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
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
f0dc4ca253349a4b8bd3bd253fa8421e76888326
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
41 changes: 22 additions & 19 deletions rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@
set -euo pipefail
set -x

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

if (wasm-opt --version | grep -q "wasm-opt version" ); then
echo "wasm-opt corrupts the SpiderMonkey build; please remove it or alias it to /bin/true!"
exit 1
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
mode=$1
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
Loading