Skip to content

Commit c70f28f

Browse files
authored
Merge pull request #1494 from swiftlang/automerge/merge-main-2026-06-29_10-33
Merge `release/6.4.x` into `main`
2 parents 45576d7 + 732f887 commit c70f28f

6 files changed

Lines changed: 71 additions & 137 deletions

File tree

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
714714
var previousArg: ByteString? = nil
715715
while let arg = iterator.next() {
716716
let argAsByteString = ByteString(encodingAsUTF8: arg)
717-
if arg == "-target" || arg == "-target-arch-variant" {
717+
if arg == "-target" || arg == "-target-variant" || arg == "-target-arch-variant" {
718718
// Exclude -target and similar options from the response file to make reading the build log easier.
719719
regularCommandLine.append(arg)
720720
if let nextArg = iterator.next() {
@@ -1504,10 +1504,11 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
15041504
return baseCachePath.join("SharedPrefixModuleMaps").join("\(prefixHeader.basename)-\(sharingIdentHashValue).modulemap")
15051505
}
15061506

1507-
@_spi(Testing) public static func precompiledHeaderHashIdentifier(commandLine: [String]) -> UInt64 {
1507+
@_spi(Testing) public static func sharedPrecompiledHeaderSharingIdentifier(commandLine: [String]) -> (string: String, hashValue: UInt64) {
15081508
// FIXME: The way in which we do this right now is very preliminary.
15091509
let sharingIdentString = commandLine.joined(separator: "|")
1510-
return sharingIdentString.utf8.reduce(UInt64(0)) { UInt64($0) &* 13 &+ UInt64($1) }
1510+
let sharingIdentHashValue = sharingIdentString.utf8.reduce(UInt64(0)) { UInt64($0) &* 13 &+ UInt64($1) }
1511+
return (sharingIdentString, sharingIdentHashValue)
15111512
}
15121513

15131514
/// Adds the arguments to use the prefix header, in the appropriate manner for the target.
@@ -1550,6 +1551,10 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
15501551

15511552
// Precompile the prefix header, if needed.
15521553
if cbc.scope.evaluate(BuiltinMacros.GCC_PRECOMPILE_PREFIX_HEADER) && shouldPrecompilePrefixHeader {
1554+
// First determine the name of the precomp file.
1555+
// FIXME: We need to add the hash etc to this.
1556+
let baseCachePath = cbc.scope.evaluate(BuiltinMacros.SHARED_PRECOMPS_DIR)
1557+
15531558
// Determine the command line arguments that should be included in the hash.
15541559
//
15551560
// Filter the commandline args that should not contribute to the hash.
@@ -1598,16 +1603,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
15981603
}
15991604

16001605
// Construct an identifier from the command line arguments that should contribute to making the precomp unique.
1601-
let sharingIdentHashValue = Self.precompiledHeaderHashIdentifier(commandLine: commandLineForHash)
1606+
let (sharingIdentString, sharingIdentHashValue) = Self.sharedPrecompiledHeaderSharingIdentifier(commandLine: commandLineForHash)
1607+
1608+
// Look up any existing precomp node for the identifier, or create it if it’s the first time we see it.
1609+
//
1610+
// FIXME: We need to be very careful here, we are still providing the build context for the current file, and the local scope. This means that the thing we compute here may depend on whatever target happens to produce it first, in subtle ways. We actually know this happens with the headermaps: <rdar://problem/24605739> [Swift Build] Stop sharing precompiled PCH files across targets
1611+
let (precompFile, pchInfoAny) = delegate.createOrReuseSharedNodeWithIdentifier(sharingIdentString) { () -> (any PlannedNode, any Sendable) in
1612+
// This block is invoked only when we need to create a task to precompile a header.
16021613

1603-
// Each target gets its own ProcessPCH task to avoid staleness bugs from sharing
1604-
// precompiled headers across targets (rdar://24605739, rdar://169564506, rdar://112855255).
1605-
// The hash still distinguishes different variants within the same target.
1606-
let targetTempDir = cbc.scope.evaluate(BuiltinMacros.TARGET_TEMP_DIR)
1607-
let precompPath = targetTempDir.join("PrecompiledHeaders").join("\(sharingIdentHashValue)").join(prefixHeader.basename + ".gch")
1614+
// Construct the full path of the precomp file, which includes the hash to make it unique.
1615+
// FIXME: This needs to actually include a hash code, and it should ideally (for comparison reasons) be the same as Xcode.
1616+
let precompPath = baseCachePath.join("SharedPrecompiledHeaders").join("\(sharingIdentHashValue)").join(prefixHeader.basename + ".gch")
16081617

1609-
let (precompFile, pchInfoAny) = delegate.createOrReuseSharedNodeWithIdentifier(precompPath.str) { () -> (any PlannedNode, any Sendable) in
1618+
// Start by invoking our logic to create a task to precompile the prefix header.
16101619
let pchInfo = self.precompile(cbc, delegate, headerPath: prefixHeader, language: language, inputFileType: inputFileType, extraArgs: perFileFlags, precompPath: precompPath, clangInfo: clangInfo)
1620+
1621+
// Return the output node for the precomp file.
16111622
return (delegate.createNode(precompPath), pchInfo)
16121623
}
16131624

Tests/SWBBuildSystemTests/HostBuildToolBuildOperationTests.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,24 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
249249
"PackageDepProduct",
250250
"HostToolDep",
251251
]),
252-
TestStandardTarget("HostToolClientLib", type: .objectFile, buildPhases: [
252+
TestStandardTarget("HostToolClientLib", type: .objectFile, buildConfigurations: [
253+
TestBuildConfiguration("Debug", buildSettings: [
254+
// Workaround for CI which have Intel hosts.
255+
"MACOSX_DEPLOYMENT_TARGET": "26.0",
256+
]),
257+
], buildPhases: [
253258
TestSourcesBuildPhase(["lib.swift"]),
254259
], dependencies: [
255260
"HostTool"
256261
]),
257262
TestPackageProductTarget("HostToolClientLibProduct", frameworksBuildPhase:
258263
TestFrameworksBuildPhase([TestBuildFile(.target("HostToolClientLib"))]
259-
), dependencies: [
264+
), buildConfigurations: [
265+
TestBuildConfiguration("Debug", buildSettings: [
266+
// Workaround for CI which have Intel hosts.
267+
"MACOSX_DEPLOYMENT_TARGET": "26.0",
268+
]),
269+
], dependencies: [
260270
"HostToolClientLib"
261271
]),
262272
])

Tests/SWBCoreTests/CommandLineSpecTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ import SWBMacro
888888
table.push(BuiltinMacros.GCC_PREFIX_HEADER, literal: Path.root.join("tmp/prefix.h").str)
889889
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: Path.root.join("tmp/derived").str)
890890
table.push(BuiltinMacros.GCC_PRECOMPILE_PREFIX_HEADER, literal: true)
891-
table.push(BuiltinMacros.TARGET_TEMP_DIR, literal: Path.root.join("tmp/target-temp").str)
891+
table.push(BuiltinMacros.SHARED_PRECOMPS_DIR, literal: Path.root.join("tmp/precomps").str)
892892
table.push(BuiltinMacros.ALWAYS_SEARCH_USER_PATHS, literal: true)
893893
table.push(BuiltinMacros.CLANG_ENABLE_MODULES, literal: true)
894894
table.push(BuiltinMacros.CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING, literal: "")
@@ -926,7 +926,7 @@ import SWBMacro
926926
let pchHash: String
927927
if core.hostOperatingSystem == .windows {
928928
// non-constant on Windows because Path.root may evaluate to any drive letter
929-
pchHash = String(ClangCompilerSpec.precompiledHeaderHashIdentifier(commandLine: [
929+
pchHash = String(ClangCompilerSpec.sharedPrecompiledHeaderSharingIdentifier(commandLine: [
930930
"clang.exe",
931931
"-x",
932932
"c",
@@ -948,21 +948,21 @@ import SWBMacro
948948
"-I\(Path.root.join("tmp/derived/x86_64").str)",
949949
"-I\(Path.root.join("tmp/derived").str)",
950950
Path.root.join("tmp/prefix.h").str,
951-
]))
951+
]).hashValue)
952952
} else {
953953
pchHash = "1041705040740768206"
954954
}
955955

956956
// Check the precompilation task
957957
let precompileTask = delegate.shellTasks.first{ $0.ruleInfo.first! == "ProcessPCH" }!
958-
precompileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c-header", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-c", Path.root.join("tmp/prefix.h").str, "-MD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.d").str)", "-o", "\(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.gch").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.dia").str)"])
959-
#expect(precompileTask.ruleInfo == ["ProcessPCH", Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.gch").str, Path.root.join("tmp/prefix.h").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
958+
precompileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c-header", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-c", Path.root.join("tmp/prefix.h").str, "-MD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.d").str)", "-o", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.dia").str)"])
959+
#expect(precompileTask.ruleInfo == ["ProcessPCH", Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str, Path.root.join("tmp/prefix.h").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
960960
#expect(precompileTask.execDescription == "Precompile prefix.h (x86_64)")
961961
precompileTask.checkInputs([
962962
.path(Path.root.join("tmp/prefix.h").str)
963963
])
964964
precompileTask.checkOutputs([
965-
.path(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.gch").str)
965+
.path(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str)
966966
])
967967
#expect(precompileTask.payload != nil)
968968
#expect(precompileTask.additionalOutput == ["Precompile of \'\(Path.root.join("tmp/prefix.h").str)\' required by \'\(Path.root.join("tmp/input-0.c").str)\'"])
@@ -973,9 +973,9 @@ import SWBMacro
973973
#expect(compileTask.ruleInfo == ["CompileC", Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str, Path.root.join("tmp/input-\(compileTaskIndex).c").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
974974
#expect(compileTask.execDescription == "Compile input-\(compileTaskIndex).c (x86_64)")
975975

976-
compileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-include", "\(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h").str)", "-MMD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).d").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).dia").str)", "-c", "\(Path.root.join("tmp/input-\(compileTaskIndex).c").str)", "-o", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str)"])
976+
compileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-include", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h").str)", "-MMD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).d").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).dia").str)", "-c", "\(Path.root.join("tmp/input-\(compileTaskIndex).c").str)", "-o", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str)"])
977977
compileTask.checkInputs([
978-
.path(Path.root.join("tmp/target-temp/PrecompiledHeaders/\(pchHash)/prefix.h.gch").str),
978+
.path(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str),
979979
.path(Path.root.join("tmp/input-\(compileTaskIndex).c").str)
980980
])
981981
compileTask.checkOutputs([

0 commit comments

Comments
 (0)