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

Enable SwiftCompilerSources on Windows #73247

Merged
merged 6 commits into from Apr 30, 2024

Conversation

eeckstein
Copy link
Member

With some hacks and workarounds I could get SwiftCompilerSources working on my local Windows machine.
To-do: also enable it in lldb (see my comment in the top-level CMakeLists file).

@eeckstein eeckstein marked this pull request as draft April 25, 2024 09:19
@eeckstein
Copy link
Member Author

@swift-ci test windows

@eeckstein eeckstein requested a review from atrick April 25, 2024 09:21
CMakeLists.txt Outdated
Comment on lines 733 to 736
# A tempoarary hack: force enabling HOSTTOOLS mode on Windows.
# Right now, SwiftCompilerSources cannot be enabled for lldb because the
# Windows build script builds lldb before swift and that fails with a missing
# dependency on swiftrt (which is built within swift).
Copy link
Collaborator

Choose a reason for hiding this comment

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

lldb is not built before swift, it is built alongside as a single unified build. This implies that there is a missing dependency in the LLDB build definition.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for clarifying. I updated the comment (We can fix the underlying problem in a follow-up PR).

SwiftCompilerSources/CMakeLists.txt Outdated Show resolved Hide resolved
@@ -106,6 +106,13 @@ function(add_swift_compiler_modules_library name)
"-Xcc" "-std=c++17"
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND swift_compile_options "-static")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Statically linking the standard library is not supported - how do we ensure that this is not applied to it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I thought that -static means that the currently built module is statically linked. The option is applied to the SwiftCompilerSources modules (and not to the stdlib).
Anyway, without this option it doesn't work and with this option it works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, okay, this flag is only applied to SwiftCompilerSources? If so, that should be fine. I just wanted to ensure that it didn't accidentally leak. You are correct that it only applies to the module that you are building.

Comment on lines 55 to 57
#if !os(Windows)
public var standardError = CFileStream(fp: stderr)
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to implement this with the Win32 + ucrt APIs to convert the stderr handle to a FILE *.

@@ -28,6 +28,9 @@ private extension ConvertEscapeToNoEscapeInst {
/// %3 = thin_to_thick_function %1 to $@noescape () -> ()

func tryCombineWithThinToThickOperand(_ context: SimplifyContext) {
// compiling bridged.getFunctionTypeWithNoEscape crashes the 5.10 Windows compiler
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this works on newer compilers, perhaps we should also include a version check?

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 still need to check if it works with newer compilers

@eeckstein
Copy link
Member Author

@swift-ci test Windows

@eeckstein
Copy link
Member Author

@swift-ci test Windows

@eeckstein
Copy link
Member Author

@swift-ci test Windows

@eeckstein
Copy link
Member Author

@swift-ci test windows

@eeckstein
Copy link
Member Author

The build is failing with

FAILED: tools/swift/SwiftCompilerSources/Basic.o T:/5/tools/swift/SwiftCompilerSources/Basic.o 
cmd.exe /C "cd /D C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\SwiftCompilerSources && T:\toolchains\swift-5.10-DEVELOPMENT-SNAPSHOT-2024-01-18-a-windows10\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -c -o T:/5/tools/swift/SwiftCompilerSources/Basic.o -resource-dir T:/toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-01-18-a-windows10/LocalApp/Programs/Swift/Platforms/0.0.0/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift -target x86_64-unknown-windows-msvc -module-name Basic -emit-module -emit-module-path T:/5/tools/swift/SwiftCompilerSources/Basic.swiftmodule -parse-as-library C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/SourceLoc.swift C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/StringParser.swift C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/Utils.swift -wmo -color-diagnostics -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-target-os-checking -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT -Xcc -DSWIFT_TARGET -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -cxx-interoperability-mode=default -O -cross-module-optimization -Xcc -UNDEBUG -Xcc -DPURE_BRIDGING_MODE -Xfrontend -disable-legacy-type-info -static -Xllvm -sil-disable-pass=loadable-address -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/llvm-project/llvm/include -Xcc -I -Xcc T:/5/include -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/llvm-project/llvm/../clang/include -Xcc -I -Xcc T:/5/tools/clang/include -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/include -Xcc -I -Xcc T:/5/tools/swift/SwiftCompilerSources/../include -I T:/5/tools/swift/SwiftCompilerSources"
<unknown>:0: error: cannot load underlying module for 'CxxStdlib'

I didn't see this problem when building locally on my machine.

@eeckstein
Copy link
Member Author

@swift-ci test Windows

@eeckstein
Copy link
Member Author

@swift-ci test Windows

@compnerd
Copy link
Collaborator

The build is failing with

FAILED: tools/swift/SwiftCompilerSources/Basic.o T:/5/tools/swift/SwiftCompilerSources/Basic.o 
cmd.exe /C "cd /D C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\SwiftCompilerSources && T:\toolchains\swift-5.10-DEVELOPMENT-SNAPSHOT-2024-01-18-a-windows10\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -c -o T:/5/tools/swift/SwiftCompilerSources/Basic.o -resource-dir T:/toolchains/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-01-18-a-windows10/LocalApp/Programs/Swift/Platforms/0.0.0/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift -target x86_64-unknown-windows-msvc -module-name Basic -emit-module -emit-module-path T:/5/tools/swift/SwiftCompilerSources/Basic.swiftmodule -parse-as-library C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/SourceLoc.swift C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/StringParser.swift C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/SwiftCompilerSources/Sources/Basic/Utils.swift -wmo -color-diagnostics -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-target-os-checking -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT -Xcc -DSWIFT_TARGET -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -cxx-interoperability-mode=default -O -cross-module-optimization -Xcc -UNDEBUG -Xcc -DPURE_BRIDGING_MODE -Xfrontend -disable-legacy-type-info -static -Xllvm -sil-disable-pass=loadable-address -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/llvm-project/llvm/include -Xcc -I -Xcc T:/5/include -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/llvm-project/llvm/../clang/include -Xcc -I -Xcc T:/5/tools/clang/include -Xcc -I -Xcc C:/Users/swift-ci/jenkins/workspace/swift-PR-windows/swift/include -Xcc -I -Xcc T:/5/tools/swift/SwiftCompilerSources/../include -I T:/5/tools/swift/SwiftCompilerSources"
<unknown>:0: error: cannot load underlying module for 'CxxStdlib'

I didn't see this problem when building locally on my machine.

This is likely another missing dependency in the build graph (CC: @etcwilde). The build is shuffled on differently on different hosts. The dependencies should be accurate to avoid these types of spurious failures.

@eeckstein
Copy link
Member Author

This is likely another missing dependency in the build graph

I already fixed it. I was using some wrong build options

@eeckstein
Copy link
Member Author

@swift-ci test

@eeckstein eeckstein marked this pull request as ready for review April 29, 2024 08:54
@ahoppen ahoppen removed their request for review April 29, 2024 16:49
@eeckstein eeckstein merged commit 74ed041 into apple:main Apr 30, 2024
5 checks passed
@eeckstein eeckstein deleted the windows-enable-swift branch April 30, 2024 07:04
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.

None yet

2 participants