commit f1c7fc7b532c50ee270e0509539f67116cbe36ad
parent 42b548adbb38248ac246f24b446cbdbb0d4c1d05
Author: Mike Hommey <mh+mozilla@glandium.org>
Date: Mon, 10 Nov 2025 22:08:14 +0000
Bug 1998855 - Use cargo-linker on Windows too. r=firefox-build-system-reviewers,sergesanspaille
The reason we use cargo-linker.bat is that cargo invokes it via
CreateProcess, which can't handle the shebang in the cargo-linker
script.
Back when cargo-linker.bat was added, cargo-linker was a shell script
that was doing essentially the same thing as it does. Things have
evolved such that the cargo-linker script is now a python script that
actually handles some edge cases that cargo-linker.bat doesn't handle,
notably quoting in the MOZ_CARGO_WRAP_LDFLAGS variable.
In some corner cases, quoting may happen there on Windows too, so we
need the same workaround, so we route linking through cargo-linker on
Windows too.
Ideally, we'd update cargo-host-linker* too, but practically speaking
it's only used when cross-compiling, and while the edge cases are
theoretically possible, they're much less likely than for cargo-linker
so for now, we leave cargo-host-linker* as they are (which is, also not
up-to-par with cargo-linker from before this change).
Differential Revision: https://phabricator.services.mozilla.com/D271725
Diffstat:
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/build/cargo-linker b/build/cargo-linker
@@ -63,4 +63,9 @@ for arg in sys.argv[1:]:
args.extend(split(os.environ["MOZ_CARGO_WRAP_LDFLAGS"]))
wrap_ld = split(wrap_ld)
+if sys.platform == "win32":
+ # For some reason, os.execvp doesn't handle arguments properly on Windows.
+ import subprocess
+ sys.exit(subprocess.run(wrap_ld + args).returncode)
+
os.execvp(wrap_ld[0], wrap_ld + args)
diff --git a/build/cargo-linker.bat b/build/cargo-linker.bat
@@ -1,2 +1,4 @@
@echo off
-%MOZ_CARGO_WRAP_LD% %* %MOZ_CARGO_WRAP_LDFLAGS%
+REM %~dpn0 expands %0 to a combination of Drive, Path, and Name (i.e.
+REM it removes the .bat extension from this script's full path)
+%PYTHON3% %~dpn0 %*