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

clang-cl: use /arch:SSE2 for x86 target arch #1425

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Feb 27, 2025

This PR changes the flag emitted for clang-cl on x86 Windows archs to use /arch:SSE2 instead of /arch:IA321 to fix compilation errors related to missing SSE2 types following GitHub Runner Image updates that bumped the MSVC toolchain version.

Context

  • Official Rust Windows targets require SSE2 as part of baseline target features.
    • i586 Windows target without SSE2 is in process of being removed, so wasn't changed in this PR.
  • STL is built with /arch:SSE2 and no longer /arch:IA32 since Build the x86 STL with /arch:SSE2 instead of /arch:IA32 microsoft/STL#4741.
  • Relevant for GitHub Runner Image windows-2022 version 20250224.5.0 and higher.

This was noticed in rust-lang/rust CI for i686-pc-windows-msvc, where rustc_llvm builds failed because __m128i wasn't available, and it seems to be due to emitting /arch:IA32 for clang-cl.

Thanks to Fulgen for noticing this /arch:IA32 flag!

Testing

Tested over at rust-lang/rust#137724 with the changes in my branch by changing compiler cc to use my branch. It gets us past rustc_llvm builds (where it previously failed) but fails at stage 2 cargo because cargo has its own cc (and fails on curl-sys).

Footnotes

  1. /arch:SSE2 is now the default instruction set "if no /arch option is specified", see https://learn.microsoft.com/en-us/cpp/build/reference/arch-x86?view=msvc-170. (Viewed on 2025-02-27).

- Official Rust Windows targets require `SSE2` as part of baseline
  target features.
    - `i586` Windows target without SSE2 is in process of being removed,
      so wasn't changed in this commit.
- STL is built with `/arch:SSE2` and no longer `/arch:IA32` since
  <microsoft/STL#4741>.

This was noticed in rust-lang/rust CI for `i686-pc-windows-msvc`, where
`rustc_llvm` builds failed because `__m128i` wasn't available, and we
suspected it was due to `/arch:IA32`.
Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

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

I won't merge yet while you finish testing but this looks fine regardless of if it fixes rustc's CI or not. As you say, all the supported windows targets require SSE2 as a baseline.

@jieyouxu jieyouxu changed the title [WIP] clang-cl: use /arch:SSE2 for x86 target arch clang-cl: use /arch:SSE2 for x86 target arch Feb 27, 2025
@jieyouxu
Copy link
Member Author

Okay, done with editing PR description/title, this should now be good to go.

@jieyouxu jieyouxu marked this pull request as ready for review February 27, 2025 14:32
@ChrisDenton
Copy link
Member

Great thanks!

@ChrisDenton ChrisDenton merged commit 9131f33 into rust-lang:main Feb 27, 2025
73 checks passed
@jieyouxu jieyouxu deleted the x86_ia32 branch February 27, 2025 14:32
@ChrisDenton
Copy link
Member

@NobodyXu would there be anything blocking an early release? While this issue is affecting rustc's CI now it's likely to start affecting others as they update their MSVC toolchain.

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 27, 2025
Use Windows 2019 for 32-bit MVSC CI jobs

Windows 2022 runner images have been updated today, which brought with itself an unfortunate problem with compiling C code (see rust-lang/cc-rs#1425 for more details).

This is a temporary hotfix to try to unblock our CI.

r? `@jieyouxu`

try-job: i686-msvc-1
try-job: i686-msvc-2
try-job: dist-i686-msvc
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 27, 2025
Use Windows 2019 for 32-bit MVSC CI jobs

Windows 2022 runner images have been updated today, which brought with itself an unfortunate problem with compiling C code (see rust-lang/cc-rs#1425 or rust-lang#137733 for more details).

This is a temporary hotfix to try to unblock our CI.

r? `@jieyouxu`

try-job: i686-msvc-1
try-job: i686-msvc-2
try-job: dist-i686-msvc
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 27, 2025
Use Windows 2019 for 32-bit MVSC CI jobs

Windows 2022 runner images have been updated today, which brought with itself an unfortunate problem with compiling C code (see rust-lang/cc-rs#1425 or rust-lang#137733 for more details).

This is a temporary hotfix to try to unblock our CI.

r? `@jieyouxu`

try-job: i686-msvc-1
try-job: i686-msvc-2
try-job: dist-i686-msvc
@NobodyXu
Copy link
Collaborator

@NobodyXu would there be anything blocking an early release? While this issue is affecting rustc's CI now it's likely to start affecting others as they update their MSVC toolchain.

No, you can cut a new release by running the workflow 'create release pr'

Also I think the scheduled release is today, so you could also wait for it

@ChrisDenton
Copy link
Member

Let me have a look when it's scheduled. If it's going to release soon anyway it doesn't seem worth a manual trigger.

@ChrisDenton
Copy link
Member

Oh ~6 hrs. Hm. That's OK I think.

@github-actions github-actions bot mentioned this pull request Feb 28, 2025
jieyouxu added a commit to jieyouxu/cargo that referenced this pull request Feb 28, 2025
GitHub Runner Images 20250224.5.0+ ship Windows 11 SDK 10.0.26100+ from
the previous Windows 11 SDK 10.0.22621, which bumped the UCRT headers.
The new UCRT headers use SSE2 types. However, `cc` versions <= 1.2.15
emit `/arch:IA32` for `x86` Windows targets for `clang-cl`, which causes
compilation errors since `clang-cl` can't find SSE2 types without
`/arch:SSE2` specified (or defaulted). (Note that MSVC at the time of
writing silently accepts and emits instruments for code using SSE2
types, as opposed to `clang-cl` hard error-ing).

To fix this for rust-lang/rust CI, we need to bump anything that
transitively relies on `cc` and tries to use `clang-cl` on `x86` Windows
targets to compile any C/C++ code that transitively use functions or
types that require SSE2 types, such as `<wchar.h>`. `cc` 1.2.16 contains
<rust-lang/cc-rs#1425> which emits `/arch:SSE2`
instead of `/arch:IA32` for `x86` Windows targets when using `clang-cl`.
github-merge-queue bot pushed a commit to rust-lang/cargo that referenced this pull request Feb 28, 2025
…15245)

### What does this PR try to resolve?

GitHub Runner Images 20250224.5.0+ ship Windows 11 SDK 10.0.26100+
compared to the previous Windows 11 SDK 10.0.22621, which bumped the
UCRT headers. The new UCRT headers use SSE2 types. However, `cc`
versions <= 1.2.15 emit `/arch:IA32` for `x86` Windows targets for
`clang-cl`, which causes compilation errors since `clang-cl` can't find
SSE2 types without `/arch:SSE2` specified (or defaulted). (Note that
MSVC at the time of writing silently accepts and emits instruments for
code using SSE2 types, as opposed to `clang-cl` hard error-ing).

`cc` 1.2.16 contains a fix for this problem,
rust-lang/cc-rs#1425, to correctly emit
`/arch:SSE2` instead of `/arch:IA32` to enable `clang-cl` to find the
SSE2 types. However, cargo's `cc` currently is still on 1.2.13.

To fix this for rust-lang/rust CI, we need to bump anything that
transitively relies on `cc` and tries to use `clang-cl` on `x86` Windows
targets to compile any C/C++ code that transitively use functions or
types that require SSE2 types, such as `<wchar.h>`.

### How should we test and review this PR?

The fix was initially intended for `rustc_{codegen_ssa,llvm}` `cc`, and
based on testing in rust-lang/rust#137724, I was
able to successfully build `rustc_{codegen_ssa,llvm}` with a forked `cc`
based on 1.2.15 which contains the fix from
rust-lang/cc-rs#1425. Note that in the same PR,
while the compiler build succeeded, the build of cargo itself failed
since it transitively used a `cc` *without* the fix to build
`curl-sys`[^dep-chain], which failed as one might expect (`curl-sys`
tries to build C code that uses `<wchar.h>` which runs into the same
problem). Hence, this PR is opened to bump cargo's `cc` to a `cc`
version containing the fix.

### Additional information

This `x86` Windows CI problem is:

- Discussed in
https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/spurious.20.28.3F.29.20i686.20msvc.20errors.
- Tracked by rust-lang/rust#137733.

#### `cc` changelog between 1.2.13 and 1.2.16

<details>
<summary>`cc` changes since 1.2.13 up to and including 1.2.16</summary>

#####
[1.2.16](rust-lang/cc-rs@cc-v1.2.15...cc-v1.2.16)
- 2025-02-28

###### Fixed

- force windows compiler to run in `out_dir` to prevent artifacts in cwd
(#1415)

###### Other

- use `/arch:SSE2` for `x86` target arch (#1425)
- Regenerate windows-sys binding
([#1422](rust-lang/cc-rs#1422))
- Regenerate target info
([#1418](rust-lang/cc-rs#1418))
- Add LIB var when compiling flag_check (#1417)
- Change flag ordering
([#1403](rust-lang/cc-rs#1403))
- Fix archiver detection for musl cross compilation
([#1404](rust-lang/cc-rs#1404))

#####
[1.2.15](rust-lang/cc-rs@cc-v1.2.14...cc-v1.2.15)
- 2025-02-21

###### Other

- Regenerate target info
([#1406](rust-lang/cc-rs#1406))
- Always read from all `CFLAGS`-style flags
([#1401](rust-lang/cc-rs#1401))
- Simplify the error output on failed `Command` invocation
([#1397](rust-lang/cc-rs#1397))

#####
[1.2.14](rust-lang/cc-rs@cc-v1.2.13...cc-v1.2.14)
- 2025-02-14

###### Other

- Regenerate target info
([#1398](rust-lang/cc-rs#1398))
- Add support for setting `-gdwarf-{version}` based on RUSTFLAGS
([#1395](rust-lang/cc-rs#1395))
- Add support for alternative network stack io-sock on QNX 7.1 aarch64
and x86_64 ([#1312](rust-lang/cc-rs#1312))

</details>

[^dep-chain]: I think the dep chain is something like git2 ->
libgit2-sys -> curl -> curl-sys?
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Feb 28, 2025
…obzol

Bump `rustc_{codegen_ssa,llvm}` `cc` to 1.2.16 to fix `x86` Windows jobs on newest Windows SDK

Part of rust-lang#137733.

Bump `rustc_{codegen_ssa,llvm}` `cc` to 1.2.16 which contains rust-lang/cc-rs#1425 to help with rust-lang#137733. Previously tested in rust-lang#137724.

#### `cc` changelog between 1.2.13 and 1.2.16

<details>
<summary>`cc` changes since 1.2.13 up to and including 1.2.16</summary>

##### [1.2.16](rust-lang/cc-rs@cc-v1.2.15...cc-v1.2.16) - 2025-02-28

###### Fixed

- force windows compiler to run in `out_dir` to prevent artifacts in cwd (rust-lang#1415)

###### Other

- use `/arch:SSE2` for `x86` target arch (rust-lang#1425)
- Regenerate windows-sys binding ([rust-lang#1422](rust-lang/cc-rs#1422))
- Regenerate target info ([rust-lang#1418](rust-lang/cc-rs#1418))
- Add LIB var when compiling flag_check (rust-lang#1417)
- Change flag ordering ([rust-lang#1403](rust-lang/cc-rs#1403))
- Fix archiver detection for musl cross compilation ([rust-lang#1404](rust-lang/cc-rs#1404))

##### [1.2.15](rust-lang/cc-rs@cc-v1.2.14...cc-v1.2.15) - 2025-02-21

###### Other

- Regenerate target info ([rust-lang#1406](rust-lang/cc-rs#1406))
- Always read from all `CFLAGS`-style flags ([rust-lang#1401](rust-lang/cc-rs#1401))
- Simplify the error output on failed `Command` invocation ([rust-lang#1397](rust-lang/cc-rs#1397))

##### [1.2.14](rust-lang/cc-rs@cc-v1.2.13...cc-v1.2.14) - 2025-02-14

###### Other

- Regenerate target info ([rust-lang#1398](rust-lang/cc-rs#1398))
- Add support for setting `-gdwarf-{version}` based on RUSTFLAGS ([rust-lang#1395](rust-lang/cc-rs#1395))
- Add support for alternative network stack io-sock on QNX 7.1 aarch64 and x86_64 ([rust-lang#1312](rust-lang/cc-rs#1312))

</details>

r? `@Kobzol`
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