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

[windows][toolchain] Build sanitizers and builtins standalone for all SDKs #78861

Conversation

weliveindetail
Copy link
Member

Unified build of compiler-rt together with LLVM failed for the Android SDKs. It got too complicated to redirect the way LLVM would configure the nested build-trees. Standalone builds slightly increase build time, but they turned out much simpler and we end up with less duplication of definitions.

Copy link
Member Author

@weliveindetail weliveindetail left a comment

Choose a reason for hiding this comment

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

Two minor notes

utils/build.ps1 Outdated
function Build-Sanitizers([Platform]$Platform, $Arch) {
$BareTarget = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
$LLVMDir = "$(Get-TargetProjectBinaryCache $Arch LLVM)\lib\cmake\llvm"
$InstallTo = "$($HostArch.ToolchainInstallRoot)\usr\lib\clang\19"
Copy link
Member Author

Choose a reason for hiding this comment

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

Can we keep it like that? I can probably get it from running stage-1 Clang, or lit

Copy link
Member

Choose a reason for hiding this comment

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

I think that we should extract this from the build, the resource dir changes on each rebranch, and this will complicate things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, done. I think asking llvm-config would usually be the right way, but for cross-compiles we cannot execute it. We are asking llvm-lit.py now. Seems more reliable than parsing a CMake config file or a header somewhere in the build-tree.

COMPILER_RT_BUILD_ORC = "NO";
COMPILER_RT_BUILD_XRAY = "NO";
COMPILER_RT_BUILD_PROFILE = "YES";
COMPILER_RT_BUILD_SANITIZERS = "YES";
Copy link
Member Author

Choose a reason for hiding this comment

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

I could put this into a CMake cache file, but it won't get much simpler

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I can see why it would not simplify much, but, it does make it more obvious that this is static configuration and not logic when you need a last second change to the build.

Copy link
Member Author

Choose a reason for hiding this comment

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

OTOH the structure in https://github.com/swiftlang/swift/tree/main/cmake/caches forces us to add 7 new files. And they all have identical content. (Unless we outsource CMAKE_SYSTEM_NAME, but it won't make that much of a difference.) I guess it should be: LLVM-$Platform-$($Arch.LLVMName).cmake

Copy link
Member Author

Choose a reason for hiding this comment

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

Could look like this for the two arches I am testing right now: weliveindetail@windows-toolchain-sanitizers-standalone-with-caches

Not sure. Or should I break the scheme and make just one?

@weliveindetail
Copy link
Member Author

@swift-ci Please test Windows

utils/build.ps1 Outdated
@@ -1606,6 +1608,52 @@ function Build-LLVM([Platform]$Platform, $Arch) {
}
}

function Build-Sanitizers([Platform]$Platform, $Arch) {
$BareTarget = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
Copy link
Member

Choose a reason for hiding this comment

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

I believe that @andrurogerz is working on creating a ModuleTriple parameter in the architecture definition to help with this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh good, yeah this difference is nifty. The unified build used to pass it via LLVM_RUNTIMES_TARGET
here, but in the standalone build CMake reports it as unused. Will drop it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

utils/build.ps1 Outdated
@@ -1606,6 +1608,52 @@ function Build-LLVM([Platform]$Platform, $Arch) {
}
}

function Build-Sanitizers([Platform]$Platform, $Arch) {
$BareTarget = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
$LLVMDir = "$(Get-TargetProjectBinaryCache $Arch LLVM)\lib\cmake\llvm"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be target? What happens if we don't have a target build of LLVM? (e.g. Android)

Copy link
Member Author

Choose a reason for hiding this comment

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

This came up as a warning during configuration. In many cases standalone builds reach out to LLVM for configuration details or test dependencies. That should work because we do configure LLVM for Android targets. Let me double-check that.

Copy link
Member Author

Choose a reason for hiding this comment

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

utils/build.ps1 Outdated
function Build-Sanitizers([Platform]$Platform, $Arch) {
$BareTarget = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
$LLVMDir = "$(Get-TargetProjectBinaryCache $Arch LLVM)\lib\cmake\llvm"
$InstallTo = "$($HostArch.ToolchainInstallRoot)\usr\lib\clang\19"
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should extract this from the build, the resource dir changes on each rebranch, and this will complicate things.

utils/build.ps1 Outdated
-UseBuiltCompilers C,CXX `
-BuildTargets "install-compiler-rt" `
-Defines (@{
CMAKE_MT = "mt";
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, it's not. Dropped.

utils/build.ps1 Outdated
-UseBuiltCompilers C,CXX `
-BuildTargets "install-compiler-rt" `
-Defines (@{
CMAKE_MT = "mt";
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Dropped as well

COMPILER_RT_BUILD_ORC = "NO";
COMPILER_RT_BUILD_XRAY = "NO";
COMPILER_RT_BUILD_PROFILE = "YES";
COMPILER_RT_BUILD_SANITIZERS = "YES";
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I can see why it would not simplify much, but, it does make it more obvious that this is static configuration and not logic when you need a last second change to the build.

@weliveindetail
Copy link
Member Author

@swift-ci Please smoke test

@weliveindetail
Copy link
Member Author

Build failure were unrelated

@swift-ci Please smoke test

@weliveindetail
Copy link
Member Author

This should be ready to land once I reverted the temporary change that enabled Android x86_64 in CI. Configure & build took less than 1min per target. We can keep it enabled for all SDKs and shouldn't need a switch for opt-out.

@@ -1599,13 +1601,61 @@ function Build-LLVM([Platform]$Platform, $Arch) {
-Bin (Get-TargetProjectBinaryCache $Arch LLVM) `
-Arch $Arch `
-Platform $Platform `
-UseMSVCCompilers C,CXX `
-UseBuiltCompilers C,CXX `
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not strictly related, but I think it's fine to land with this PR.

@weliveindetail
Copy link
Member Author

@swift-ci Please smoke test

@weliveindetail
Copy link
Member Author

The cross-build for Windows arm64 failed with:

FAILED: lib/aarch64-unknown-windows-msvc/clang_rt.builtins.lib 
C:\Windows\system32\cmd.exe /C "cd . && T:\5\bin\llvm-lib.exe /nologo /machine:ARM64 /out:lib\aarch64-unknown-windows-msvc\clang_rt.builtins.lib @CMakeFiles\clang_rt.builtins-aarch64.rsp && cd ."
CMakeFiles\clang_rt.builtins-aarch64.dir\outline_atomic_helpers.dir\outline_atomic_cas1_1.S.obj: file machine type x64 conflicts with library machine type arm64 (from '/machine:ARM64' flag)

ninja: build stopped: subcommand failed.
Error: Error: cmake.exe exited with code 1.
Invocation:
  cmake.exe --build T:\306 --target install-compiler-rt

The build step is generated here in CMake and there was a recent change (downstream in swiftlang LLVM) to skip it with MSVC: swiftlang/llvm-project@95a1047

I can reproduce the failure locally and keep investigating.

@weliveindetail
Copy link
Member Author

@swift-ci Please smoke test

@weliveindetail weliveindetail merged commit 76243a2 into swiftlang:main Jan 28, 2025
3 checks passed
@weliveindetail weliveindetail deleted the windows-toolchain-sanitizers-standalone branch January 28, 2025 21:08
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