From 682de9f2891c5f08f76c6be16ba324be87d61027 Mon Sep 17 00:00:00 2001 From: Itms Date: Tue, 8 Oct 2024 21:54:14 +0200 Subject: [PATCH] Unbundle SpiderMonkey This deletes the RETRY flag from the build script, which can be manually mocked if needed. --- build/premake/extern_libs5.lua | 25 +- libraries/build-source-libs.sh | 2 +- libraries/source/spidermonkey/build.sh | 213 +++++++++++++++++- .../spidermonkey/patches/FixClang16Build.diff | 24 ++ .../patches/FixFedoraVirtualEnv.diff | 15 ++ .../spidermonkey/patches/FixFpNormIssue.diff | 110 +++++++++ .../patches/FixInstallScheme.diff | 26 +++ .../spidermonkey/patches/FixLibNames.diff | 16 ++ .../spidermonkey/patches/FixRustLinkage.diff | 16 ++ .../patches/FixUnicodePython311.diff | 130 +++++++++++ .../spidermonkey/patches/FixVirtualEnv.diff | 16 ++ .../source/spidermonkey/patches/patch.sh | 55 +++++ 12 files changed, 619 insertions(+), 29 deletions(-) create mode 100644 libraries/source/spidermonkey/patches/FixClang16Build.diff create mode 100644 libraries/source/spidermonkey/patches/FixFedoraVirtualEnv.diff create mode 100644 libraries/source/spidermonkey/patches/FixFpNormIssue.diff create mode 100644 libraries/source/spidermonkey/patches/FixInstallScheme.diff create mode 100644 libraries/source/spidermonkey/patches/FixLibNames.diff create mode 100644 libraries/source/spidermonkey/patches/FixRustLinkage.diff create mode 100644 libraries/source/spidermonkey/patches/FixUnicodePython311.diff create mode 100644 libraries/source/spidermonkey/patches/FixVirtualEnv.diff create mode 100755 libraries/source/spidermonkey/patches/patch.sh diff --git a/build/premake/extern_libs5.lua b/build/premake/extern_libs5.lua index a710c0bb9c..5109d810dd 100644 --- a/build/premake/extern_libs5.lua +++ b/build/premake/extern_libs5.lua @@ -642,23 +642,18 @@ extern_lib_defs = { pkgconfig.add_includes_after("mozjs-91") end else - if os.istarget("windows") then - include_dir = "include-win32" - else - include_dir = "include-unix" - end filter "Debug" if externalincludedirs then - externalincludedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-debug" } + externalincludedirs { libraries_source_dir.."spidermonkey/include-debug" } else - sysincludedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-debug" } + sysincludedirs { libraries_source_dir.."spidermonkey/include-debug" } end defines { "DEBUG" } filter "Release" if externalincludedirs then - externalincludedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-release" } + externalincludedirs { libraries_source_dir.."spidermonkey/include-release" } else - sysincludedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-release" } + sysincludedirs { libraries_source_dir.."spidermonkey/include-release" } end filter { } end @@ -671,16 +666,12 @@ extern_lib_defs = { pkgconfig.add_links("mozjs-91") end else - filter { "Debug", "action:vs*" } - links { "mozjs91-ps-debug" } - links { "mozjs91-ps-rust-debug" } - filter { "Debug", "action:not vs*" } - links { "mozjs91-ps-debug" } - links { "mozjs91-ps-rust" } + filter { "Debug" } + links { "mozjs91-debug" } filter { "Release" } - links { "mozjs91-ps-release" } - links { "mozjs91-ps-rust" } + links { "mozjs91-release" } filter { } + links { "mozjs91-rust" } add_source_lib_paths("spidermonkey") end end, diff --git a/libraries/build-source-libs.sh b/libraries/build-source-libs.sh index 461a3e40e8..6b53c9b631 100755 --- a/libraries/build-source-libs.sh +++ b/libraries/build-source-libs.sh @@ -76,7 +76,7 @@ fi echo if [ "$with_system_mozjs" = "false" ]; then ./source/spidermonkey/build.sh || die "SpiderMonkey build failed" - cp source/spidermonkey/bin/* ../binaries/system/ + cp source/spidermonkey/lib/* ../binaries/system/ fi echo if [ "$with_spirv_reflect" = "true" ]; then diff --git a/libraries/source/spidermonkey/build.sh b/libraries/source/spidermonkey/build.sh index ed83e80fc0..44abe59680 100755 --- a/libraries/source/spidermonkey/build.sh +++ b/libraries/source/spidermonkey/build.sh @@ -3,32 +3,223 @@ set -e cd "$(dirname "$0")" -LIB_VERSION=28209 +# This should match the version in config/milestone.txt +FOLDER="mozjs-91.13.1" +# If same-version changes are needed, increment this. +LIB_VERSION="91.13.1+2" +LIB_NAME="mozjs91" if [ -e .already-built ] && [ "$(cat .already-built)" = "${LIB_VERSION}" ]; then echo "Spidermonkey is already up to date." exit fi +OS="${OS:=$(uname -s)}" + # fetch -svn co "https://svn.wildfiregames.com/public/source-libs/trunk/spidermonkey@${LIB_VERSION}" spidermonkey-svn +if [ ! -e "${FOLDER}.tar.xz" ]; then + curl -fLo "${FOLDER}.tar.xz" \ + "https://svn.wildfiregames.com/public/source-libs/trunk/spidermonkey/${FOLDER}.tar.xz" +fi # unpack -rm -Rf spidermonkey-build -cp -R spidermonkey-svn spidermonkey-build +rm -Rf "${FOLDER}" +tar xfJ "${FOLDER}.tar.xz" + +# patch +( + cd "${FOLDER}" + # shellcheck disable=SC1091 + . ../patches/patch.sh +) # build ( - cd spidermonkey-build - mkdir bin lib - ./build.sh + cd "${FOLDER}" + + # Prevent the SpiderMonkey build system from reading dependencies from + # user-installed python packages. + PYTHONNOUSERSITE=true + + # Use Mozilla make on Windows + if [ "${OS}" = "Windows_NT" ]; then + MAKE="mozmake" + else + MAKE=${MAKE:="make"} + fi + + MAKE_OPTS="${JOBS}" + + # Standalone SpiderMonkey can not use jemalloc (see https://bugzilla.mozilla.org/show_bug.cgi?id=1465038) + # Jitspew doesn't compile on VS17 in the zydis disassembler - since we don't use it, deactivate it. + # Trace-logging doesn't compile for now. + CONF_OPTS="--disable-tests + --disable-jemalloc + --disable-js-shell + --without-intl-api + --enable-shared-js" + + if [ -n "$PROFILE" ]; then + CONF_OPTS="$CONF_OPTS --enable-profiling + --enable-perf + --enable-instruments + --enable-jitspew + --with-jitreport-granularity=3" + fi + + if [ "${OS}" = "Windows_NT" ]; then + CONF_OPTS="${CONF_OPTS} --target=i686" + elif [ "${OS}" = "Darwin" ]; then + # Unless we are forcing an architecture, switch between ARM / x86 based on platform. + if [ -z "${ARCH}" ]; then + if [ "$(uname -m)" = "arm64" ]; then + ARCH="aarch64" + else + ARCH="x86_64" + fi + fi + CONF_OPTS="${CONF_OPTS} --target=$ARCH-apple-darwin" + + # Link to custom-built zlib + export PKG_CONFIG_PATH="=${ZLIB_DIR}:${PKG_CONFIG_PATH}" + CONF_OPTS="${CONF_OPTS} --with-system-zlib" + # Specify target versions and SDK + if [ "${MIN_OSX_VERSION}" ] && [ "${MIN_OSX_VERSION-_}" ]; then + CONF_OPTS="${CONF_OPTS} --enable-macos-target=$MIN_OSX_VERSION" + fi + if [ "${SYSROOT}" ] && [ "${SYSROOT-_}" ]; then + CONF_OPTS="${CONF_OPTS} --with-macos-sdk=${SYSROOT}" + fi + fi + + LLVM_OBJDUMP=${LLVM_OBJDUMP:=$(command -v llvm-objdump || command -v objdump)} + + # Quick sanity check to print explicit error messages + # (Don't run this on windows as it would likely fail spuriously) + if [ "${OS}" != "Windows_NT" ]; then + [ -n "$(command -v rustc)" ] || (echo "Error: rustc is not available. Install the rust toolchain (rust + cargo) before proceeding." && exit 1) + [ -n "${LLVM_OBJDUMP}" ] || (echo "Error: LLVM objdump is not available. Install it (likely via LLVM-clang) before proceeding." && exit 1) + fi + + # If Valgrind looks like it's installed, then set up SM to support it + # (else the JITs will interact poorly with it) + if [ -e /usr/include/valgrind/valgrind.h ]; then + CONF_OPTS="${CONF_OPTS} --enable-valgrind" + fi + + # We need to be able to override CHOST in case it is 32bit userland on 64bit kernel + CONF_OPTS="${CONF_OPTS} \ + ${CBUILD:+--build=${CBUILD}} \ + ${CHOST:+--host=${CHOST}} \ + ${CTARGET:+--target=${CTARGET}}" + + echo "SpiderMonkey build options: ${CONF_OPTS}" + + # Build + # Debug (broken on FreeBSD) + if [ "${OS}" != "FreeBSD" ]; then + mkdir -p build-debug + ( + cd build-debug + # llvm-objdump is searched for with the complete name, not simply 'objdump', account for that. + CXXFLAGS="${CXXFLAGS}" ../js/src/configure \ + LLVM_OBJDUMP="${LLVM_OBJDUMP}" \ + ${CONF_OPTS} \ + --enable-debug \ + --disable-optimize \ + --enable-gczeal + ${MAKE} ${MAKE_OPTS} + ) + fi + # Release + mkdir -p build-release + ( + cd build-release + CXXFLAGS="${CXXFLAGS}" ../js/src/configure \ + LLVM_OBJDUMP="${LLVM_OBJDUMP}" \ + ${CONF_OPTS} \ + --enable-optimize + ${MAKE} ${MAKE_OPTS} + ) + ) # install -rm -Rf bin include-unix-debug include-unix-release lib -cp -R spidermonkey-build/bin spidermonkey-build/include-unix-release spidermonkey-build/lib . -if [ "$(uname -s)" != "FreeBSD" ]; then - cp -R spidermonkey-build/include-unix-debug . +rm -Rf bin include-debug include-release lib + +mkdir bin lib + +if [ "${OS}" = "Windows_NT" ]; then + LIB_PREFIX= + LIB_SUFFIX=.dll + STATIC_LIB_SUFFIX=.lib +else + LIB_PREFIX=lib + LIB_SUFFIX=.so + STATIC_LIB_SUFFIX=.a + if [ "${OS}" = "OpenBSD" ]; then + LIB_SUFFIX=.so.1.0 + elif [ "${OS}" = "Darwin" ]; then + LIB_SUFFIX=.a + fi fi +if [ "${OS}" = "Windows_NT" ]; then + # Bug #776126 + # SpiderMonkey uses a tweaked zlib when building, and it wrongly copies its own files to include dirs + # afterwards, so we have to remove them to not have them conflicting with the regular zlib + ( + cd "${FOLDER}"/build-debug/dist/include + rm -f mozzconf.h zconf.h zlib.h + ) + ( + cd "${FOLDER}"/build-release/dist/include + rm -f mozzconf.h zconf.h zlib.h + ) +fi + +# js-config.h is different for debug and release builds, so we need different include directories for both +mkdir include-release +cp -R -L "${FOLDER}"/build-release/dist/include/* include-release/ + +if [ "${OS}" != "FreeBSD" ]; then + mkdir include-debug + cp -R -L "${FOLDER}"/build-debug/dist/include/* include-debug/ +fi + +# These align the ligns below, making it easier to check for mistakes. +DEB="debug" +REL="release" + +# Fetch the jsrust static library. Path is grepped from the build file as it varies by rust toolset. +rust_path=$(grep jsrust <"${FOLDER}/build-release/js/src/build/backend.mk" | cut -d = -f 2 | cut -c2-) +cp -L "${rust_path}" "lib/${LIB_PREFIX}${LIB_NAME}-rust${STATIC_LIB_SUFFIX}" + +if [ "${OS}" = "Darwin" ]; then + # On MacOS, copy the static libraries only. + cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}js_static${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" + cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}js_static${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" +elif [ "${OS}" = "Windows_NT" ]; then + # Windows needs DLLs to binaries/, static stubs to lib/ and debug symbols + cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" "bin/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" + cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" "bin/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" + 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}" + 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}" + # Copy debug symbols as well. + cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}.pdb" "bin/${LIB_PREFIX}${LIB_NAME}-${DEB}.pdb" + cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}.pdb" "bin/${LIB_PREFIX}${LIB_NAME}-${REL}.pdb" + # Copy the debug jsrust library. + rust_path=$(grep jsrust <"${FOLDER}/build-debug/js/src/build/backend.mk" | cut -d = -f 2 | cut -c2-) + cp -L "${rust_path}" "lib/${LIB_PREFIX}${LIB_NAME}-rust-debug${STATIC_LIB_SUFFIX}" +else + # Copy shared libs to lib/, they will also be copied to binaries/system, so the compiler and executable (resp.) can find them. + cp -L "${FOLDER}/build-${REL}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${REL}${LIB_SUFFIX}" + if [ "${OS}" != "FreeBSD" ]; then + cp -L "${FOLDER}/build-${DEB}/js/src/build/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" "lib/${LIB_PREFIX}${LIB_NAME}-${DEB}${LIB_SUFFIX}" + fi +fi + +# cleanup +rm -Rf "$FOLDER" + echo "${LIB_VERSION}" >.already-built diff --git a/libraries/source/spidermonkey/patches/FixClang16Build.diff b/libraries/source/spidermonkey/patches/FixClang16Build.diff new file mode 100644 index 0000000000..c684248a7f --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixClang16Build.diff @@ -0,0 +1,24 @@ +From 8dd2ad66811d2d5c72599bd87a77345c254af23c Mon Sep 17 00:00:00 2001 +From: Ralph Sennhauser +Date: Mon, 15 May 2023 22:02:52 +0200 +Subject: [PATCH 1/1] Use default pass manager for clang + +--- + build/moz.configure/flags.configure | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/build/moz.configure/flags.configure b/build/moz.configure/flags.configure +index cc8ca1e6aada..40f4c7d905ec 100644 +--- a/build/moz.configure/flags.configure ++++ b/build/moz.configure/flags.configure +@@ -36,6 +36,7 @@ option( + ubsan, + ) + def new_pass_manager_flags(enabled, compiler, host, target, pgo, enable_fuzzing, ubsan): ++ return None + if host.os == "OSX": + # Some native Mac builds hang with the new pass manager. Given the + # inability to test in CI, don't take the risk of further breakage. +-- +2.39.3 + diff --git a/libraries/source/spidermonkey/patches/FixFedoraVirtualEnv.diff b/libraries/source/spidermonkey/patches/FixFedoraVirtualEnv.diff new file mode 100644 index 0000000000..5df044bb08 --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixFedoraVirtualEnv.diff @@ -0,0 +1,15 @@ +--- a/third_party/python/virtualenv/virtualenv/discovery/py_info.py ++++ b/third_party/python/virtualenv/virtualenv/discovery/py_info.py +@@ -177,7 +177,11 @@ + ) + if not os.path.exists(path): # some broken packaging don't respect the sysconfig, fallback to distutils path + # the pattern include the distribution name too at the end, remove that via the parent call +- fallback = os.path.join(self.prefix, os.path.dirname(self.distutils_install["headers"])) ++ # A hack for https://github.com/pypa/virtualenv/issues/2208 ++ distutils_path = self.distutils_install["headers"] ++ if distutils_path.startswith(u"local/"): ++ distutils_path = distutils_path[6:] ++ fallback = os.path.join(self.prefix, os.path.dirname(distutils_path)) + if os.path.exists(fallback): + path = fallback + return path diff --git a/libraries/source/spidermonkey/patches/FixFpNormIssue.diff b/libraries/source/spidermonkey/patches/FixFpNormIssue.diff new file mode 100644 index 0000000000..ef4d4d96b6 --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixFpNormIssue.diff @@ -0,0 +1,110 @@ +--- a/modules/fdlibm/src/math_private.h ++++ b/modules/fdlibm/src/math_private.h +@@ -30,8 +30,13 @@ + * Adapted from https://github.com/freebsd/freebsd-src/search?q=__double_t + */ + ++#if defined __FLT_EVAL_METHOD__ && (__FLT_EVAL_METHOD__ == 2) ++typedef long double __double_t; ++#else + typedef double __double_t; ++#endif + typedef __double_t double_t; ++typedef float __float_t; + + /* + * The original fdlibm code used statements like: +@@ -630,6 +634,53 @@ + return ((double)(x + 0x1.8p52) - 0x1.8p52); + } + ++static inline float ++rnintf(__float_t x) ++{ ++ /* ++ * As for rnint(), except we could just call that to handle the ++ * extra precision case, usually without losing efficiency. ++ */ ++ return ((float)(x + 0x1.8p23F) - 0x1.8p23F); ++} ++ ++#ifdef LDBL_MANT_DIG ++/* ++ * The complications for extra precision are smaller for rnintl() since it ++ * can safely assume that the rounding precision has been increased from ++ * its default to FP_PE on x86. We don't exploit that here to get small ++ * optimizations from limiting the rangle to double. We just need it for ++ * the magic number to work with long doubles. ld128 callers should use ++ * rnint() instead of this if possible. ld80 callers should prefer ++ * rnintl() since for amd64 this avoids swapping the register set, while ++ * for i386 it makes no difference (assuming FP_PE), and for other arches ++ * it makes little difference. ++ */ ++ ++static inline long double ++rnintl(long double x) ++{ ++ /* The WRAPPED__CONCAT() macro below is required for non-FreeBSD targets ++ which don't have a multi-level CONCAT macro implementation. On those ++ targets the hexadecimal floating-point values being created don't expand ++ properly resulting in code that cannot be compiled. ++ ++ The extra level provided by this macro should not affect FreeBSD, should ++ this code be used there. ++ ++ See the following for more details: ++ ++ https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC32 ++ https://sources.debian.org/src/glibc/2.32-3/misc/sys/cdefs.h/ ++ https://github.com/freebsd/freebsd-src/blob/main/sys/sys/cdefs.h ++ */ ++ #define WRAPPED__CONCAT(x,y) __CONCAT(x,y) ++ ++ return (x + WRAPPED__CONCAT(0x1.8p, LDBL_MANT_DIG) / 2 - ++ WRAPPED__CONCAT(0x1.8p, LDBL_MANT_DIG) / 2); ++} ++#endif /* LDBL_MANT_DIG */ ++ + /* + * irint() and i64rint() give the same result as casting to their integer + * return type provided their arg is a floating point integer. They can +@@ -646,6 +697,39 @@ + #define irint(x) ((int)(x)) + #endif + ++#define i64rint(x) ((int64_t)(x)) /* only needed for ld128 so not opt. */ ++ ++#if defined(__i386__) && defined(__GNUCLIKE_ASM) ++static __inline int ++irintf(float x) ++{ ++ int n; ++ ++ __asm("fistl %0" : "=m" (n) : "t" (x)); ++ return (n); ++} ++ ++static __inline int ++irintd(double x) ++{ ++ int n; ++ ++ __asm("fistl %0" : "=m" (n) : "t" (x)); ++ return (n); ++} ++#endif ++ ++#if (defined(__amd64__) || defined(__i386__)) && defined(__GNUCLIKE_ASM) ++static __inline int ++irintl(long double x) ++{ ++ int n; ++ ++ __asm("fistl %0" : "=m" (n) : "t" (x)); ++ return (n); ++} ++#endif ++ + #ifdef DEBUG + #if defined(__amd64__) || defined(__i386__) + #define breakpoint() asm("int $3") diff --git a/libraries/source/spidermonkey/patches/FixInstallScheme.diff b/libraries/source/spidermonkey/patches/FixInstallScheme.diff new file mode 100644 index 0000000000..0b2c9568ca --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixInstallScheme.diff @@ -0,0 +1,26 @@ +--- a/python/mozbuild/mozbuild/virutalenv.py ++++ b/python/mozbuild/mozbuild/virtualenv.py +@@ -587,18 +587,11 @@ + """ + +- # Defer "distutils" import until this function is called so that +- # "mach bootstrap" doesn't fail due to Linux distro python-distutils +- # package not being installed. +- # By the time this function is called, "distutils" must be installed +- # because it's needed by the "virtualenv" package. +- from distutils import dist ++ import sysconfig + +- distribution = dist.Distribution({"script_args": "--no-user-cfg"}) +- installer = distribution.get_command_obj("install") +- installer.prefix = os.path.normpath(self.virtualenv_root) +- installer.finalize_options() +- + # Path to virtualenv's "site-packages" directory +- site_packages = installer.install_purelib ++ site_packages = sysconfig.get_path( ++ 'purelib', ++ scheme='posix_prefix', ++ vars={ 'base': os.path.normpath(self.virtualenv_root) }) + + pip_dist_info = next( diff --git a/libraries/source/spidermonkey/patches/FixLibNames.diff b/libraries/source/spidermonkey/patches/FixLibNames.diff new file mode 100644 index 0000000000..27a1ee41f6 --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixLibNames.diff @@ -0,0 +1,16 @@ +--- a/js/src/old-configure ++++ b/js/src/old-configure +@@ -7035,10 +7035,10 @@ + + + +-if test -n "$JS_STANDALONE"; then +-JS_LIBRARY_NAME="mozjs-$MOZILLA_SYMBOLVERSION" ++if test -n "$MOZ_DEBUG"; then ++JS_LIBRARY_NAME="mozjs$MOZILLA_SYMBOLVERSION-debug" + else +-JS_LIBRARY_NAME="mozjs" ++JS_LIBRARY_NAME="mozjs$MOZILLA_SYMBOLVERSION-release" + fi + JS_CONFIG_LIBS="$NSPR_LIBS $LIBS" + if test -n "$GNU_CC"; then diff --git a/libraries/source/spidermonkey/patches/FixRustLinkage.diff b/libraries/source/spidermonkey/patches/FixRustLinkage.diff new file mode 100644 index 0000000000..5f767a131c --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixRustLinkage.diff @@ -0,0 +1,16 @@ +--- a/js/src/moz.build ++++ b/js/src/moz.build +@@ -50,9 +50,12 @@ + if CONFIG["ENABLE_WASM_CRANELIFT"]: + CONFIGURE_SUBST_FILES += ["rust/extra-bindgen-flags"] + ++DIRS += [ ++ "rust" ++] ++ + if not CONFIG["JS_DISABLE_SHELL"]: + DIRS += [ +- "rust", + "shell", + ] + diff --git a/libraries/source/spidermonkey/patches/FixUnicodePython311.diff b/libraries/source/spidermonkey/patches/FixUnicodePython311.diff new file mode 100644 index 0000000000..35f3bf572f --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixUnicodePython311.diff @@ -0,0 +1,130 @@ +From c6c6300e8698ba1d3db96591b9c150c49b8e6d76 Mon Sep 17 00:00:00 2001 +From: Ralph Sennhauser +Date: Fri, 13 Jan 2023 13:13:47 +0100 +Subject: [PATCH] Fix use of removed 'U' support in python 3.11 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Form https://docs.python.org/3.11/whatsnew/3.11.html: + +open(), io.open(), codecs.open() and fileinput.FileInput no longer +accept 'U' (“universal newline”) in the file mode. In Python 3, +“universal newline” mode is used by default whenever a file is opened in +text mode, and the 'U' flag has been deprecated since Python 3.3. The +newline parameter to these functions controls how universal newlines +work. (Contributed by Victor Stinner in bpo-37330.) + +https://github.com/python/cpython/issues/81511 +--- + python/mozbuild/mozbuild/action/process_define_files.py | 2 +- + python/mozbuild/mozbuild/backend/base.py | 2 +- + python/mozbuild/mozbuild/preprocessor.py | 6 +++--- + python/mozbuild/mozbuild/util.py | 4 ++-- + python/mozbuild/mozpack/files.py | 4 ++-- + 5 files changed, 9 insertions(+), 9 deletions(-) + +diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py +index f1d401ac2600..aca59d0f0517 100644 +--- a/python/mozbuild/mozbuild/action/process_define_files.py ++++ b/python/mozbuild/mozbuild/action/process_define_files.py +@@ -36,7 +36,7 @@ def process_define_file(output, input): + ) and not config.substs.get("JS_STANDALONE"): + config = PartialConfigEnvironment(mozpath.join(topobjdir, "js", "src")) + +- with open(path, "rU") as input: ++ with open(path, "r") as input: + r = re.compile( + "^\s*#\s*(?P[a-z]+)(?:\s+(?P\S+)(?:\s+(?P\S+))?)?", re.U + ) +diff --git a/python/mozbuild/mozbuild/backend/base.py b/python/mozbuild/mozbuild/backend/base.py +index 7bc1986d863b..b64a70946863 100644 +--- a/python/mozbuild/mozbuild/backend/base.py ++++ b/python/mozbuild/mozbuild/backend/base.py +@@ -272,7 +272,7 @@ class BuildBackend(LoggingMixin): + return status + + @contextmanager +- def _write_file(self, path=None, fh=None, readmode="rU"): ++ def _write_file(self, path=None, fh=None, readmode="r"): + """Context manager to write a file. + + This is a glorified wrapper around FileAvoidWrite with integration to +diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py +index f7820b9c9147..857f1a6c9bfd 100644 +--- a/python/mozbuild/mozbuild/preprocessor.py ++++ b/python/mozbuild/mozbuild/preprocessor.py +@@ -531,7 +531,7 @@ class Preprocessor: + + if args: + for f in args: +- with io.open(f, "rU", encoding="utf-8") as input: ++ with io.open(f, "r", encoding="utf-8") as input: + self.processFile(input=input, output=out) + if depfile: + mk = Makefile() +@@ -860,7 +860,7 @@ class Preprocessor: + args = self.applyFilters(args) + if not os.path.isabs(args): + args = os.path.join(self.curdir, args) +- args = io.open(args, "rU", encoding="utf-8") ++ args = io.open(args, "r", encoding="utf-8") + except Preprocessor.Error: + raise + except Exception: +@@ -914,7 +914,7 @@ class Preprocessor: + def preprocess(includes=[sys.stdin], defines={}, output=sys.stdout, marker="#"): + pp = Preprocessor(defines=defines, marker=marker) + for f in includes: +- with io.open(f, "rU", encoding="utf-8") as input: ++ with io.open(f, "r", encoding="utf-8") as input: + pp.processFile(input=input, output=output) + return pp.includes + +diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py +index 071daecc397b..b59aabbea61b 100644 +--- a/python/mozbuild/mozbuild/util.py ++++ b/python/mozbuild/mozbuild/util.py +@@ -225,7 +225,7 @@ class FileAvoidWrite(BytesIO): + still occur, as well as diff capture if requested. + """ + +- def __init__(self, filename, capture_diff=False, dry_run=False, readmode="rU"): ++ def __init__(self, filename, capture_diff=False, dry_run=False, readmode="r"): + BytesIO.__init__(self) + self.name = filename + assert type(capture_diff) == bool +@@ -1447,7 +1447,7 @@ def patch_main(): + + def my_get_command_line(): + with open( +- os.path.join(os.path.dirname(__file__), "fork_interpose.py"), "rU" ++ os.path.join(os.path.dirname(__file__), "fork_interpose.py"), "r" + ) as fork_file: + fork_code = fork_file.read() + # Add our relevant globals. +diff --git a/python/mozbuild/mozpack/files.py b/python/mozbuild/mozpack/files.py +index 8150e72d6fa2..001c497b2796 100644 +--- a/python/mozbuild/mozpack/files.py ++++ b/python/mozbuild/mozpack/files.py +@@ -574,7 +574,7 @@ class PreprocessedFile(BaseFile): + pp = Preprocessor(defines=self.defines, marker=self.marker) + pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings) + +- with _open(self.path, "rU") as input: ++ with _open(self.path, "r") as input: + with _open(os.devnull, "w") as output: + pp.processFile(input=input, output=output) + +@@ -631,7 +631,7 @@ class PreprocessedFile(BaseFile): + pp = Preprocessor(defines=self.defines, marker=self.marker) + pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings) + +- with _open(self.path, "rU") as input: ++ with _open(self.path, "r") as input: + pp.processFile(input=input, output=dest, depfile=deps_out) + + dest.close() +-- +2.38.2 + diff --git a/libraries/source/spidermonkey/patches/FixVirtualEnv.diff b/libraries/source/spidermonkey/patches/FixVirtualEnv.diff new file mode 100644 index 0000000000..2a638c9f9e --- /dev/null +++ b/libraries/source/spidermonkey/patches/FixVirtualEnv.diff @@ -0,0 +1,16 @@ +--- a/python/mozbuild/mozbuild/virtualenv.py ++++ b/python/mozbuild/mozbuild/virtualenv.py +@@ -246,11 +246,12 @@ + if os.path.exists(self.virtualenv_root): + shutil.rmtree(self.virtualenv_root) + + args = [ + python, +- self.virtualenv_script_path, ++ "-m", ++ "virtualenv", + # Without this, virtualenv.py may attempt to contact the outside + # world and search for or download a newer version of pip, + # setuptools, or wheel. This is bad for security, reproducibility, + # and speed. + "--no-download", diff --git a/libraries/source/spidermonkey/patches/patch.sh b/libraries/source/spidermonkey/patches/patch.sh new file mode 100755 index 0000000000..de93c1d1e2 --- /dev/null +++ b/libraries/source/spidermonkey/patches/patch.sh @@ -0,0 +1,55 @@ +#!/bin/sh +set -e + +OS="${OS:=$(uname -s)}" + +# This script gets called from inside the extracted SM tarball. +PATCHES="../patches" + +# The rust code is only linked if the JS Shell is enabled, +# which fails now that rust is required in all cases. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1588340 +patch -p1 <"${PATCHES}"/FixRustLinkage.diff + +# Differentiate debug/release library names. +patch -p1 <"${PATCHES}"/FixLibNames.diff + +# There is an issue on 32-bit linux builds sometimes. +# NB: the patch here is Comment 21 modified by Comment 25 +# but that seems to imperfectly fix the issue with GCC. +# It also won't compile on windows - in doubt, apply only where relevant. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1729459 +if [ "$(uname -m)" = "i686" ] && [ "${OS}" != "Windows_NT" ]; then + patch -p1 <"${PATCHES}"/FixFpNormIssue.diff +fi + +if [ "$OS" = "Darwin" ]; then + # The bundled virtualenv version is not working on MacOS + # with recent homebrew and needs to be upgraded. + # Install it locally to not pollute anything. + pip3 install --upgrade -t virtualenv virtualenv + export PYTHONPATH="$(pwd)/virtualenv:$PYTHONPATH" + patch -p1 <"${PATCHES}"/FixVirtualEnv.diff +fi + +if [ "$OS" = "Linux" ]; then + # Use sysconfig instead of distutils with the bundled virtualenv + # This fixes an issue with install schemes on recent Debian and Fedora + # Furthermore, distutils is going to be deprecated and is replaced + # by sysconfig in ESR102 + patch -p1 <"${PATCHES}"/FixInstallScheme.diff + + # Extend the previous fix with a portion of the following commit + # https://phabricator.services.mozilla.com/D130410 + # This will prevent bug 1739486 from happening on Fedora + patch -p1 <"${PATCHES}"/FixFedoraVirtualEnv.diff +fi + +# Python >= 3.11 support +PYTHON_MINOR_VERSION="$(python3 -c 'import sys; print(sys.version_info.minor)')" +if [ "$PYTHON_MINOR_VERSION" -ge 11 ]; then + patch -p1 <"${PATCHES}"/FixUnicodePython311.diff +fi + +# fixed in SM102 +patch -p1 <"${PATCHES}"/FixClang16Build.diff