2 # This script is called by update-workspaces.sh / build-osx-libraries.sh
5 # This should match the version in config/milestone.txt
7 # If same-version changes are needed, increment this.
8 LIB_VERSION
="91.13.1+2"
11 # Since this script is called by update-workspaces.sh, we want to quickly
12 # avoid doing any work if SpiderMonkey is already built and up-to-date.
13 # Running SM's Makefile is a bit slow and noisy, so instead we'll make a
14 # special file and only rebuild if the build.sh version differs.
15 if [ -e .already-built
] && [ "$(cat .already-built)" = "${LIB_VERSION}" ]
17 echo "SpiderMonkey is already up to date."
21 echo "Building SpiderMonkey..."
24 # Prevent the SpiderMonkey build system from reading dependencies from
25 # user-installed python packages.
28 OS
="${OS:=$(uname -s)}"
30 # Use Mozilla make on Windows
31 if [ "${OS}" = "Windows_NT" ]
40 # Standalone SpiderMonkey can not use jemalloc (see https://bugzilla.mozilla.org/show_bug.cgi?id=1465038)
41 # Jitspew doesn't compile on VS17 in the zydis disassembler - since we don't use it, deactivate it.
42 # Trace-logging doesn't compile for now.
43 CONF_OPTS
="--disable-tests
52 CONF_OPTS
="$CONF_OPTS --enable-profiling
56 --with-jitreport-granularity=3"
59 if [ "${OS}" = "Windows_NT" ]
61 CONF_OPTS
="${CONF_OPTS} --target=i686"
62 elif [ "${OS}" = "Darwin" ]
64 # Unless we are forcing an architecture, switch between ARM / x86 based on platform.
65 if [ -z "${ARCH}" ]; then
66 if [ "$(uname -m)" == "arm64" ]
73 CONF_OPTS
="${CONF_OPTS} --target=$ARCH-apple-darwin"
75 # Link to custom-built zlib
76 export PKG_CONFIG_PATH
="=${ZLIB_DIR}:${PKG_CONFIG_PATH}"
77 CONF_OPTS
="${CONF_OPTS} --with-system-zlib"
78 # Specify target versions and SDK
79 if [ "${MIN_OSX_VERSION}" ] && [ "${MIN_OSX_VERSION-_}" ]; then
80 CONF_OPTS
="${CONF_OPTS} --enable-macos-target=$MIN_OSX_VERSION"
82 if [ "${SYSROOT}" ] && [ "${SYSROOT-_}" ]; then
83 CONF_OPTS
="${CONF_OPTS} --with-macos-sdk=${SYSROOT}"
87 LLVM_OBJDUMP
=${LLVM_OBJDUMP:=$(command -v llvm-objdump || command -v objdump)}
89 # Quick sanity check to print explicit error messages
90 # (Don't run this on windows as it would likely fail spuriously)
91 if [ "${OS}" != "Windows_NT" ]
93 [ -n "$(command -v rustc)" ] ||
(echo "Error: rustc is not available. Install the rust toolchain (rust + cargo) before proceeding." && exit 1)
94 [ -n "${LLVM_OBJDUMP}" ] ||
(echo "Error: LLVM objdump is not available. Install it (likely via LLVM-clang) before proceeding." && exit 1)
97 # If Valgrind looks like it's installed, then set up SM to support it
98 # (else the JITs will interact poorly with it)
99 if [ -e /usr
/include
/valgrind
/valgrind.h
]
101 CONF_OPTS
="${CONF_OPTS} --enable-valgrind"
104 # We need to be able to override CHOST in case it is 32bit userland on 64bit kernel
105 CONF_OPTS
="${CONF_OPTS} \
106 ${CBUILD:+--build=${CBUILD}} \
107 ${CHOST:+--host=${CHOST}} \
108 ${CTARGET:+--target=${CTARGET}}"
110 echo "SpiderMonkey build options: ${CONF_OPTS}"
112 # It can occasionally be useful to not rebuild everything, but don't do this by default.
113 REBUILD
=${REBUILD:=true}
114 if [ $REBUILD = true
]
116 # Delete the existing directory to avoid conflicts and extract the tarball
118 if [ ! -e "${FOLDER}.tar.xz" ]
120 # The tarball is committed to svn, but it's useful to let jenkins download it (when testing upgrade scripts).
121 download
="$(command -v wget || echo "curl
-L -o "${FOLDER}.tar.xz"")"
122 $download "https://github.com/wraitii/spidermonkey-tarballs/releases/download/${FOLDER}/${FOLDER}.tar.xz"
124 tar xfJ
"${FOLDER}.tar.xz"
126 # Clean up header files that may be left over by earlier versions of SpiderMonkey
127 rm -rf include-unix-debug
128 rm -rf include-unix-release
132 # Prevent complaining that configure is outdated.
133 touch .
/js
/src
/configure
141 # Debug version of SM is broken on FreeBSD.
142 if [ "${OS}" != "FreeBSD" ]
146 # llvm-objdump is searched for with the complete name, not simply 'objdump', account for that.
147 CXXFLAGS
="${CXXFLAGS}" ..
/js
/src
/configure \
148 LLVM_OBJDUMP
="${LLVM_OBJDUMP}" \
157 mkdir
-p build-release
159 CXXFLAGS
="${CXXFLAGS}" ..
/js
/src
/configure \
160 LLVM_OBJDUMP
="${LLVM_OBJDUMP}" \
168 if [ "${OS}" = "Windows_NT" ]
170 INCLUDE_DIR_DEBUG
=include-win32-debug
171 INCLUDE_DIR_RELEASE
=include-win32-release
174 STATIC_LIB_SUFFIX
=.lib
176 INCLUDE_DIR_DEBUG
=include-unix-debug
177 INCLUDE_DIR_RELEASE
=include-unix-release
181 if [ "${OS}" = "OpenBSD" ];
184 elif [ "${OS}" = "Darwin" ];
190 if [ "${OS}" = "Windows_NT" ]
193 # SpiderMonkey uses a tweaked zlib when building, and it wrongly copies its own files to include dirs
194 # afterwards, so we have to remove them to not have them conflicting with the regular zlib
195 pushd "${FOLDER}/build-release/dist/include"
196 rm -f mozzconf.h zconf.h zlib.h
198 pushd "${FOLDER}/build-debug/dist/include"
199 rm -f mozzconf.h zconf.h zlib.h
203 # Copy files into the necessary locations for building and running the game
205 # js-config.h is different for debug and release builds, so we need different include directories for both
206 mkdir
-p "${INCLUDE_DIR_RELEASE}"
207 cp -R -L "${FOLDER}"/build-release
/dist
/include
/* "${INCLUDE_DIR_RELEASE}/"
209 if [ "${OS}" != "FreeBSD" ]; then
210 mkdir
-p "${INCLUDE_DIR_DEBUG}"
211 cp -R -L "${FOLDER}"/build-debug
/dist
/include
/* "${INCLUDE_DIR_DEBUG}/"
214 # These align the ligns below, making it easier to check for mistakes.
220 # Fetch the jsrust static library. Path is grepped from the build file as it varies by rust toolset.
221 rust_path
=$
(grep jsrust
< "${FOLDER}/build-release/js/src/build/backend.mk" | cut
-d = -f 2 | cut
-c2-)
222 cp -L "${rust_path}" "lib/${LIB_PREFIX}${LIB_NAME}-rust${STATIC_LIB_SUFFIX}"
224 if [ "${OS}" = "Darwin" ]
226 # On MacOS, copy the static libraries only.
227 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}js_static${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}"
228 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}js_static${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}"
229 elif [ "${OS}" = "Windows_NT" ]
231 # Windows needs DLLs to binaries/, static stubs to lib/ and debug symbols
232 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}"
233 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}"
234 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${STATIC_LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${DEB}${STATIC_LIB_SUFFIX}"
235 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${STATIC_LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${REL}${STATIC_LIB_SUFFIX}"
236 # Copy debug symbols as well.
237 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}.pdb" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${DEB}.pdb"
238 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}.pdb" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${REL}.pdb"
239 # Copy the debug jsrust library.
240 rust_path
=$
(grep jsrust
< "${FOLDER}/build-debug/js/src/build/backend.mk" | cut
-d = -f 2 | cut
-c2-)
241 cp -L "${rust_path}" "lib/${LIB_PREFIX}${LIB_NAME}-rust-debug${STATIC_LIB_SUFFIX}"
243 # Copy shared libs to both lib/ and binaries/ so the compiler and executable (resp.) can find them.
244 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}"
245 cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}"
246 if [ "${OS}" != "FreeBSD" ]; then
247 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" "../../../binaries/system/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}"
248 cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}"
252 # Flag that it's already been built successfully so we can skip it next time
253 echo "${LIB_VERSION}" > .already-built