Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·158 lines (149 loc) · 8.33 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·158 lines (149 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Get number of CPU cores
CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1)
echo "Installing dependencies"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
SUDO=''
if command -v sudo >/dev/null; then
# sudo is present on the system, so use it
SUDO='sudo'
fi
echo "Installing apt packages"
$SUDO apt-get install --yes cmake llvm clang pkg-config m4 unzip \
wget curl python3-dev
# SpiderMonkey's configure requires libstdc++ >= 10 (toolchain.configure,
# minimum_gcc_version). Ubuntu 20.04, which CI builds in for wheel
# compatibility, defaults to gcc-9's; the -10 headers are in its own repos
# and don't change which libstdc++.so the wheel links against.
$SUDO apt-get install --yes libstdc++-10-dev
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
# shellcheck source=cmake/macos-brew-deps.sh
source "$(dirname "${BASH_SOURCE[0]}")/cmake/macos-brew-deps.sh"
install_macos_brew_deps
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then # Windows
echo "Dependencies are not going to be installed automatically on Windows."
else
echo "Unsupported OS"
exit 1
fi
# Install rust compiler, skipping if the pinned toolchain is already the
# default so this script can be re-run without re-downloading the installer.
if command -v rustup >/dev/null && rustup default 2>/dev/null | grep -q '^1\.90'; then
echo "Rust 1.90 toolchain already installed, skipping rustup-init"
else
echo "Installing rust compiler"
unset HOST_ABI_FLAGS
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then # Windows
HOST_ABI_FLAGS=("--default-host" "$(clang --print-target-triple)")
fi
# SpiderMonkey's configure requires rustc >= 1.90.0
curl --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/rust-lang/rustup/refs/tags/1.28.2/rustup-init.sh -sSf | sh -s -- -y ${HOST_ABI_FLAGS+"${HOST_ABI_FLAGS[@]}"} --default-toolchain 1.90.0
fi
CARGO_BIN="$HOME/.cargo/bin/cargo" # also works for Windows. On Windows this equals to %USERPROFILE%\.cargo\bin\cargo
command -v cbindgen >/dev/null || $CARGO_BIN install cbindgen
# Setup Poetry
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then # Windows
POETRY_BIN="$APPDATA/Python/Scripts/poetry"
else
POETRY_BIN="$HOME/.local/bin/poetry"
fi
# Skip if already installed, for the same re-run reason as rustup above.
if [ -x "$POETRY_BIN" ]; then
echo "Poetry already installed, skipping"
else
echo "Installing poetry"
# Windows Python installs often provide `python` but not `python3`
PYTHON_FOR_POETRY=$(command -v python3 || command -v python)
curl -sSL https://install.python-poetry.org | "$PYTHON_FOR_POETRY" - --version "1.8.5"
"$POETRY_BIN" self add 'poetry-dynamic-versioning[plugin]'
fi
echo "Done installing dependencies"
echo "Downloading spidermonkey source code"
# Read the commit hash for mozilla-central from the `mozcentral.version` file
MOZCENTRAL_VERSION=$(cat mozcentral.version)
# Skip if already extracted so this script can be re-run after a later failure.
if [ ! -d firefox-source ]; then
# curl rather than wget: it ships with Windows, macOS and most Linux distros
curl -fsSL -o firefox-source-${MOZCENTRAL_VERSION}.zip https://github.com/mozilla-firefox/firefox/archive/${MOZCENTRAL_VERSION}.zip
unzip -q firefox-source-${MOZCENTRAL_VERSION}.zip && mv firefox-${MOZCENTRAL_VERSION} firefox-source
else
echo "firefox-source already exists, skipping download+extract"
fi
echo "Done downloading spidermonkey source code"
echo "Building spidermonkey"
cd firefox-source
# Apply patching
# making it work for both GNU and BSD (macOS) versions of sed
sed -i'' -e 's/os not in ("WINNT", "OSX", "Android")/os not in ("WINNT", "Android")/' ./build/moz.configure/pkg.configure # use pkg-config on macOS
sed -i'' -e 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./js/public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey
sed -i'' -e 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./js/src/vm/JSObject.cpp # same here
sed -i'' -e 's/shared_lib = self._pretty_path(libdef.output_path, backend_file)/shared_lib = libdef.lib_name/' ./python/mozbuild/mozbuild/backend/recursivemake.py # would generate a Makefile to install the binary files from an invalid path prefix
sed -i'' -e 's/% self._pretty_path(libdef.import_path, backend_file)/% libdef.import_name/' ./python/mozbuild/mozbuild/backend/recursivemake.py # same as above. Shall we file a bug in bugzilla?
sed -i'' -e 's/if version < Version(mac_sdk_min_version())/if False/' ./build/moz.configure/toolchain.configure # do not verify the macOS SDK version as the required version is not available on Github Actions runner
sed -i'' -e 's/return JS::GetWeakRefsEnabled() == JS::WeakRefSpecifier::Disabled/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable FinalizationRegistry
sed -i'' -e 's/return !IsIteratorHelpersEnabled()/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable iterator helpers
sed -i'' -e '/MOZ_CRASH_UNSAFE_PRINTF/,/__PRETTY_FUNCTION__);/d' ./mfbt/LinkedList.h # would crash in Debug Build: in `~LinkedList()` it should have removed all this list's elements before the list's destruction
sed -i'' -e '/MOZ_ASSERT(stackRootPtr == nullptr);/d' ./js/src/vm/JSContext.cpp # would assert false in Debug Build since we extensively use `new JS::Rooted`
sed -i'' -e 's/"-fuse-ld=ld"/"-ld64" if c_compiler.version > "14.0.0" else "-fuse-ld=ld"/' ./build/moz.configure/toolchain.configure # XCode 15 changed the linker behaviour. See https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking
sed -i'' -e 's/defined(XP_WIN)/defined(_WIN32)/' ./mozglue/baseprofiler/public/BaseProfilerUtils.h # this header file is introduced to js/Debug.h in https://phabricator.services.mozilla.com/D221102, but it would be compiled without XP_WIN in this building configuration
sed -i'' -e 's/os\.environ\["MOZILLABUILD"\]/os.environ.get("MOZILLABUILD", "")/g' ./python/mozbuild/mozbuild/backend/visualstudio.py # avoid KeyError: we don't use the official Mozilla Build package, so this is never set
cd js/src
mkdir -p _build
cd _build
mkdir -p ../../../../_spidermonkey_install/
../configure --target=$(clang --print-target-triple) \
--prefix=$(realpath $PWD/../../../../_spidermonkey_install) \
--with-intl-api \
$(if [[ "$OSTYPE" != "msys"* && "$OSTYPE" != "cygwin"* ]]; then echo "--without-system-zlib"; fi) \
--disable-debug-symbols \
--disable-jemalloc \
--disable-tests \
--disable-bootstrap \
$(if [[ "$OSTYPE" == "darwin"* ]]; then echo "--enable-linker=ld64"; fi) \
--enable-optimize
# --disable-explicit-resource-management (Bugzilla 1940342 workaround) is no
# longer a recognized flag; the feature it gated has shipped.
make -j$CPUS
echo "Done building spidermonkey"
echo "Installing spidermonkey"
# install to ../../../../_spidermonkey_install/
make install
if [[ "$OSTYPE" == "darwin"* ]]; then # macOS
cd ../../../../_spidermonkey_install/lib/
# Set the `install_name` field to use RPATH instead of an absolute path
# overrides https://hg.mozilla.org/releases/mozilla-esr102/file/89d799cb/js/src/build/Makefile.in#l83
install_name_tool -id @rpath/$(basename ./libmozjs*) ./libmozjs* # making it work for whatever name the libmozjs dylib is called
fi
echo "Done installing spidermonkey"
# if this is being ran in the root directory of the PythonMonkey repo, then include dev configurations
if test -f .git/hooks/pre-commit; then
# set git hooks
ln -s -f ../../githooks/pre-commit .git/hooks/pre-commit
# set blame ignore file
git config blame.ignorerevsfile .git-blame-ignore-revs
# install autopep8
$POETRY_BIN run pip install autopep8
# install uncrustify
echo "Downloading uncrustify source code"
wget -c -q https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.78.1.tar.gz
mkdir -p uncrustify-source
tar -xzf uncrustify-0.78.1.tar.gz -C uncrustify-source --strip-components=1 # strip the root folder
echo "Done downloading uncrustify source code"
echo "Building uncrustify"
cd uncrustify-source
mkdir -p build
cd build
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then # Windows
cmake ../
cmake --build . -j$CPUS --config Release
cp Release/uncrustify.exe ../../uncrustify.exe
else
cmake ../
make -j$CPUS
cp uncrustify ../../uncrustify
fi
cd ../..
echo "Done building uncrustify"
fi