Skip to content

mach: Fix cross-compiling from windows to non windows#36070

Merged
jschwe merged 1 commit intoservo:mainfrom
jschwe:jschwender/windows-fix-cross
Apr 4, 2025
Merged

mach: Fix cross-compiling from windows to non windows#36070
jschwe merged 1 commit intoservo:mainfrom
jschwe:jschwender/windows-fix-cross

Conversation

@jschwe
Copy link
Copy Markdown
Member

@jschwe jschwe commented Mar 20, 2025

Since we switched to using aws-lc-rs instead of ring, cross-compiling on windows (to non-windows) had been broken. Using the default MSVC Generator results in CMake erroneously being configured for the host platform, with failing compiler checks. Switching to Ninja fixes that issue.

The CMake build rules of aws-lc-rs also make use of tr and assume it is installed, hence we provide a helpful error message suggesting to try using mach from git bash which does provide the tr command.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix cross-compiling servo on windows hosts to non-windows targets
  • These changes do not require tests because: We don't test cross-compiling from windows hosts in CI. These changes were manually tested by compiling for OpenHarmony on windows.

Since we switched to using `aws-lc-rs` instead of `ring`,
cross-compiling on windows (to non-windows) had been broken.
Using the default MSVC Generator results in CMake erroneously
being configured for the host platform, with failing compiler checks.
Switching to Ninja fixes that issue.

The CMake build rules of aws-lc-rs also make use of `tr` and assume
it is installed, hence we provide a helpful error message suggesting
to try using mach from `git bash` which does provide the `tr` command.

Signed-off-by: Jonathan Schwender <[email protected]>
Comment on lines +515 to +527
if sys.platform == 'win32' and 'windows' not in self.target.triple():
# aws-lc-rs only supports the Ninja Generator when cross-compiling on windows hosts to non-windows.
env['TARGET_CMAKE_GENERATOR'] = "Ninja"
if shutil.which('ninja') is None:
print("Error: Cross-compiling servo on windows requires the Ninja tool to be installed and in PATH.")
print("Hint: Ninja-build is available on github at: https://github.com/ninja-build/ninja/releases")
exit(1)
# `tr` is also required by the CMake build rules of `aws-lc-rs`
if shutil.which('tr') is None:
print("Error: Cross-compiling servo on windows requires the `tr` tool, which was not found.")
print("Hint: Try running ./mach from `git bash` instead of powershell.")
exit(1)

Copy link
Copy Markdown
Member

@mrobinson mrobinson Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate, because it adds one more place where Servo depends on mach to build properly. Could we modify the build to always require and install ninja and tr by default, and set the environment variable via Cargo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think building servo for OpenHarmony via just cargo already works perfectly fine - you "just" need to source a bash file which exports all the same environment variables we are setting here in mach. The advantage of setting environment variables via python is that it doesn't depend on the shell.

We could add ninja to the bootstrap, but I thought our current policy was to only install tools in bootstrap that are needed to build servo for the host platform. For tr - it's a unix tool, so I don't think we can really force its availability. Ideally aws-lc-rs wouldn't use tr on windows, but I suspect it isn't too simple.

@jschwe jschwe added this pull request to the merge queue Apr 4, 2025
Merged via the queue into servo:main with commit d6d610e Apr 4, 2025
21 checks passed
@jschwe jschwe deleted the jschwender/windows-fix-cross branch April 4, 2025 09:14
github-merge-queue bot pushed a commit that referenced this pull request Jan 8, 2026
…#41748)

I never forget that day: @dependabot updates aws-lc-rs, and
cross-compilation Servo from Windows fails. We were left with two
options:
1. Get a local clone of aws-lc-rs, and modify it in a hacky way
2. Use Git Bash, but still has to set up MSYS2 etc.

Later, we've been restricted since #36070 to only use option 2 due to
restrictions imposed here. But the system is innocent, and it is
aws-lc-rs's responsibility to fix the rules. Still, @d-desiatkin and I
believed that day would come, when we would return justice to the
victim.

Freedom is better served late than never. It is now working normally
since aws-lc-rs has fixed the rules.

Signed-off-by: Euclid Ye <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants