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

CMake: option to disable swift in swift #79778

Merged

Conversation

etcwilde
Copy link
Contributor

@etcwilde etcwilde commented Mar 5, 2025

Adding SWIFT_ENABLE_SWIFT_IN_SWIFT option to enable or disable the parts of Swift that require a Swift compiler to build. This is meant for bootstrapping compilers on new platforms and is not guaranteed to result in a compiler that will pass the test suite.

This option is on by default so that folks won't forget. If the option is off, the resulting compiler does not include the Swift optimizer sources in SwiftCompilerSources nor does the resulting compiler have swift macro support.

@etcwilde etcwilde requested a review from a team as a code owner March 5, 2025 00:10
@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 5, 2025

This will require the compiler and stdlib-side changes in #77815
Without them, we have several build failures due to missing symbols:

/sources/swift/lib/AST/ASTScope.cpp:162: error: undefined reference to 'swift_ASTGen_validateUnqualifiedLookup'                              
/sources/swift/lib/Sema/TypeChecker.cpp:771: error: undefined reference to 'swift_ASTGen_evaluatePoundIfCondition'                           
/sources/swift/include/swift/Basic/BasicBridgingImpl.h:149: error: undefined reference to 'swift_ASTGen_bridgedSwiftClosureCall_1'

@etcwilde etcwilde force-pushed the ewilde/yo-dawg-heard-you-liked-swift branch from e044d9b to cc066eb Compare March 5, 2025 05:42
@etcwilde etcwilde requested a review from compnerd March 5, 2025 16:33
@etcwilde etcwilde force-pushed the ewilde/yo-dawg-heard-you-liked-swift branch from cc066eb to 318c963 Compare March 5, 2025 23:48
@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 5, 2025

This patch is enough to bring up a stage-0 compiler without macro support using the C++ Swift driver without Swift on the platform.

Verified with on Ubuntu 24.04 without a pre-installed Swift:

./sources/swift/utils/build-script \
  --skip-test-cmark \
  --skip-test-lldb \
  --skip-test-swift \
  --skip-test-llbuild \
  --skip-test-swiftpm \
  --skip-test-swift-driver \
  --skip-test-xctest \
  --skip-test-foundation \
  --skip-test-libdispatch \
  --skip-test-playgroundsupport \
  --skip-test-indexstore-db \
  --skip-test-sourcekit-lsp \
  --skip-test-swiftdocc \
  --skip-test-wasm-stdlib \
  --skip-test-swiftformat \
  --swift-include-tests=0 \
  --llvm-include-tests=0 \
  --release \
  --skip-early-swiftsyntax \
  --skip-early-swift-driver \
  --skip-build-benchmarks \
  --build-runtime-with-host-compiler=0 \
  --build-swift-libexec=0 \
  --build-swift-remote-mirror=0 \
  '--swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;toolchain-tools;license' \
  '--llvm-install-components=llvm-ar;llvm-ranlib;clang;clang-resource-headers;compiler-rt;clang-features-file' \
  '--extra-cmake-options=-DLLVM_TARGETS_TO_BUILD=X86;AArch64' \
  '--swift-cmake-options=-DSWIFT_ENABLE_SWIFT_IN_SWIFT:BOOL=NO -DSWIFT_INCLUDE_DOCS:BOOL=NO' \
  --build-subdir=stage0 \
  --install-destdir=/staging/stage0 \
  --install-llvm \
  --install-swift

The resulting compiler is able to build the standard library and a simple "hello world" program.

@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 5, 2025

@swift-ci please test

@etcwilde etcwilde force-pushed the ewilde/yo-dawg-heard-you-liked-swift branch from 318c963 to 4353c83 Compare March 6, 2025 17:50
@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 6, 2025

@swift-ci please test

@3405691582
Copy link
Member

3405691582 commented Mar 6, 2025

FYI: when building Swift with a recent bootstrap compiler, I've noticed the following error:

Begin Error in Function: '$s11swiftASTGen0B7VisitorV22generateDeclAttributes_11allowStaticAC0eF6ResultVx_Sbt20_CompilerSwiftSyntax04WithfL0RzAH0m9ModifiersL0RzlF'
Error! Found a leak due to a consuming post-dominance failure!
Value:   %255 = begin_borrow [lexical] %6 : ${ var BridgedDeclAttributes } // users: %309, %259                                                                 
Post Dominating Failure Blocks:
 bb32
End Error in Function: '$s11swiftASTGen0B7VisitorV22generateDeclAttributes_11allowStaticAC0eF6ResultVx_Sbt20_CompilerSwiftSyntax04WithfL0RzAH0m9ModifiersL0RzlF'
Found ownership error?! 

Bisecting leads to commit 008e10c and reverting this is a workaround for the problem. I haven't investigated or tested further than this, but a heads-up in case you run in to the same issue.

@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 6, 2025

yeah, I've seen that as well. Thanks for bisecting it.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Thank you for picking this up! Just the one question from me

etcwilde and others added 3 commits March 6, 2025 13:32

Verified

This commit was signed with the committer’s verified signature.
etcwilde Evan Wilde
Adding `SWIFT_ENABLE_SWIFT_IN_SWIFT` option to enable or disable the
parts of Swift that require a Swift compiler to build. This is meant for
bootstrapping compilers on new platforms and is not guaranteed to result
in a compiler that will pass the test suite.

This option is on by default so that folks won't forget.
If the option is off, the resulting compiler does not include the Swift
optimizer sources in SwiftCompilerSources nor does the resulting
compiler have swift macro support.

Verified

This commit was signed with the committer’s verified signature.
etcwilde Evan Wilde
Remove dependency on macros from compiler and stdlib build when
bootstrapping the compiler without Swift available.

Verified

This commit was signed with the committer’s verified signature.
etcwilde Evan Wilde
PR 79186 (swiftlang#79186) moved one of
the mandatory passes from the C++ implementation to the Swift
implementation resulting in a compiler that is unable to build the
standard library. The pass used to ensure that inaccessible control-flow
positions after an infinite loop was marked with `unreachable` in SIL.
Since the pass is no longer running, any function that returns a value
that also has an infinite loop internally must place a fatalError after
the infinite loop or it will fail to compile as the compiler will
determine that the function does not return from all control flow paths
even though some of the paths are unreachable.
@etcwilde etcwilde force-pushed the ewilde/yo-dawg-heard-you-liked-swift branch from 4353c83 to ddaf003 Compare March 6, 2025 21:33
@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 6, 2025

@swift-ci please test

@etcwilde
Copy link
Contributor Author

etcwilde commented Mar 7, 2025

@swift-ci please test Linux

@etcwilde etcwilde merged commit 28f9641 into swiftlang:main Mar 7, 2025
5 checks passed
@etcwilde etcwilde deleted the ewilde/yo-dawg-heard-you-liked-swift branch March 13, 2025 17:01
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

4 participants