Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Use the right LLVM tools and arguments for MSVC cross-compilation #160

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented Jan 4, 2024

xbuild uses the headers from xwin to support cross-compiling, but doesn't fully replicate the other setup steps that it proposes to provide a valid and working cross-compilation setup to MSVC. We need to make the following changes:

  • clang-cl must be used (a clang driver with cl.exe interface), as all native projects will call CC/CXX with flags that are only compatible with cl.exe;

  • -I does not seem to set up the system headers correctly, for this -imsvc should be used;

  • Remove -Clink-arg=-fuse-ld=lld-link because we have already selected a linker for Rust with the LINKER env var (see warning below). We might instead want to set it in C(XX)FLAGS so that when a native crate uses CC/CXX to link libraries, it can use lld-link instead of (probably, like cargo/rustc when LINKER is unsed) using link.exe by default;

  • Unset forced static CRT and stdlib=libc++ selection, as these don't appear to ever be needed, and cause some builds to fail (when crates are changing these config options themselves?):

    = note: rust-lld: warning: ignoring unknown argument '-fuse-ld=lld-link'
            rust-lld: error: /failifmismatch: mismatch detected for 'RuntimeLibrary':
            >>> libbasis_universal_sys-4f5abd4a27e6aa13.rlib(basisu_resample_filters.o) has value MT_StaticRelease
            >>> libintel_tex_2-6d9bd3438efd06d9.rlib(ispc_texcomp_astc.o) has value MD_DynamicRelease
    

@MarijnS95 MarijnS95 requested a review from dvc94ch January 4, 2024 16:09
`xbuild` uses the headers from `xwin` to support cross-compiling,
but doesn't fully replicate the other setup steps that it proposes to
provide a valid and working cross-compilation setup to MSVC.  We need to
make the following changes:

- `clang-cl` must be used (a `clang` driver with `cl.exe` interface),
  as all native projects will call `CC`/`CXX` with flags that are only
  compatible with `cl.exe`;
- `-I` does not seem to set up the system headers correctly, for this
  `-imsvc` should be used;
- Remove `-Clink-arg=-fuse-ld=lld-link` because we have already selected
  a linker for Rust with the `LINKER` env var (see warning below). We
  might instead want to set it in `C(XX)FLAGS` so that when a native
  crate uses `CC`/`CXX` to link libraries, it can use `lld-link` instead
  of (probably, like `cargo`/`rustc` when `LINKER` is unsed) using
  `link.exe` by default;
- Unset forced static CRT and `stdlib=libc++` selection, as these don't
  appear to ever be needed, and cause some builds to fail (when crates
  are changing these config options themselves?):

      = note: rust-lld: warning: ignoring unknown argument '-fuse-ld=lld-link'
              rust-lld: error: /failifmismatch: mismatch detected for 'RuntimeLibrary':
              >>> libbasis_universal_sys-4f5abd4a27e6aa13.rlib(basisu_resample_filters.o) has value MT_StaticRelease
              >>> libintel_tex_2-6d9bd3438efd06d9.rlib(ispc_texcomp_astc.o) has value MD_DynamicRelease
@MarijnS95 MarijnS95 merged commit ffe3e34 into master Jul 12, 2024
34 checks passed
@MarijnS95 MarijnS95 deleted the fix-msvc-cross-compile branch July 12, 2024 09:52
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.

3 participants