Skip to content

CMake: option to disable swift in swift #79778

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 58 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,24 @@ option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
debugging Swift)"
FALSE)

set(BOOTSTRAPPING_MODE HOSTTOOLS CACHE STRING [=[
How to build the swift compiler modules. Possible values are
HOSTTOOLS: build with a pre-installed toolchain
BOOTSTRAPPING: build with a 2-stage bootstrapping process
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
but the compiler links against the host system swift libs (macOS only)
CROSSCOMPILE: cross-compiledwith a native host compiler, provided in
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
]=])
option(SWIFT_ENABLE_SWIFT_IN_SWIFT "Enable Swift sources in Swift compiler" ON)

if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
set(BOOTSTRAPPING_MODE HOSTTOOLS CACHE STRING [=[
How to build the swift compiler modules. Possible values are
HOSTTOOLS: build with a pre-installed toolchain
BOOTSTRAPPING: build with a 2-stage bootstrapping process
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
but the compiler links against the host system swift libs (macOS only)
CROSSCOMPILE: cross-compiledwith a native host compiler, provided in
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
]=])
else()
set(BOOTSTRAPPING_MODE OFF)
set(SWIFT_BUILD_SWIFT_SYNTAX OFF)
endif()

option(BRIDGING_MODE [=[
How swift-C++ bridging code is compiled:
Expand Down Expand Up @@ -939,41 +946,44 @@ set(SWIFT_MAIN_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/include")
set(SWIFT_SHIMS_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims")
set(SWIFT_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")

if (NOT BOOTSTRAPPING_MODE)
if (NOT BOOTSTRAPPING_MODE AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
message(FATAL_ERROR "turning off bootstrapping is not supported anymore")
endif()

set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
# This is the normal case. We are not cross-compiling.
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined")
set(BOOTSTRAPPING_MODE "OFF")
endif()
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
# If cross-compiling, we don't have to bootstrap. We can just use the previously
# built native swiftc to build the swift compiler modules.
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
else()
set(BOOTSTRAPPING_MODE "HOSTTOOLS")

if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
if(NOT SWIFT_NATIVE_SWIFT_TOOLS_PATH)
# This is the normal case. We are not cross-compiling.
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined")
set(BOOTSTRAPPING_MODE "OFF")
endif()
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
# If cross-compiling, we don't have to bootstrap. We can just use the previously
# built native swiftc to build the swift compiler modules.
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
else()
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
endif()
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
# We are building using a pre-installed host toolchain but not bootstrapping
# the Swift modules. This happens when building using 'build-tooling-libs'
# where we haven't built a new Swift compiler. Use the Swift compiler from the
# pre-installed host toolchain to build the Swift modules.
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
endif()
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
# We are building using a pre-installed host toolchain but not bootstrapping
# the Swift modules. This happens when building using 'build-tooling-libs'
# where we haven't built a new Swift compiler. Use the Swift compiler from the
# pre-installed host toolchain to build the Swift modules.
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
endif()

if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX)
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
# Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
Expand Down Expand Up @@ -1530,14 +1540,16 @@ if(SWIFT_INCLUDE_TOOLS)
# https://github.com/apple/swift/issues/48534
add_subdirectory(tools)

# Localization targets are configured in a way that assume the swift
# frontend is being built, so trying to include them for other builds
# (like stdlib) fail!
#
# Diagnostics information is only useful for the frontend compiler
# anyway, so let's only include it if the compiler is being built,
# which at the moment seems like if SWIFT_INCLUDE_TOOLS is defined.
add_subdirectory(localization)
if(SWIFT_NATIVE_SWIFT_TOOLS_PATH)
# Localization targets are configured in a way that assume the swift
# frontend is being built, so trying to include them for other builds
# (like stdlib) fail!
#
# Diagnostics information is only useful for the frontend compiler
# anyway, so let's only include it if the compiler is being built,
# which at the moment seems like if SWIFT_INCLUDE_TOOLS is defined.
add_subdirectory(localization)
endif()
endif()

add_subdirectory(utils)
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ASTScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void ASTScope::unqualifiedLookup(
if (auto *s = SF->getASTContext().Stats)
++s->getFrontendCounters().NumASTScopeLookups;

#if SWIFT_BUILD_SWIFT_SYNTAX
// Perform validation of SwiftLexicalLookup if option
// Feature::UnqualifiedLookupValidation is enabled and lookup was not
// performed in a macro.
Expand All @@ -171,6 +172,9 @@ void ASTScope::unqualifiedLookup(
} else {
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
}
#else
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
#endif
}

llvm::SmallVector<LabeledStmt *, 4> ASTScope::lookupLabeledStmts(
Expand Down
14 changes: 14 additions & 0 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,20 @@ ParserResult<Expr> Parser::parseExprMacroExpansion(bool isExprBasic) {
if (!macroNameRef)
return status;

#if !SWIFT_BUILD_SWIFT_SYNTAX
// If we don't have swift-syntax and therefore have no support for macros,
// recognize #isolation as special and route it through
// CurrentContextIsolationExpr.
if (macroNameRef.getBaseName().userFacingName() == "isolation" &&
genericArgs.empty() &&
(!argList || argList->empty())) {
return makeParserResult(
status,
new (Context) CurrentContextIsolationExpr(
macroNameLoc.getStartLoc(), Type()));
}
#endif

return makeParserResult(
status,
MacroExpansionExpr::create(
Expand Down
4 changes: 4 additions & 0 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ std::pair<bool, bool> EvaluateIfConditionRequest::evaluate(
Evaluator &evaluator, SourceFile *sourceFile, SourceRange conditionRange,
bool shouldEvaluate
) const {
#if SWIFT_BUILD_SWIFT_SYNTAX
// FIXME: When we migrate to SwiftParser, use the parsed syntax tree.
ASTContext &ctx = sourceFile->getASTContext();
auto &sourceMgr = ctx.SourceMgr;
Expand All @@ -775,4 +776,7 @@ std::pair<bool, bool> EvaluateIfConditionRequest::evaluate(
bool isActive = (evalResult & 0x01) != 0;
bool allowSyntaxErrors = (evalResult & 0x02) != 0;
return std::pair(isActive, allowSyntaxErrors);
#else
llvm_unreachable("Must not be used in C++-only build");
#endif
}
13 changes: 10 additions & 3 deletions stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,12 @@ function(_compile_swift_files
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(HOST_EXECUTABLE_SUFFIX .exe)
endif()
if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
if(NOT SWIFT_ENABLE_SWIFT_IN_SWIFT)
# This is only for bootstrapping purposes. The just-built Swift is very
# limited and only built for the builder to build the next stages with
# hosttools.
set(swift_compiler_tool "${Swift_BINARY_DIR}/bin/swiftc")
elseif(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
if(SWIFT_PREBUILT_SWIFT)
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
elseif(CMAKE_Swift_COMPILER)
Expand Down Expand Up @@ -886,8 +891,10 @@ function(_compile_swift_files
# cross-compiling the compiler.
list(APPEND swift_compiler_tool_dep "swift-frontend${target_suffix}")

# If we aren't cross compiling, also depend on SwiftMacros.
list(APPEND swift_compiler_tool_dep SwiftMacros)
if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
# If we aren't cross compiling, also depend on SwiftMacros.
list(APPEND swift_compiler_tool_dep SwiftMacros)
endif()
endif()

# If there are more than one output files, we assume that they are specified
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/core/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public func _stdlib_isOSVersionAtLeast(
@_semantics("availability.osversion")
@_effects(readnone)
@_unavailableInEmbedded
#if hasFeature(Macros)
@_noLocks
#endif
public func _stdlib_isOSVersionAtLeast(
_ major: Builtin.Word,
_ minor: Builtin.Word,
Expand All @@ -65,7 +67,9 @@ public func _stdlib_isOSVersionAtLeast(
@_semantics("availability.osversion")
@_effects(readnone)
@_alwaysEmitIntoClient
#if hasFeature(Macros)
@_noLocks
#endif
public func _stdlib_isOSVersionAtLeast_AEIC(
_ major: Builtin.Word,
_ minor: Builtin.Word,
Expand Down Expand Up @@ -110,7 +114,9 @@ public func _stdlib_isOSVersionAtLeast_AEIC(
@_semantics("availability.osversion")
@_effects(readnone)
@available(macOS 10.15, iOS 13.0, *)
#if hasFeature(Macros)
@_noLocks
#endif
public func _stdlib_isVariantOSVersionAtLeast(
_ major: Builtin.Word,
_ minor: Builtin.Word,
Expand Down Expand Up @@ -153,7 +159,9 @@ public func _stdlib_isVariantOSVersionAtLeast(
@_semantics("availability.osversion")
@_effects(readnone)
@_unavailableInEmbedded
#if hasFeature(Macros)
@_noLocks
#endif
public func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(
_ major: Builtin.Word,
_ minor: Builtin.Word,
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/CollectionAlgorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ extension MutableCollection where Self: BidirectionalCollection {
swapAt(lo, hi)
formIndex(after: &lo)
}
fatalError()
}
}

Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Flatten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ extension FlattenSequence.Iterator: IteratorProtocol {
_inner = s!.makeIterator()
}
while true
fatalError()
}
}

Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/HashTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ extension _HashTable {
return unsafe Bucket(word: word, bit: bit)
}
}
fatalError()
}

@inlinable
Expand Down Expand Up @@ -414,6 +415,7 @@ extension _HashTable {
return unsafe Bucket(word: word, bit: bit)
}
}
fatalError()
}
}

Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ extension JoinedSequence.Iterator: IteratorProtocol {
return nil
}
}
fatalError()
}
}

Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/KeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public class AnyKeyPath: _AppendKeyPath {

if optNextType == nil { return .some(offset) }
}
fatalError()
}
#else
// compiler optimizes _storedInlineOffset into a direct offset computation,
Expand Down Expand Up @@ -271,6 +272,7 @@ extension AnyKeyPath: Hashable {
return true
}
}
fatalError()
}
}
}
Expand Down Expand Up @@ -432,6 +434,7 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
}
}
}
fatalError()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

#if !$Embedded
#if !$Embedded && hasFeature(Macros)
@DebugDescription
extension ObjectIdentifier {
var lldbDescription: String {
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/SequenceAlgorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ extension Sequence {
case (nil, nil): return true
}
}
fatalError()
}
}

Expand Down Expand Up @@ -425,6 +426,7 @@ extension Sequence {
return false
}
}
fatalError()
}
}

Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/StringBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ extension StringProtocol {

public // SPI(Foundation)
func _toUTF16Indices(_ range: Range<Int>) -> Range<Index> {
#if hasFeature(Macros)
if Self.self == String.self {
let s = unsafe unsafeBitCast(self, to: String.self)
return s.utf16._indexRange(for: range, from: s.startIndex)
Expand All @@ -760,6 +761,7 @@ extension StringProtocol {
let s = unsafe unsafeBitCast(self, to: Substring.self)
return s._slice._base.utf16._indexRange(for: range, from: s.startIndex)
}
#endif
let lowerbound = _toUTF16Index(range.lowerBound)
let upperbound = _toUTF16Index(range.upperBound)
return unsafe Range(uncheckedBounds: (lower: lowerbound, upper: upperbound))
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/StringComparison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private func _findBoundary(

unsafe idx &-= _utf8ScalarLength(utf8, endingAt: idx)
}
fatalError()
}

@frozen
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/StringUTF16View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ extension String.UTF16View {

readIdx &+= len
}
fatalError()
}
}

Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/SwiftifyImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public enum _SwiftifyInfo {
///
/// Parameter paramInfo: information about how the function uses the pointer passed to it. The
/// safety of the generated wrapper function depends on this info being extensive and accurate.
#if hasFeature(Macros)
@attached(peer, names: overloaded)
public macro _SwiftifyImport(_ paramInfo: _SwiftifyInfo..., typeMappings: [String: String] = [:]) =
#externalMacro(module: "SwiftMacros", type: "SwiftifyImportMacro")
#endif
1 change: 1 addition & 0 deletions stdlib/public/core/UTF16.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ extension Unicode.UTF16 {
return (utf16Count, utf16BitUnion < 0x80)
}
}
fatalError()
}
}

Expand Down
Loading