Skip to content

Previews break with explicit modules enabled <rdar://146184835> #259

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 1 commit into from
Mar 6, 2025
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
60 changes: 30 additions & 30 deletions Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3241,42 +3241,42 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
// Preview thunks does not need this
"-emit-objc-header",

// Stripping for completeness, but XOJIT Previews are already forced as `-Onone`.
// We add back `-Onone` below.
// Previews only work on unoptimized build products.
"-O",
"-Onone",
"-Osize",

// _Very_ deprecated, but continuing to strip for backwards compatibility
"-embed-bitcode",
"-embed-bitcode-marker",

// Stripped for historical reasons. Previews can add it back if it needs debugging information.
"-g",
"-dwarf-version=4",
"-dwarf-version=5",

// Previews does not use compiler output
"-parseable-output",
"-use-frontend-parseable-output",

// Writes more intermediates that Previews does not need
"-emit-const-values",
"-save-temps",

"-explicit-module-build",

// Strip until builder SDKs include a swift-driver with this flag. Do not remove without also removing -clang-build-session-file.
"-validate-clang-modules-once"
] {
while let index = commandLine.firstIndex(of: arg) {
commandLine.remove(at: index)
}
}
if payload.previewStyle == .dynamicReplacement {
for arg in [
// Debug symbols aren't needed in dynamic replacement preview info.
"-g",

// We add back `-Onone` below in dynamic replacement.
"-Onone",

// Dynamic replacement thunks don't need this.
"-import-underlying-module",

// This property was always stripped in dynamic replacement.
"-explicit-module-build",

// Strip until builder SDKs include a swift-driver with this flag. Do not remove without also removing -clang-build-session-file.
"-validate-clang-modules-once"
] {
while let index = commandLine.firstIndex(of: arg) {
commandLine.remove(at: index)
Expand Down Expand Up @@ -3334,17 +3334,17 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
removeWithPrefix("-cache-compile-job")
commandLine.append("-disable-bridging-pch")

for (arg, newValue) in [
// Previews needs a path to _a_ module cache so it has a place to store built modules.
("-module-cache-path", previewPayload.moduleCacheDir.str)
] {
removeWithParameter(arg)
if !newValue.isEmpty {
commandLine += [arg, newValue]
if payload.previewStyle == .dynamicReplacement {
for (arg, newValue) in [
// Previews needs a path to _a_ module cache so it has a place to store built modules.
("-module-cache-path", previewPayload.moduleCacheDir.str)
] {
removeWithParameter(arg)
if !newValue.isEmpty {
commandLine += [arg, newValue]
}
}
}

if payload.previewStyle == .dynamicReplacement {
for arg in [
// We want the objc header in XOJIT mode so ignore in dynamic replacement mode
"-import-objc-header",
Expand Down Expand Up @@ -3414,16 +3414,16 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
"\(payload.moduleName)_PreviewReplacement_\(sourceFile.basenameWithoutSuffix)_\(thunkVariantSuffix)".mangledToC99ExtendedIdentifier(),
])
commandLine.append("-parse-as-library")
}

// Faster thunk builds
commandLine.append("-Onone")
// Faster thunk builds
commandLine.append("-Onone")

// Faster thunk builds
commandLine.append(contentsOf: [
"-Xfrontend",
"-disable-modules-validate-system-headers",
])
// Faster thunk builds
commandLine.append(contentsOf: [
"-Xfrontend",
"-disable-modules-validate-system-headers",
])
}

// For XOJIT previews, we want the frontend (`swift-frontend`) invocation rather than the driver (`swiftc`) invocation, so ask libSwiftDriver for it and replace the command line with the result for propagation back to the request.
if let driverPayload = payload.driverPayload, payload.previewStyle == .xojit {
Expand Down
Loading