Skip to content

Conversation

@SimplyDanny
Copy link
Contributor

@SimplyDanny SimplyDanny commented Dec 4, 2025

This option appears to be unsupported in clang (now). Builds fail with clang-cl.

FYI: @compnerd

Edit: The option doesn't need to be removed, but the syntax needs to be different. It works with a single argument instead of two separate ones.

@keith
Copy link
Member

keith commented Dec 4, 2025

seems like in upstream clang it was removed in llvm/llvm-project@0628bea and never added back 🤔

@compnerd
Copy link
Contributor

compnerd commented Dec 4, 2025

Pretty sure that this option is not unsupported by clang, but it is not part of llvm.org clang and requires the swift.org clang

@keith
Copy link
Member

keith commented Dec 4, 2025

checking that now

@keith
Copy link
Member

keith commented Dec 4, 2025

ok yea added back in apple only swiftlang/llvm-project@3948c4c

@compnerd
Copy link
Contributor

compnerd commented Dec 4, 2025

One thing to consider: it is generally no longer needed on Windows if you have a relatively newer toolchain. Do we want to drop this now simply because we can assume that anyone using the bazel rules_swift will be on a new enough toolchain (i.e. Swift 6+)?

@SimplyDanny
Copy link
Contributor Author

ok yea added back in apple only swiftlang/llvm-project@3948c4c

So does that mean I need to point Bazel to the Clang toolchain that comes bundled with Swift?

@compnerd
Copy link
Contributor

compnerd commented Dec 5, 2025

So does that mean I need to point Bazel to the Clang toolchain that comes bundled with Swift?

Yes, the Swift clang toolchain is not a stock clang, it has extensions whihc are required for Swift to function. You should be pointing bazel to the bundled clang.

@SimplyDanny
Copy link
Contributor Author

So does that mean I need to point Bazel to the Clang toolchain that comes bundled with Swift?

Yes, the Swift clang toolchain is not a stock clang, it has extensions whihc are required for Swift to function. You should be pointing bazel to the bundled clang.

Could rules_swift do that on its own by default?

@keith
Copy link
Member

keith commented Dec 5, 2025

that is the intent behind the forced --repo_env=CC=clang thing, that might not be enough if you have multiple clangs installed though

@SimplyDanny
Copy link
Contributor Author

Trying with

build:windows \
  --repo_env=BAZEL_LLVM=C:/Software/swift/Toolchains/6.2.1+Asserts/usr \
  --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl \
  --extra_execution_platforms=//:x64_windows-clang-cl

and

platform(
    name = "x64_windows-clang-cl",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:windows",
        "@bazel_tools//tools/cpp:clang-cl",
    ],
)

I get the error

ERROR: C:/users/****/_bazel_msd1lo/ituthjzq/external/rules_swift~/tools/worker/BUILD:34:11: Compiling tools/worker/compile_without_worker.cc [for tool] failed: (Exit -2147483645): clang-cl.exe failed: error executing CppCompile command (from target @@rules_swift~//tools/worker:compile_without_worker) C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe ... (remaining 1 argument skipped)
Assertion failed: Index >= End && "Unexpected parser error.", file C:\Users\swift-ci\jenkins\workspace\swift-6.2-windows-toolchain\llvm-project\llvm\lib\Option\OptTable.cpp, line 559
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: C:\\Software\\swift\\Toolchains\\6.2.1+Asserts\\usr\\bin\\clang-cl.exe @bazel-out/x64_windows-opt-exec-ST-d610928244b0/bin/external/rules_swift~/tools/worker/_objs/compile_without_worker/compile_without_worker.obj.params
Exception Code: 0x80000003
 #0 0x00007ff7ce355795 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0x1725795)
 #1 0x00007ff9f4f6e6d5 (C:\WINDOWS\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9f4f6f6e1 (C:\WINDOWS\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff9f4f7108e (C:\WINDOWS\System32\ucrtbase.dll+0x8108e)
 #4 0x00007ff9f4f712d1 (C:\WINDOWS\System32\ucrtbase.dll+0x812d1)
 #5 0x00007ff7ce22195c (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0x15f195c)
 #6 0x00007ff7ce21fbf2 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0x15efbf2)
 #7 0x00007ff7cedeaff8 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0x21baff8)
 #8 0x00007ff7cccd1121 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0xa1121)
 #9 0x00007ff7ccce53f6 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0xb53f6)
#10 0x00007ff7d17cb514 (C:\Software\swift\Toolchains\6.2.1+Asserts\usr\bin\clang-cl.exe+0x4b9b514)
#11 0x00007ff9f627259d (C:\WINDOWS\System32\KERNEL32.DLL+0x1259d)
#12 0x00007ff9f750af78 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x5af78)

@keith
Copy link
Member

keith commented Dec 5, 2025

i believe this failure is compiler params files not being properly formatted. you can try with --features=-compiler_param_file --host_features=-compiler_param_file

@SimplyDanny
Copy link
Contributor Author

SimplyDanny commented Dec 5, 2025

i believe this failure is compiler params files not being properly formatted. you can try with --features=-compiler_param_file --host_features=-compiler_param_file

With --host_features=-compiler_param_file it compiles without the "fix" in this PR, but fails linking. --features=-archive_param_file makes that work, too, since --feature=windows_quoting_for_param_files (which actually sounds promising) doesn't seem to have any effect.

I'm trying to build https://github.com/apple/swift-argument-parser by the way.

@SimplyDanny SimplyDanny changed the title Remove unsupported -fno-split-cold-code clang option Fix syntax of arguments passed on to Clang Dec 8, 2025
@keith keith merged commit 16b95b3 into bazelbuild:main Dec 8, 2025
13 checks passed
@SimplyDanny
Copy link
Contributor Author

FYI: I draftet a PR for LLVM with llvm/llvm-project#171214 to make the argument parsing process less sensitive to such subtleties.

@keith: Thanks for merging! Next would be archive_param_file which doesn't quote paths containing spaces properly. Any idea why windows_quoting_for_param_files wouldn't work?

I wonder if this needs fixing in LLVM as well, though.

@SimplyDanny SimplyDanny deleted the no-cold-code-split branch December 8, 2025 22:24
@keith
Copy link
Member

keith commented Dec 8, 2025

i think that's probably a bug somewhere on the bazel side. looks to me like https://github.com/bazelbuild/rules_cc/blob/a2994c414fafa1acdc2f461edda85d67841f88ec/cc/private/toolchain/windows_cc_toolchain_config.bzl needs to define the windows_quoting_for_param_files feature in order for it to ever be considered enabled:

https://github.com/bazelbuild/rules_cc/blob/a2994c414fafa1acdc2f461edda85d67841f88ec/cc/private/link/finalize_link_action.bzl#L340

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