tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 36868c346befb56bd92ad0f2c12dffc3639866a7
parent c72557b7aa9ffb5de4ef75c46dda35d36321d745
Author: Mike Hommey <mh+mozilla@glandium.org>
Date:   Tue,  9 Dec 2025 08:14:37 +0000

Bug 2004178 - Add a rust-dev compiler for Windows. r=firefox-build-system-reviewers,ahochheiden

Differential Revision: https://phabricator.services.mozilla.com/D275156

Diffstat:
Mtaskcluster/kinds/toolchain/rust.yml | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtaskcluster/scripts/misc/repack_rust.py | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 120 insertions(+), 16 deletions(-)

diff --git a/taskcluster/kinds/toolchain/rust.yml b/taskcluster/kinds/toolchain/rust.yml @@ -128,6 +128,33 @@ linux64-rust-1.82-dev: - linux64-clang-toolchain - linux64-toolchain-sysroot +win64-rust-1.82-dev: + description: "build rust from source" + worker-type: b-win2022 + treeherder: + symbol: TW64(rust-dev) + run: + arguments: [ + '--patch', 'rust-vendor-std.patch', + '--channel', 'dev', + '--host', 'x86_64-pc-windows-msvc', + '--target', 'x86_64-pc-windows-msvc', + ] + resources: + - build/build-rust/rust-vendor-std.patch + toolchain-alias: + by-project: + toolchains: null + default: win64-rust-dev + fetches: + fetch: + - rust-1.82.0 + - win64-ninja + toolchain: + - win64-clang-toolchain + - win64-cmake + - vs + linux64-rust-cross-1.90: description: "rust repack with macos and windows cross support" treeherder: @@ -345,6 +372,35 @@ linux64-rust-nightly-dev: - linux64-clang-toolchain - linux64-toolchain-sysroot +win64-rust-nightly-dev: + attributes: + cached_task: false + description: "build rust from source" + worker-type: b-win2022 + treeherder: + symbol: TW64(rust-dev-nightly) + run: + arguments: [ + '--patch', 'rust-vendor-std.patch', + '--channel', 'dev', + '--host', 'x86_64-pc-windows-msvc', + '--target', 'x86_64-pc-windows-msvc', + ] + resources: + - build/build-rust/rust-vendor-std.patch + toolchain-alias: + by-project: + toolchains: win64-rust-dev + default: null + fetches: + fetch: + - rust-nightly + - win64-ninja + toolchain: + - win64-clang-toolchain + - win64-cmake + - vs + linux64-rust-cross-nightly: attributes: cached_task: false diff --git a/taskcluster/scripts/misc/repack_rust.py b/taskcluster/scripts/misc/repack_rust.py @@ -432,17 +432,39 @@ def build_src(install_dir, host, targets, patches): download-ci-llvm = false """ ) - - # Rust requires these to be specified per-target - target_config = textwrap.dedent( - """ - [target.{target}] - cc = "clang" - cxx = "clang++" - linker = "clang" - - """ - ) + if "msvc" in host: + assert all("msvc" in target for target in targets) + base_config += textwrap.dedent( + f""" + ldflags = "-winsysroot:{fetches}/vs" + + [llvm.build-config] + CMAKE_MT = "llvm-mt.exe" + CMAKE_ASM_MASM_COMPILER = "ml64.exe" + """ + ) + target_config = textwrap.dedent( + """ + [target.{target}] + cc = "clang-cl.bat" + cxx = "clang-cl.bat" + linker = "lld-link.bat" + ar = "llvm-lib" + + """ + ) + else: + assert all("msvc" not in target for target in targets) + # Rust requires these to be specified per-target + target_config = textwrap.dedent( + """ + [target.{target}] + cc = "clang" + cxx = "clang++" + linker = "clang" + + """ + ) final_config = base_config for target in sorted(set(targets) | set([host])): @@ -457,11 +479,11 @@ def build_src(install_dir, host, targets, patches): clang_lib = os.path.join(clang, "lib") sysroot = os.path.join(fetches, "sysroot") - # The rust build doesn't offer much in terms of overriding compiler flags - # when it builds LLVM's compiler-rt, but we want to build with a sysroot. - # So, we create wrappers for clang and clang++ that add the sysroot to the - # command line. with tempfile.TemporaryDirectory() as tmpdir: + # The rust build doesn't offer much in terms of overriding compiler flags + # when it builds LLVM's compiler-rt, but we want to build with a sysroot. + # So, we create wrappers for clang and clang++ that add the sysroot to the + # command line. for exe in ("clang", "clang++"): tmp_exe = os.path.join(tmpdir, exe) with open(tmp_exe, "w") as fh: @@ -469,6 +491,21 @@ def build_src(install_dir, host, targets, patches): fh.write(f'exec {clang_bin}/{exe} --sysroot={sysroot} "$@"\n') os.chmod(tmp_exe, 0o755) + if "msvc" in host: + # Same thing for the linker on windows, where we want to add the MSVC + # sysroot + with open(os.path.join(tmpdir, "lld-link.bat"), "w") as fh: + fh.write("@echo off\n") + fh.write(f"{clang_bin}/lld-link.exe -winsysroot:{fetches}/vs %*") + # And clang-cl. + with open(os.path.join(tmpdir, "clang-cl.bat"), "w") as fh: + fh.write("@echo off\n") + fh.write( + f"{clang_bin}/clang-cl.exe -Xclang -ivfsoverlay -Xclang {fetches}/vs/overlay.yaml -winsysroot {fetches}/vs %*" + ) + # cc-rs expects to find ml64.exe to build asm files, without a way to override it. + shutil.copy(f"{clang_bin}/llvm-ml.exe", f"{tmpdir}/ml64.exe") + env = os.environ.copy() env.update( { @@ -477,10 +514,21 @@ def build_src(install_dir, host, targets, patches): "DESTDIR": install_dir, } ) + if "msvc" in host: + cmake_bin = os.path.join(fetches, "cmake", "bin") + ninja_bin = os.path.join(fetches, "ninja", "bin") + env.update( + { + "PATH": os.pathsep.join((env["PATH"], cmake_bin, ninja_bin)), + "CC_x86_64_pc_windows_msvc": "clang-cl.bat", + "CXX_x86_64_pc_windows_msvc": "clang-cl.bat", + "AR_x86_64_pc_windows_msvc": "llvm-lib", + } + ) # x.py install does everything we need for us. # If you're running into issues, consider using `-vv` to debug it. - command = ["python3", "x.py", "install", "-v", "--host", host] + command = ["python3", "x.py", "install", "-v", "--host", host, "--build", host] for target in targets: command.extend(["--target", target])