Skip to content

Commit

Permalink
Merge pull request #15 from cfallin/cfallin/dedup-build-scripts
Browse files Browse the repository at this point in the history
Deduplicate build-engine.sh and rebuild.sh.
  • Loading branch information
cfallin authored Jul 25, 2024
2 parents ffbf1c4 + 559644d commit 2575d3d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 123 deletions.
83 changes: 44 additions & 39 deletions build-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mode="${1:-release}"
mozconfig="${working_dir}/mozconfig-${mode}"
objdir="obj-$mode"
outdir="$mode"
rebuild="${REBUILD_ENGINE:-0}"

cat << EOF > "$mozconfig"
ac_add_options --enable-project=js
Expand Down Expand Up @@ -62,47 +63,51 @@ 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
# For a full build (not a rebuild), we need to clone the repo and do some setup work.
# `rebuild.sh` invokes this script with REBUILD_ENGINE=1 which sets rebuild=1
# and skips this setup.
if [[ $rebuild == 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
86 changes: 2 additions & 84 deletions rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,4 @@
#!/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=-O3
ac_add_options --enable-js-streams
ac_add_options --enable-portable-baseline-interp
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 \
CXX=~/.mozbuild/clang/bin/clang++ \
AR=~/.mozbuild/clang/bin/llvm-ar \
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"

cp js/src/build/libjs_static.a "wasm32-wasi/${mode}/libjsrust.a" "../$outdir/lib"
export REBUILD_ENGINE=1
exec $(dirname $0)/build-engine.sh "$@"

0 comments on commit 2575d3d

Please sign in to comment.