From 72abaf32042ce25aa0a5fad5ee7fc04d95d12bfd Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 25 Nov 2022 21:37:01 +0800 Subject: [PATCH 01/16] Added Automatic mozmake Installation --- mozjs/Cargo.toml | 2 + mozjs/build.rs | 56 ++++++++++- mozjs/makefile.cargo | 232 +++++++++++++++++++++---------------------- 3 files changed, 173 insertions(+), 117 deletions(-) diff --git a/mozjs/Cargo.toml b/mozjs/Cargo.toml index 48b0222eac5..73563c7fa81 100644 --- a/mozjs/Cargo.toml +++ b/mozjs/Cargo.toml @@ -36,4 +36,6 @@ libz-sys = "1.0" [build-dependencies] bindgen = { version = "0.62", default-features = false, features = ["runtime", "which-rustfmt"] } cc = "1.0" +tar = "0.4.38" walkdir = "2" +ruzstd = "0.3.0" diff --git a/mozjs/build.rs b/mozjs/build.rs index 38128dd582c..f0c26b9f98c 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -9,6 +9,7 @@ extern crate walkdir; use std::env; use std::ffi::{OsStr, OsString}; use std::fs; +use std::io::Read; use std::path::{Path, PathBuf}; use std::process::Command; use std::str; @@ -94,6 +95,43 @@ fn find_make() -> OsString { } } +fn install_mozmake(mozbuild_dir: &OsStr) { + let mozbuild_dir = Path::new(mozbuild_dir); + let mozmake_tar_zst_path = mozbuild_dir.join("mozmake.tar.zst"); + + let mut curl = Command::new("curl"); + let result = curl.arg("-SL") + .arg("https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-1.toolchains.v3.win64-mozmake.latest/artifacts/public/build/mozmake.tar.zst") + .args(&["-o", &mozmake_tar_zst_path.display().to_string()]) + .status() + .expect("Failed to install mozmake."); + assert!(result.success()); + + let mozmake_tar_zst = + fs::File::open(&mozmake_tar_zst_path).expect("Failed to open mozmake.tar.zst"); + let mut mozmake_compressed = + ruzstd::StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst"); + let mut mozmake_uncompressed = Vec::new(); + + mozmake_compressed + .read_to_end(&mut mozmake_uncompressed) + .expect("Failed to decode mozmake.tar.zst"); + let mut archive = tar::Archive::new(&*mozmake_uncompressed); + archive + .unpack(mozbuild_dir.join("bin")) + .expect("Failed to unpack mozmake.tar"); + + assert!(mozbuild_dir + .join("bin") + .join("mozmake") + .join("mozmake.exe") + .exists()); + fs::remove_file(&mozmake_tar_zst_path).expect("Failed to remove mozmake.tar.zst"); + + let mozmake_lock = mozbuild_dir.join("MOZMAKE_LOCK"); + fs::write(mozmake_lock, "").expect("Failed to write to mozmake lock."); +} + fn cc_flags() -> Vec<&'static str> { let mut result = vec!["-DRUST_BINDGEN", "-DSTATIC_JS_API"]; @@ -143,9 +181,25 @@ fn build_jsapi(build_dir: &Path) { paths.extend(env::split_paths(&path)); let new_path = env::join_paths(paths).unwrap(); env::set_var("PATH", &new_path); - make = OsStr::new("mozmake").to_os_string(); + + let mozbuild_dir = env::var_os("MOZILLABUILD").unwrap_or("C:\\mozilla-build".into()); + + let mozmake_lock = Path::new(&mozbuild_dir).join("MOZMAKE_LOCK"); + if !mozmake_lock.exists() { + install_mozmake(&mozbuild_dir); + } + + make = OsString::from( + Path::new(&mozbuild_dir) + .join("bin") + .join("mozmake") + .join("mozmake.exe") + .as_os_str(), + ); } + eprintln!("{:#?}", make); + let mut cmd = Command::new(make); let encoding_c_mem_include_dir = env::var("DEP_ENCODING_C_MEM_INCLUDE_DIR").unwrap(); diff --git a/mozjs/makefile.cargo b/mozjs/makefile.cargo index da896831470..9e7ece459d5 100644 --- a/mozjs/makefile.cargo +++ b/mozjs/makefile.cargo @@ -4,16 +4,16 @@ SHELL := bash # Default flags CONFIGURE_FLAGS := \ - --disable-jemalloc \ - --disable-js-shell \ - --disable-tests \ - --disable-export-js \ - --disable-shared-js \ - --build-backends=RecursiveMake \ + --disable-jemalloc \ + --disable-js-shell \ + --disable-tests \ + --disable-export-js \ + --disable-shared-js \ + --build-backends=RecursiveMake \ --enable-js-streams ifneq (,$(MACOS_SDK_PATH)) - CONFIGURE_FLAGS += --with-macos-sdk=$(MACOS_SDK_PATH) + CONFIGURE_FLAGS += --with-macos-sdk=$(MACOS_SDK_PATH) endif ifneq (,$(CARGO_FEATURE_JITSPEW)) @@ -21,85 +21,85 @@ ifneq (,$(CARGO_FEATURE_JITSPEW)) endif ifeq (windows,$(findstring windows,$(TARGET))) - WINDOWS := 1 - # Override any attempt to use the debug CRT when building with debug. - CFLAGS += -MD - CXXFLAGS += -MD - ifneq (,$(CARGO_FEATURE_UWP)) - CONFIGURE_FLAGS += --enable-uwp --without-intl-api --disable-vtune - CFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP - CXXFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP - endif + WINDOWS := 1 + # Override any attempt to use the debug CRT when building with debug. + CFLAGS += -MD + CXXFLAGS += -MD + ifneq (,$(CARGO_FEATURE_UWP)) + CONFIGURE_FLAGS += --enable-uwp --without-intl-api --disable-vtune + CFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP + CXXFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP + endif else - WINDOWS := + WINDOWS := endif ifneq ($(HOST),$(TARGET)) - ifeq (armv7-linux-androideabi,$(TARGET)) - # Reset TARGET variable because armv7 target name used by Rust is not - # the same as the target name needed for the CXX toolchain. - TARGET = arm-linux-androideabi - CONFIGURE_FLAGS += \ - --with-arch=armv7-a \ - --with-fpu=neon \ - $(NULL) - endif - - ifeq (aarch64-unknown-linux-gnu,$(TARGET)) - # Reset TARGET variable because aarch64 target name used by Rust is not - # the same as the target name needed for the CXX toolchain. - TARGET = aarch64-linux-gnu - CONFIGURE_FLAGS += \ - --with-arch=armv8-a \ - $(NULL) - endif - - ifeq (android,$(findstring android,$(TARGET))) - ifneq (,$(STLPORT_CPPFLAGS)) - CONFIGURE_FLAGS += STLPORT_CPPFLAGS="$(STLPORT_CPPFLAGS)" - endif - ifneq (,$(ANDROID_NDK)) - CONFIGURE_FLAGS += --with-android-ndk=$(ANDROID_NDK) - endif - ifneq (,$(ANDROID_NDK_VERSION)) - CONFIGURE_FLAGS += --with-android-ndk-version=$(ANDROID_NDK_VERSION) - endif - ifneq (,$(ANDROID_VERSION)) - CONFIGURE_FLAGS += --with-android-version=$(ANDROID_VERSION) - endif - ifneq (,$(ANDROID_PLATFORM_DIR)) - CONFIGURE_FLAGS += --with-android-platform=$(ANDROID_PLATFORM_DIR) - endif - ifneq (,$(ANDROID_TOOLCHAIN_DIR)) - CONFIGURE_FLAGS += --with-android-toolchain=$(ANDROID_TOOLCHAIN_DIR) - endif - ifneq (,$(ANDROID_CLANG)) - CONFIGURE_FLAGS += --with-android-clang=$(ANDROID_CLANG) - endif - endif + ifeq (armv7-linux-androideabi,$(TARGET)) + # Reset TARGET variable because armv7 target name used by Rust is not + # the same as the target name needed for the CXX toolchain. + TARGET = arm-linux-androideabi + CONFIGURE_FLAGS += \ + --with-arch=armv7-a \ + --with-fpu=neon \ + $(NULL) + endif + + ifeq (aarch64-unknown-linux-gnu,$(TARGET)) + # Reset TARGET variable because aarch64 target name used by Rust is not + # the same as the target name needed for the CXX toolchain. + TARGET = aarch64-linux-gnu + CONFIGURE_FLAGS += \ + --with-arch=armv8-a \ + $(NULL) + endif + + ifeq (android,$(findstring android,$(TARGET))) + ifneq (,$(STLPORT_CPPFLAGS)) + CONFIGURE_FLAGS += STLPORT_CPPFLAGS="$(STLPORT_CPPFLAGS)" + endif + ifneq (,$(ANDROID_NDK)) + CONFIGURE_FLAGS += --with-android-ndk=$(ANDROID_NDK) + endif + ifneq (,$(ANDROID_NDK_VERSION)) + CONFIGURE_FLAGS += --with-android-ndk-version=$(ANDROID_NDK_VERSION) + endif + ifneq (,$(ANDROID_VERSION)) + CONFIGURE_FLAGS += --with-android-version=$(ANDROID_VERSION) + endif + ifneq (,$(ANDROID_PLATFORM_DIR)) + CONFIGURE_FLAGS += --with-android-platform=$(ANDROID_PLATFORM_DIR) + endif + ifneq (,$(ANDROID_TOOLCHAIN_DIR)) + CONFIGURE_FLAGS += --with-android-toolchain=$(ANDROID_TOOLCHAIN_DIR) + endif + ifneq (,$(ANDROID_CLANG)) + CONFIGURE_FLAGS += --with-android-clang=$(ANDROID_CLANG) + endif + endif ifeq ($(WINDOWS),) - CC ?= $(TARGET)-gcc - CPP ?= $(TARGET)-gcc -E - CXX ?= $(TARGET)-g++ - AR ?= $(TARGET)-ar - CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold + CC ?= $(TARGET)-gcc + CPP ?= $(TARGET)-gcc -E + CXX ?= $(TARGET)-g++ + AR ?= $(TARGET)-ar + CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold endif else ifeq (,$(WINDOWS)) - ifeq (freebsd,$(findstring freebsd,$(TARGET))) - # Does not symlink clang as "gcc" like macOS does - CC ?= clang - CPP ?= clang -E - CXX ?= clang++ - else - CC ?= gcc - CPP ?= gcc -E - CXX ?= g++ - endif + ifeq (freebsd,$(findstring freebsd,$(TARGET))) + # Does not symlink clang as "gcc" like macOS does + CC ?= clang + CPP ?= clang -E + CXX ?= clang++ + else + CC ?= gcc + CPP ?= gcc -E + CXX ?= g++ + endif AR ?= ar # check if python2 is a valid Python executable, otherwise fall back to python @@ -114,69 +114,69 @@ endif endif ifneq (,$(CARGO_FEATURE_DEBUGMOZJS)) - CONFIGURE_FLAGS += --enable-debug --disable-optimize --enable-gczeal + CONFIGURE_FLAGS += --enable-debug --disable-optimize --enable-gczeal endif ifneq (,$(CARGO_FEATURE_PROFILEMOZJS)) - CONFIGURE_FLAGS += --enable-profiling + CONFIGURE_FLAGS += --enable-profiling endif ifneq (,$(CCACHE)) - CONFIGURE_FLAGS += --with-ccache=$(CCACHE) + CONFIGURE_FLAGS += --with-ccache=$(CCACHE) endif ifneq ($(WINDOWS),) - # Visual Studio build - NEED_WIN_PYTHON := 1 + # Visual Studio build + NEED_WIN_PYTHON := 1 - # There's no cygpath in mozilla-build, and we're expecting to - # be building with MOZ_BUILD_TOOLS, so do our best - OUT_DIR:=$(subst \,/,$(OUT_DIR)) + # There's no cygpath in mozilla-build, and we're expecting to + # be building with MOZ_BUILD_TOOLS, so do our best + OUT_DIR:=$(subst \,/,$(OUT_DIR)) ifeq ($(findstring x86_64,$(TARGET)),x86_64) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32 + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32 else ifeq ($(findstring i686,$(TARGET)),i686) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=x86_64-pc-mingw32 + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=x86_64-pc-mingw32 else ifeq ($(findstring aarch64,$(TARGET)),aarch64) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=aarch64-windows-mingw32 --host=x86_64-pc-mingw32 + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=aarch64-windows-mingw32 --host=x86_64-pc-mingw32 endif - MOZ_TOOLS=/ + MOZ_TOOLS=/ else ifeq ($(MSYSTEM),MINGW64) - # MSYS2/MINGW64 build - NEED_WIN_PYTHON := 1 - - # msys2 sets CC=cc as default. however, there is no `cc.exe`. - # overwrite it here. - ifeq ($(CC),cc) - CC = gcc - CPP = gcc -E - endif - - # cargo uses Windows native path. msys2 make unfortunately doesn't understand it. - OUT_DIR:=$(shell cygpath "$(OUT_DIR)") - - # Fake out the SM build with a dummy dir here; just needs $(MOZ_TOOLS)/bin - # to exist - MOZ_TOOLS=/ + # MSYS2/MINGW64 build + NEED_WIN_PYTHON := 1 + + # msys2 sets CC=cc as default. however, there is no `cc.exe`. + # overwrite it here. + ifeq ($(CC),cc) + CC = gcc + CPP = gcc -E + endif + + # cargo uses Windows native path. msys2 make unfortunately doesn't understand it. + OUT_DIR:=$(shell cygpath "$(OUT_DIR)") + + # Fake out the SM build with a dummy dir here; just needs $(MOZ_TOOLS)/bin + # to exist + MOZ_TOOLS=/ endif # If we need to do extra work to find an appropriate python on # Windows, do it here -ifeq ($(NEED_WIN_PYTHON),1) - ifneq (,$(NATIVE_WIN32_PYTHON)) - PYTHON := $(NATIVE_WIN32_PYTHON) - else ifneq (,$(wildcard c:/python27/python.exe)) - PYTHON := c:/python27/python.exe - else - $(message You must either have the Native Win32 python installed in C:/python27, or set NATIVE_WIN32_PYTHON to point to the appropriate python.exe.) - $(message Download the Python installer from https://www.python.org/downloads/release/python-2710/) - $(error Native Win32 Python not found) - endif -endif +# ifeq ($(NEED_WIN_PYTHON),1) +# ifneq (,$(NATIVE_WIN32_PYTHON)) +# PYTHON := $(NATIVE_WIN32_PYTHON) +# else ifneq (,$(wildcard c:/python27/python.exe)) +# PYTHON := c:/python27/python.exe +# else +# $(message You must either have the Native Win32 python installed in C:/python27, or set NATIVE_WIN32_PYTHON to point to the appropriate python.exe.) +# $(message Download the Python installer from https://www.python.org/downloads/release/python-2710/) +# $(error Native Win32 Python not found) +# endif +# endif .PHONY : all maybe-configure From fdef3fbb1ccb3c37c73124e804d8a3feb0e378f6 Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 25 Nov 2022 21:41:53 +0800 Subject: [PATCH 02/16] Updated Mozilla Build in CI --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ffab016f98f..900ffbb36b4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -75,7 +75,7 @@ jobs: - uses: actions/checkout@v2 - name: Install deps run: | - Start-BitsTransfer -Source https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe -Destination ./MozillaBuildSetup.exe + Start-BitsTransfer -Source https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-4.0.2.exe -Destination ./MozillaBuildSetup.exe .\MozillaBuildSetup.exe /S | Out-Null iwr -useb get.scoop.sh -outfile 'install.ps1' .\install.ps1 -RunAsAdmin From cf99255cb8638fb9809c016ba858852cc51addbf Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 25 Nov 2022 23:01:26 +0800 Subject: [PATCH 03/16] Updated Build Environment in CI --- .github/workflows/rust.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 900ffbb36b4..4fd938b6f45 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -86,12 +86,11 @@ jobs: if: contains(matrix.target, 'uwp') shell: cmd env: - MOZTOOLS_PATH: 'C:\mozilla-build\msys\bin;C:\mozilla-build\bin' + MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" - NATIVE_WIN32_PYTHON: "C:\\mozilla-build\\python2\\python.exe" PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" run: | @@ -103,12 +102,11 @@ jobs: if: contains(matrix.target, 'uwp') != true shell: cmd env: - MOZTOOLS_PATH: 'C:\mozilla-build\msys\bin;C:\mozilla-build\bin' + MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" - NATIVE_WIN32_PYTHON: "C:\\mozilla-build\\python2\\python.exe" PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" run: | From 9632e9c0633d2d8c8e88797c186b90d67c4c9e90 Mon Sep 17 00:00:00 2001 From: Redfire Date: Tue, 29 Nov 2022 22:12:07 +0800 Subject: [PATCH 04/16] Started Mozilla Build Shell in CI Added mozmake to PATH --- .github/workflows/rust.yml | 4 ++++ mozjs/build.rs | 21 +++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4fd938b6f45..46c1e0163c4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -86,6 +86,7 @@ jobs: if: contains(matrix.target, 'uwp') shell: cmd env: + MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" @@ -97,11 +98,13 @@ jobs: rustup install nightly-2022-11-20 rustup default nightly rustup component add rust-src + $env:MOZILLA_BUILD\start-shell.bat -full-path -here cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }} - name: Build Windows if: contains(matrix.target, 'uwp') != true shell: cmd env: + MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" @@ -110,6 +113,7 @@ jobs: PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" run: | + $env:MOZILLA_BUILD\start-shell.bat -full-path -here cargo test --verbose ${{ matrix.features }} --lib Integrity: runs-on: ubuntu-latest diff --git a/mozjs/build.rs b/mozjs/build.rs index f0c26b9f98c..da813415aa5 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -95,7 +95,7 @@ fn find_make() -> OsString { } } -fn install_mozmake(mozbuild_dir: &OsStr) { +fn install_mozmake(mozbuild_dir: &Path) { let mozbuild_dir = Path::new(mozbuild_dir); let mozmake_tar_zst_path = mozbuild_dir.join("mozmake.tar.zst"); @@ -175,31 +175,24 @@ fn build_jsapi(build_dir: &Path) { // Put MOZTOOLS_PATH at the beginning of PATH if specified if let Some(moztools) = env::var_os("MOZTOOLS_PATH") { + let mozbuild_dir = env::var_os("MOZILLA_BUILD").unwrap_or("C:\\mozilla-build".into()); + let mozbuild_dir = Path::new(&mozbuild_dir); + let path = env::var_os("PATH").unwrap(); let mut paths = Vec::new(); paths.extend(env::split_paths(&moztools)); paths.extend(env::split_paths(&path)); + paths.push(mozbuild_dir.join("bin").join("mozmake").into()); let new_path = env::join_paths(paths).unwrap(); env::set_var("PATH", &new_path); - let mozbuild_dir = env::var_os("MOZILLABUILD").unwrap_or("C:\\mozilla-build".into()); - - let mozmake_lock = Path::new(&mozbuild_dir).join("MOZMAKE_LOCK"); - if !mozmake_lock.exists() { + if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { install_mozmake(&mozbuild_dir); } - make = OsString::from( - Path::new(&mozbuild_dir) - .join("bin") - .join("mozmake") - .join("mozmake.exe") - .as_os_str(), - ); + make = "mozmake".into(); } - eprintln!("{:#?}", make); - let mut cmd = Command::new(make); let encoding_c_mem_include_dir = env::var("DEP_ENCODING_C_MEM_INCLUDE_DIR").unwrap(); From e864bd78e58d62d0b3b4d8d1594e2a38599b8c60 Mon Sep 17 00:00:00 2001 From: Redfire Date: Tue, 29 Nov 2022 22:27:14 +0800 Subject: [PATCH 05/16] Fixed Start Shell Script Path --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 46c1e0163c4..a72191cc8ca 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -98,7 +98,7 @@ jobs: rustup install nightly-2022-11-20 rustup default nightly rustup component add rust-src - $env:MOZILLA_BUILD\start-shell.bat -full-path -here + C:\mozilla-build\start-shell.bat -full-path -here cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }} - name: Build Windows if: contains(matrix.target, 'uwp') != true @@ -113,7 +113,7 @@ jobs: PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" run: | - $env:MOZILLA_BUILD\start-shell.bat -full-path -here + C:\mozilla-build\start-shell.bat -full-path -here cargo test --verbose ${{ matrix.features }} --lib Integrity: runs-on: ubuntu-latest From 7b33932dd0e17aa8c7573854dd93b947597f3f3e Mon Sep 17 00:00:00 2001 From: Redfire Date: Tue, 29 Nov 2022 22:37:25 +0800 Subject: [PATCH 06/16] Moved Start Shell to Shell Parameter on CI Step --- .github/workflows/rust.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a72191cc8ca..7a08c7547f0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -84,7 +84,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - name: Build uwp if: contains(matrix.target, 'uwp') - shell: cmd + shell: C:\mozilla-build\start-shell.bat -full-path -here {0} env: MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' @@ -98,11 +98,10 @@ jobs: rustup install nightly-2022-11-20 rustup default nightly rustup component add rust-src - C:\mozilla-build\start-shell.bat -full-path -here cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }} - name: Build Windows if: contains(matrix.target, 'uwp') != true - shell: cmd + shell: C:\mozilla-build\start-shell.bat -full-path -here {0} env: MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' @@ -113,7 +112,6 @@ jobs: PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" run: | - C:\mozilla-build\start-shell.bat -full-path -here cargo test --verbose ${{ matrix.features }} --lib Integrity: runs-on: ubuntu-latest From d486e061cce9bf77910ed3dc7f34ca9e547e647d Mon Sep 17 00:00:00 2001 From: Redfire Date: Tue, 29 Nov 2022 23:19:39 +0800 Subject: [PATCH 07/16] Removed AUTOCONF Environment Variable --- .github/workflows/rust.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7a08c7547f0..c6c9cc3800b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -88,7 +88,6 @@ jobs: env: MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' - AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" @@ -105,7 +104,6 @@ jobs: env: MOZILLA_BUILD: 'C:\mozilla-build' MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' - AUTOCONF: "C:/mozilla-build/msys/local/bin/autoconf-2.13" LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" From 396475e6fa2d03083527f47250d2cc76ad7727b6 Mon Sep 17 00:00:00 2001 From: Redfire Date: Mon, 5 Dec 2022 02:56:21 +0800 Subject: [PATCH 08/16] Added Temporary Fix for MozillaBuild in Windows CI --- .github/workflows/rust.yml | 5 +++++ start-shell.bat | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 start-shell.bat diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c6c9cc3800b..7fe40442a5f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -81,6 +81,11 @@ jobs: .\install.ps1 -RunAsAdmin scoop install llvm@14.0.6 --global echo "C:\ProgramData\scoop\shims;C:\Users\runneradmin\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # TODO: Remove this step and start-shell.bat when the MozillaBuild is updated + - name: Replace MozillaBuild shell + run: | + Remove-Item -Path C:\mozilla-build\start-shell.bat + Move-Item -Path start-shell.bat -Destination C:\mozilla-build\ - uses: dtolnay/rust-toolchain@stable - name: Build uwp if: contains(matrix.target, 'uwp') diff --git a/start-shell.bat b/start-shell.bat new file mode 100644 index 00000000000..200753a5a59 --- /dev/null +++ b/start-shell.bat @@ -0,0 +1,34 @@ +@ECHO OFF + +SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION + +REM Reset some env vars. +SET CYGWIN= +SET INCLUDE= +SET LIB= +SET GITDIR= +SET MOZILLABUILD=%~dp0 + +REM mintty is available as an alternate terminal, but is not enabled by default due +REM to spurious newlines being added to copied text - see bug 1751500. +IF NOT DEFINED USE_MINTTY ( + SET USE_MINTTY= +) + +FOR /F "tokens=* USEBACKQ" %%F IN (`where ssh 2^>NUL`) DO ( + IF NOT DEFINED EXTERNAL_TO_MOZILLABUILD_SSH_DIR ( + SET "EXTERNAL_TO_MOZILLABUILD_SSH_DIR='%%~dpF'" + ) +) + +REM Start shell. +IF "%USE_MINTTY%" == "1" ( + REM Opt into "ConPTY" support, which enables usage of win32 console binaries when + REM running from mintty + SET MSYS=enable_pcon + %MOZILLABUILD%msys2\msys2_shell.cmd -full-path %* +) ELSE ( + %MOZILLABUILD%msys2\msys2_shell.cmd -no-start -defterm -full-path %* +) + +EXIT /B \ No newline at end of file From 418e8e43d52ec2c8b215a7b0958afe0beda02bfe Mon Sep 17 00:00:00 2001 From: Redfire Date: Mon, 5 Dec 2022 03:16:08 +0800 Subject: [PATCH 09/16] Automatically Start MozillaBuild Shell --- .github/workflows/rust.yml | 12 ++---- mozjs/build.rs | 82 +++++++++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7fe40442a5f..abece7e2fd1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -89,15 +89,13 @@ jobs: - uses: dtolnay/rust-toolchain@stable - name: Build uwp if: contains(matrix.target, 'uwp') - shell: C:\mozilla-build\start-shell.bat -full-path -here {0} env: MOZILLA_BUILD: 'C:\mozilla-build' - MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" - PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" - LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" + PYTHON3: 'C:\mozilla-build\python3\python3.exe' + LIBCLANG_PATH: "C:\ProgramData\scoop\apps\llvm\current\lib" run: | rustup install nightly-2022-11-20 rustup default nightly @@ -105,15 +103,13 @@ jobs: cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }} - name: Build Windows if: contains(matrix.target, 'uwp') != true - shell: C:\mozilla-build\start-shell.bat -full-path -here {0} env: MOZILLA_BUILD: 'C:\mozilla-build' - MOZTOOLS_PATH: 'C:\mozilla-build\msys2\bin;C:\mozilla-build\bin' LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" - PYTHON3: "C:\\mozilla-build\\python3\\python3.exe" - LIBCLANG_PATH: "C:\\ProgramData\\scoop\\apps\\llvm\\current\\lib" + PYTHON3: 'C:\mozilla-build\python3\python3.exe' + LIBCLANG_PATH: "C:\ProgramData\scoop\apps\llvm\current\lib" run: | cargo test --verbose ${{ matrix.features }} --lib Integrity: diff --git a/mozjs/build.rs b/mozjs/build.rs index da813415aa5..300130709c2 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -4,15 +4,20 @@ extern crate bindgen; extern crate cc; +extern crate ruzstd; +extern crate tar; extern crate walkdir; +use ruzstd::StreamingDecoder; use std::env; use std::ffi::{OsStr, OsString}; use std::fs; +use std::fs::File; use std::io::Read; use std::path::{Path, PathBuf}; use std::process::Command; use std::str; +use tar::Archive; use walkdir::WalkDir; const ENV_VARS: &'static [&'static str] = &[ @@ -27,8 +32,8 @@ const ENV_VARS: &'static [&'static str] = &[ "CXXFLAGS", "MAKE", "MOZ_TOOLS", + "MOZILLABUILD", "MOZJS_FORCE_RERUN", - "MOZTOOLS_PATH", "PYTHON", "STLPORT_LIBS", ]; @@ -108,15 +113,15 @@ fn install_mozmake(mozbuild_dir: &Path) { assert!(result.success()); let mozmake_tar_zst = - fs::File::open(&mozmake_tar_zst_path).expect("Failed to open mozmake.tar.zst"); + File::open(&mozmake_tar_zst_path).expect("Failed to open mozmake.tar.zst"); let mut mozmake_compressed = - ruzstd::StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst"); + StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst"); let mut mozmake_uncompressed = Vec::new(); mozmake_compressed .read_to_end(&mut mozmake_uncompressed) .expect("Failed to decode mozmake.tar.zst"); - let mut archive = tar::Archive::new(&*mozmake_uncompressed); + let mut archive = Archive::new(&*mozmake_uncompressed); archive .unpack(mozbuild_dir.join("bin")) .expect("Failed to unpack mozmake.tar"); @@ -170,27 +175,40 @@ fn cc_flags() -> Vec<&'static str> { } fn build_jsapi(build_dir: &Path) { + fn cmd_to_string(cmd: &Command) -> String { + let mut cmd_string = format!(r#""{}""#, cmd.get_program().to_string_lossy()); + for arg in cmd.get_args() { + cmd_string.push_str(&format!(r#" "{}""#, arg.to_string_lossy())); + } + cmd_string + } + let target = env::var("TARGET").unwrap(); let mut make = find_make(); - // Put MOZTOOLS_PATH at the beginning of PATH if specified - if let Some(moztools) = env::var_os("MOZTOOLS_PATH") { - let mozbuild_dir = env::var_os("MOZILLA_BUILD").unwrap_or("C:\\mozilla-build".into()); - let mozbuild_dir = Path::new(&mozbuild_dir); + let mozbuild = env::var_os("MOZILLABUILD").map(|mozbuild_env| { + if mozbuild_env.is_empty() || mozbuild_env.to_ascii_lowercase() == "true" { + PathBuf::from(r#"C:\mozilla-build\"#) + } else { + PathBuf::from(&mozbuild_env) + } + }); + if let Some(mozbuild_dir) = &mozbuild { + // Add mozmake to PATH let path = env::var_os("PATH").unwrap(); let mut paths = Vec::new(); - paths.extend(env::split_paths(&moztools)); + paths.push(mozbuild_dir.join("bin").join("mozmake").into()); paths.extend(env::split_paths(&path)); - paths.push(mozbuild_dir.join("bin").join("mozmake").into()); let new_path = env::join_paths(paths).unwrap(); env::set_var("PATH", &new_path); + // Install mozmake if not installed if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { install_mozmake(&mozbuild_dir); } - make = "mozmake".into(); + make = OsString::from("mozmake"); } let mut cmd = Command::new(make); @@ -202,10 +220,10 @@ fn build_jsapi(build_dir: &Path) { )); cppflags.push(" "); cppflags.push(env::var_os("CPPFLAGS").unwrap_or_default()); - cmd.env("CPPFLAGS", cppflags); + cmd.env("CPPFLAGS", &cppflags); if let Some(makeflags) = env::var_os("CARGO_MAKEFLAGS") { - cmd.env("MAKEFLAGS", makeflags); + cmd.env("MAKEFLAGS", &makeflags); } if target.contains("apple") || target.contains("freebsd") { @@ -214,15 +232,41 @@ fn build_jsapi(build_dir: &Path) { let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); - let result = cmd - .args(&["-R", "-f"]) + cmd.args(&["-R", "-f"]) .arg(cargo_manifest_dir.join("makefile.cargo")) .current_dir(&build_dir) .env("SRC_DIR", &cargo_manifest_dir.join("mozjs")) - .env("NO_RUST_PANIC_HOOK", "1") - .status() - .expect("Failed to run `make`"); - assert!(result.success()); + .env("NO_RUST_PANIC_HOOK", "1"); + + if let Some(mozbuild_dir) = mozbuild { + // Create script that runs mozmake + let script_path = build_dir.join("mozbuild.sh"); + let script = cmd_to_string(&cmd); + fs::write(&script_path, script).expect("Failed to write to mozbuild.sh"); + + let start_shell = mozbuild_dir.join("start-shell.bat"); + let mut shell = Command::new(start_shell.as_os_str()); + shell + .arg("-here") + .arg("-use-full-path") + .arg(script_path.display().to_string()); + + for (key, value) in cmd.get_envs() { + if let Some(value) = value { + shell.env(key, value); + } + } + + if let Some(current_dir) = cmd.get_current_dir() { + shell.current_dir(current_dir); + } + + let result = shell.status().expect("Failed to run `make`"); + assert!(result.success()); + } else { + let result = cmd.status().expect("Failed to run `make`"); + assert!(result.success()); + } println!( "cargo:rustc-link-search=native={}/js/src/build", From 5caf1fd95432cbe4f26e41967a56da94539c5e67 Mon Sep 17 00:00:00 2001 From: Redfire Date: Mon, 5 Dec 2022 03:20:12 +0800 Subject: [PATCH 10/16] Fixed Windows CI Environment --- .github/workflows/rust.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index abece7e2fd1..61217ca7f25 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -90,12 +90,12 @@ jobs: - name: Build uwp if: contains(matrix.target, 'uwp') env: - MOZILLA_BUILD: 'C:\mozilla-build' + MOZILLABUILD: 'C:\mozilla-build' LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" PYTHON3: 'C:\mozilla-build\python3\python3.exe' - LIBCLANG_PATH: "C:\ProgramData\scoop\apps\llvm\current\lib" + LIBCLANG_PATH: 'C:\ProgramData\scoop\apps\llvm\current\lib' run: | rustup install nightly-2022-11-20 rustup default nightly @@ -104,12 +104,12 @@ jobs: - name: Build Windows if: contains(matrix.target, 'uwp') != true env: - MOZILLA_BUILD: 'C:\mozilla-build' + MOZILLABUILD: 'C:\mozilla-build' LINKER: "lld-link.exe" CC: "clang-cl.exe" CXX: "clang-cl.exe" PYTHON3: 'C:\mozilla-build\python3\python3.exe' - LIBCLANG_PATH: "C:\ProgramData\scoop\apps\llvm\current\lib" + LIBCLANG_PATH: 'C:\ProgramData\scoop\apps\llvm\current\lib' run: | cargo test --verbose ${{ matrix.features }} --lib Integrity: From 0e67a76bd18290eb5fe75b9b03de0db151d097ab Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 6 Jan 2023 17:11:56 +0800 Subject: [PATCH 11/16] Removed Build Dependency on ruzstd and tar on Non-Windows Platforms Changed mozmake Installation to occur only on Windows Changed MozillaBuild detection and integration to occur only on Windows --- mozjs/Cargo.toml | 4 +- mozjs/build.rs | 100 +++++++++++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/mozjs/Cargo.toml b/mozjs/Cargo.toml index 73563c7fa81..0e9bda9aca8 100644 --- a/mozjs/Cargo.toml +++ b/mozjs/Cargo.toml @@ -36,6 +36,8 @@ libz-sys = "1.0" [build-dependencies] bindgen = { version = "0.62", default-features = false, features = ["runtime", "which-rustfmt"] } cc = "1.0" -tar = "0.4.38" walkdir = "2" + +[target.'cfg(windows)'.build-dependencies] ruzstd = "0.3.0" +tar = "0.4.38" diff --git a/mozjs/build.rs b/mozjs/build.rs index 300130709c2..70d5bad5a08 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -4,11 +4,12 @@ extern crate bindgen; extern crate cc; +#[cfg(windows)] extern crate ruzstd; +#[cfg(windows)] extern crate tar; extern crate walkdir; -use ruzstd::StreamingDecoder; use std::env; use std::ffi::{OsStr, OsString}; use std::fs; @@ -17,7 +18,6 @@ use std::io::Read; use std::path::{Path, PathBuf}; use std::process::Command; use std::str; -use tar::Archive; use walkdir::WalkDir; const ENV_VARS: &'static [&'static str] = &[ @@ -100,6 +100,7 @@ fn find_make() -> OsString { } } +#[cfg(windows)] fn install_mozmake(mozbuild_dir: &Path) { let mozbuild_dir = Path::new(mozbuild_dir); let mozmake_tar_zst_path = mozbuild_dir.join("mozmake.tar.zst"); @@ -115,13 +116,13 @@ fn install_mozmake(mozbuild_dir: &Path) { let mozmake_tar_zst = File::open(&mozmake_tar_zst_path).expect("Failed to open mozmake.tar.zst"); let mut mozmake_compressed = - StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst"); + ruzstd::StreamingDecoder::new(mozmake_tar_zst).expect("Failed to decode mozmake.tar.zst"); let mut mozmake_uncompressed = Vec::new(); mozmake_compressed .read_to_end(&mut mozmake_uncompressed) .expect("Failed to decode mozmake.tar.zst"); - let mut archive = Archive::new(&*mozmake_uncompressed); + let mut archive = tar::Archive::new(&*mozmake_uncompressed); archive .unpack(mozbuild_dir.join("bin")) .expect("Failed to unpack mozmake.tar"); @@ -193,22 +194,25 @@ fn build_jsapi(build_dir: &Path) { PathBuf::from(&mozbuild_env) } }); + + #[cfg(windows)] + { + if let Some(mozbuild_dir) = &mozbuild { + // Add mozmake to PATH + let path = env::var_os("PATH").unwrap(); + let mut paths = Vec::new(); + paths.push(mozbuild_dir.join("bin").join("mozmake").into()); + paths.extend(env::split_paths(&path)); + let new_path = env::join_paths(paths).unwrap(); + env::set_var("PATH", &new_path); + + // Install mozmake if not installed + if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { + install_mozmake(&mozbuild_dir); + } - if let Some(mozbuild_dir) = &mozbuild { - // Add mozmake to PATH - let path = env::var_os("PATH").unwrap(); - let mut paths = Vec::new(); - paths.push(mozbuild_dir.join("bin").join("mozmake").into()); - paths.extend(env::split_paths(&path)); - let new_path = env::join_paths(paths).unwrap(); - env::set_var("PATH", &new_path); - - // Install mozmake if not installed - if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { - install_mozmake(&mozbuild_dir); + make = OsString::from("mozmake"); } - - make = OsString::from("mozmake"); } let mut cmd = Command::new(make); @@ -238,36 +242,46 @@ fn build_jsapi(build_dir: &Path) { .env("SRC_DIR", &cargo_manifest_dir.join("mozjs")) .env("NO_RUST_PANIC_HOOK", "1"); - if let Some(mozbuild_dir) = mozbuild { - // Create script that runs mozmake - let script_path = build_dir.join("mozbuild.sh"); - let script = cmd_to_string(&cmd); - fs::write(&script_path, script).expect("Failed to write to mozbuild.sh"); - - let start_shell = mozbuild_dir.join("start-shell.bat"); - let mut shell = Command::new(start_shell.as_os_str()); - shell - .arg("-here") - .arg("-use-full-path") - .arg(script_path.display().to_string()); - - for (key, value) in cmd.get_envs() { - if let Some(value) = value { - shell.env(key, value); + #[cfg(not(windows))] + { + let result = cmd.status().expect("Failed to run `make`"); + assert!(result.success()); + } + + #[cfg(windows)] + { + if let Some(mozbuild_dir) = mozbuild { + // Create script that runs mozmake + let script_path = build_dir.join("mozbuild.sh"); + let script = cmd_to_string(&cmd); + fs::write(&script_path, script).expect("Failed to write to mozbuild.sh"); + + let start_shell = mozbuild_dir.join("start-shell.bat"); + let mut shell = Command::new(start_shell.as_os_str()); + shell + .arg("-here") + .arg("-use-full-path") + .arg(script_path.display().to_string()); + + for (key, value) in cmd.get_envs() { + if let Some(value) = value { + shell.env(key, value); + } } - } - if let Some(current_dir) = cmd.get_current_dir() { - shell.current_dir(current_dir); - } + if let Some(current_dir) = cmd.get_current_dir() { + shell.current_dir(current_dir); + } - let result = shell.status().expect("Failed to run `make`"); - assert!(result.success()); - } else { - let result = cmd.status().expect("Failed to run `make`"); - assert!(result.success()); + let result = shell.status().expect("Failed to run `make`"); + assert!(result.success()); + } else { + let result = cmd.status().expect("Failed to run `make`"); + assert!(result.success()); + } } + println!( "cargo:rustc-link-search=native={}/js/src/build", build_dir.display() From 43708c48646331d9433de080a24a615b7abb9502 Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 6 Jan 2023 19:05:52 +0800 Subject: [PATCH 12/16] Fixed find_make Added Checking for make and gmake on All Platforms Added Checking for mozmake on Windows --- mozjs/build.rs | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/mozjs/build.rs b/mozjs/build.rs index 70d5bad5a08..5935780e8c6 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -83,21 +83,36 @@ fn main() { } } -fn find_make() -> OsString { - if let Some(make) = env::var_os("MAKE") { - make - } else { - match Command::new("gmake").status() { - Ok(gmake) => { - if gmake.success() { - OsStr::new("gmake").to_os_string() +fn find_make() -> Option { + fn check_make(name: &OsStr) -> bool { + let mut cmd = Command::new(name); + cmd.arg("--version"); + cmd.status().map(|status| status.success()).unwrap_or(false) + } + + env::var_os("MAKE").or_else(|| { + let gmake = OsString::from("gmake"); + let make = OsString::from("make"); + if check_make(&gmake) { + Some(gmake) + } else if check_make(&make) { + Some(make) + } else { + #[cfg(windows)] + { + let mozmake = OsString::from("mozmake"); + if check_make(&mozmake) { + Some(mozmake) } else { - OsStr::new("make").to_os_string() + None } } - Err(_) => OsStr::new("make").to_os_string(), + #[cfg(unix)] + { + None + } } - } + }) } #[cfg(windows)] @@ -206,15 +221,18 @@ fn build_jsapi(build_dir: &Path) { let new_path = env::join_paths(paths).unwrap(); env::set_var("PATH", &new_path); - // Install mozmake if not installed - if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { - install_mozmake(&mozbuild_dir); - } + if make.is_none() { + // Install mozmake if not installed + if !mozbuild_dir.join("MOZMAKE_LOCK").exists() { + install_mozmake(&mozbuild_dir); + } - make = OsString::from("mozmake"); + make = Some(OsString::from("mozmake")); + } } } + let make = make.expect("Install `make` or `gmake`"); let mut cmd = Command::new(make); let encoding_c_mem_include_dir = env::var("DEP_ENCODING_C_MEM_INCLUDE_DIR").unwrap(); From 40649acffa9d5a11ff256340652a68cc02c09fea Mon Sep 17 00:00:00 2001 From: Redfire Date: Mon, 20 Feb 2023 13:44:40 +0800 Subject: [PATCH 13/16] Resolved Merge Conflicts --- mozjs/makefile.cargo | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/mozjs/makefile.cargo b/mozjs/makefile.cargo index 9e7ece459d5..3dfeb659181 100644 --- a/mozjs/makefile.cargo +++ b/mozjs/makefile.cargo @@ -79,37 +79,37 @@ ifneq ($(HOST),$(TARGET)) endif endif -ifeq ($(WINDOWS),) - CC ?= $(TARGET)-gcc - CPP ?= $(TARGET)-gcc -E - CXX ?= $(TARGET)-g++ - AR ?= $(TARGET)-ar - CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold -endif + ifeq ($(WINDOWS),) + CC ?= $(TARGET)-gcc + CPP ?= $(TARGET)-gcc -E + CXX ?= $(TARGET)-g++ + AR ?= $(TARGET)-ar + CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold + endif else -ifeq (,$(WINDOWS)) - ifeq (freebsd,$(findstring freebsd,$(TARGET))) - # Does not symlink clang as "gcc" like macOS does - CC ?= clang - CPP ?= clang -E - CXX ?= clang++ - else - CC ?= gcc - CPP ?= gcc -E - CXX ?= g++ - endif -AR ?= ar + ifeq (,$(WINDOWS)) + ifeq (freebsd,$(findstring freebsd,$(TARGET))) + # Does not symlink clang as "gcc" like macOS does + CC ?= clang + CPP ?= clang -E + CXX ?= clang++ + else + CC ?= cc + CPP ?= cc -E + CXX ?= c++ + endif + AR ?= ar -# check if python2 is a valid Python executable, otherwise fall back to python -ifeq (, $(findstring Python 2.,$(shell python2 --version 2> /dev/null))) -PYTHON ?= python2 -else -PYTHON ?= python -endif + # check if python2 is a valid Python executable, otherwise fall back to python + ifeq (, $(findstring Python 2.,$(shell python2 --version 2> /dev/null))) + PYTHON ?= python2 + else + PYTHON ?= python + endif -endif + endif endif From 42a7dfa2956b2f9733474e3f2ad5fa1216feb902 Mon Sep 17 00:00:00 2001 From: Redfire Date: Mon, 20 Feb 2023 23:34:45 +0800 Subject: [PATCH 14/16] Removed Python 2 Support in Makefile Switched to cygpath on MSVC Reformatted Makefile --- mozjs/makefile.cargo | 92 +++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/mozjs/makefile.cargo b/mozjs/makefile.cargo index 3dfeb659181..fc3729260ad 100644 --- a/mozjs/makefile.cargo +++ b/mozjs/makefile.cargo @@ -79,7 +79,7 @@ ifneq ($(HOST),$(TARGET)) endif endif - ifeq ($(WINDOWS),) + ifeq (,$(WINDOWS)) CC ?= $(TARGET)-gcc CPP ?= $(TARGET)-gcc -E CXX ?= $(TARGET)-g++ @@ -87,28 +87,25 @@ ifneq ($(HOST),$(TARGET)) CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold endif -else - - ifeq (,$(WINDOWS)) - ifeq (freebsd,$(findstring freebsd,$(TARGET))) - # Does not symlink clang as "gcc" like macOS does - CC ?= clang - CPP ?= clang -E - CXX ?= clang++ - else - CC ?= cc - CPP ?= cc -E - CXX ?= c++ - endif - AR ?= ar - - # check if python2 is a valid Python executable, otherwise fall back to python - ifeq (, $(findstring Python 2.,$(shell python2 --version 2> /dev/null))) - PYTHON ?= python2 - else - PYTHON ?= python - endif +else ifeq (,$(WINDOWS)) + + ifeq (freebsd,$(findstring freebsd,$(TARGET))) + # Does not symlink clang as "gcc" like macOS does + CC ?= clang + CPP ?= clang -E + CXX ?= clang++ + else + CC ?= cc + CPP ?= cc -E + CXX ?= c++ + endif + AR ?= ar + # check if python3 is a valid Python executable, otherwise fall back to python + ifeq (,$(findstring Python 3.,$(shell python3 --version 2> /dev/null))) + PYTHON ?= python3 + else + PYTHON ?= python endif endif @@ -125,29 +122,28 @@ ifneq (,$(CCACHE)) CONFIGURE_FLAGS += --with-ccache=$(CCACHE) endif -ifneq ($(WINDOWS),) +ifneq (,$(WINDOWS)) # Visual Studio build - NEED_WIN_PYTHON := 1 - - # There's no cygpath in mozilla-build, and we're expecting to - # be building with MOZ_BUILD_TOOLS, so do our best - OUT_DIR:=$(subst \,/,$(OUT_DIR)) - -ifeq ($(findstring x86_64,$(TARGET)),x86_64) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32 -else ifeq ($(findstring i686,$(TARGET)),i686) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=x86_64-pc-mingw32 -else ifeq ($(findstring aarch64,$(TARGET)),aarch64) - # This is the correct target for MSVC builds - CONFIGURE_FLAGS += --target=aarch64-windows-mingw32 --host=x86_64-pc-mingw32 -endif + + OUT_DIR:=$(shell cygpath "$(OUT_DIR)") + + # Fake out the SM build with a dummy dir here; just needs $(MOZ_TOOLS)/bin + # to exist MOZ_TOOLS=/ + ifeq ($(findstring x86_64,$(TARGET)),x86_64) + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32 + else ifeq ($(findstring i686,$(TARGET)),i686) + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=x86_64-pc-mingw32 + else ifeq ($(findstring aarch64,$(TARGET)),aarch64) + # This is the correct target for MSVC builds + CONFIGURE_FLAGS += --target=aarch64-windows-mingw32 --host=x86_64-pc-mingw32 + endif + else ifeq ($(MSYSTEM),MINGW64) # MSYS2/MINGW64 build - NEED_WIN_PYTHON := 1 # msys2 sets CC=cc as default. however, there is no `cc.exe`. # overwrite it here. @@ -159,25 +155,9 @@ else ifeq ($(MSYSTEM),MINGW64) # cargo uses Windows native path. msys2 make unfortunately doesn't understand it. OUT_DIR:=$(shell cygpath "$(OUT_DIR)") - # Fake out the SM build with a dummy dir here; just needs $(MOZ_TOOLS)/bin - # to exist MOZ_TOOLS=/ endif -# If we need to do extra work to find an appropriate python on -# Windows, do it here -# ifeq ($(NEED_WIN_PYTHON),1) -# ifneq (,$(NATIVE_WIN32_PYTHON)) -# PYTHON := $(NATIVE_WIN32_PYTHON) -# else ifneq (,$(wildcard c:/python27/python.exe)) -# PYTHON := c:/python27/python.exe -# else -# $(message You must either have the Native Win32 python installed in C:/python27, or set NATIVE_WIN32_PYTHON to point to the appropriate python.exe.) -# $(message Download the Python installer from https://www.python.org/downloads/release/python-2710/) -# $(error Native Win32 Python not found) -# endif -# endif - .PHONY : all maybe-configure all: maybe-configure From 81ed487eb44b8ed8a8b4e128395f9050cf045e4c Mon Sep 17 00:00:00 2001 From: Redfire Date: Tue, 21 Feb 2023 00:00:55 +0800 Subject: [PATCH 15/16] Updated Windows Build Instructions --- README.md | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index aebc3b1d24d..a45568eea90 100644 --- a/README.md +++ b/README.md @@ -29,30 +29,21 @@ export LIBCLANG_PATH=/usr/lib/clang/4.0/lib Under Windows: 1. Follow the directions at - https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Windows_Prerequisites + https://firefox-source-docs.mozilla.org/setup/windows_build.html. + (Steps 1.1 and 1.2) -2. Open up a shell configured to use Visual Studio. This could be the - one included with Visual Studio (e.g. Visual Studio 2017 / X64 Native - Tools Command Prompt for VS 2017) or a shell in which you have run -``` -"c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat" -``` - -3. Set the `MOZTOOLS_PATH` environment variable to point to the tools from the Mozilla Build Package: -``` -set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\bin -``` - -4. Download and install Clang for Windows (64 bit) from https://releases.llvm.org/download.html +2. Download and install Clang for Windows (64 bit) from https://releases.llvm.org/download.html and set the `LIBCLANG_PATH` environment variable to its `lib` directory: ``` set LIBCLANG_PATH=C:\Program Files\LLVM\lib ``` -5. Set environment variables so the build script can find Python 2.7 and Autoconf 2.13: +3. Set environment variables so the build script can find Python 2.7 and Autoconf 2.13: ``` -set AUTOCONF=C:\mozilla-build\msys\local\bin\autoconf-2.13 -set NATIVE_WIN32_PYTHON=C:\mozilla-build\python\python2.7.exe +set CC=clang-cl.exe +set CXX=clang-cl.exe +set LINKER=lld-link.exe +set MOZILLABUILD=C:\mozilla-build ``` You can now build and test the crate using cargo: From d4a691f9d8a46c428dc12490e0e8f86b9c852141 Mon Sep 17 00:00:00 2001 From: Redfire Date: Wed, 8 Mar 2023 13:45:04 +0800 Subject: [PATCH 16/16] Added Initialisation for MOZILLABUILD Environment Variable Fixed Wording in ReadME --- README.md | 2 +- mozjs/build.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a45568eea90..8ebad06ef70 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Under Windows: set LIBCLANG_PATH=C:\Program Files\LLVM\lib ``` -3. Set environment variables so the build script can find Python 2.7 and Autoconf 2.13: +3. Set environment variables so the build script can find the build tools. ``` set CC=clang-cl.exe set CXX=clang-cl.exe diff --git a/mozjs/build.rs b/mozjs/build.rs index 5935780e8c6..604735ed1b8 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -204,6 +204,7 @@ fn build_jsapi(build_dir: &Path) { let mozbuild = env::var_os("MOZILLABUILD").map(|mozbuild_env| { if mozbuild_env.is_empty() || mozbuild_env.to_ascii_lowercase() == "true" { + env::set_var("MOZILLABUILD", r#"C:\mozilla-build\"#); PathBuf::from(r#"C:\mozilla-build\"#) } else { PathBuf::from(&mozbuild_env)