Skip to content

Commit 7aa1056

Browse files
committed
Pass toolchain settings when using XCBuild
This is a follow-up to #3695, adding various other settings of the toolchain that we weren't yet correctly forwarding when XCBuild is being used. rdar://82313817
1 parent 4af60f7 commit 7aa1056

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ public struct PIFBuilderParameters {
2727
/// Whether to create dylibs for dynamic library products.
2828
public let shouldCreateDylibForDynamicProducts: Bool
2929

30+
/// The path to the library directory of the active toolchain.
31+
public let toolchainLibDir: AbsolutePath
32+
3033
/// Creates a `PIFBuilderParameters` instance.
3134
/// - Parameters:
3235
/// - enableTestability: Whether or not build for testability is enabled.
3336
/// - shouldCreateDylibForDynamicProducts: Whether to create dylibs for dynamic library products.
34-
public init(enableTestability: Bool, shouldCreateDylibForDynamicProducts: Bool) {
37+
public init(enableTestability: Bool, shouldCreateDylibForDynamicProducts: Bool, toolchainLibDir: AbsolutePath) {
3538
self.enableTestability = enableTestability
3639
self.shouldCreateDylibForDynamicProducts = shouldCreateDylibForDynamicProducts
40+
self.toolchainLibDir = toolchainLibDir
3741
}
3842
}
3943

@@ -395,6 +399,10 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
395399
settings[.SWIFT_FORCE_STATIC_LINK_STDLIB] = "NO"
396400
settings[.SWIFT_FORCE_DYNAMIC_LINK_STDLIB] = "YES"
397401

402+
if product.type == .executable || product.type == .test {
403+
settings[.LIBRARY_SEARCH_PATHS] = ["$(inherited)", "\(parameters.toolchainLibDir.pathString)/swift/macosx"]
404+
}
405+
398406
// Tests can have a custom deployment target based on the minimum supported by XCTest.
399407
if mainTarget.underlyingTarget.type == .test {
400408
settings[.MACOSX_DEPLOYMENT_TARGET] = mainTarget.underlyingTarget.deploymentTarget(for: .macOS)

Sources/XCBuildSupport/XcodeBuildSystem.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
153153

154154
// Generate a table of any overriding build settings.
155155
var settings: [String: String] = [:]
156+
// An error with determining the override should not be fatal here.
157+
settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString
156158
// Always specify the path of the effective Swift compiler, which was determined in the same way as for the native build system.
157159
settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompiler.pathString
158-
settings["LIBRARY_SEARCH_PATHS"] = "$(inherited) \(buildParameters.toolchain.toolchainLibDir.pathString)/swift/macosx"
160+
settings["LIBRARY_SEARCH_PATHS"] = "$(inherited) \(buildParameters.toolchain.toolchainLibDir.pathString)"
161+
settings["OTHER_CFLAGS"] = "$(inherited) \(buildParameters.toolchain.extraCCFlags.joined(separator: " "))"
162+
settings["OTHER_CPLUSPLUSFLAGS"] = "$(inherited) \(buildParameters.toolchain.extraCPPFlags.joined(separator: " "))"
163+
settings["OTHER_SWIFT_FLAGS"] = "$(inherited) \(buildParameters.toolchain.extraSwiftCFlags.joined(separator: " "))"
159164
// Optionally also set the list of architectures to build for.
160165
if !buildParameters.archs.isEmpty {
161166
settings["ARCHS"] = buildParameters.archs.joined(separator: " ")
@@ -164,7 +169,7 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
164169
// Generate the build parameters.
165170
let params = XCBBuildParameters(
166171
configurationName: buildParameters.configuration.xcbuildName,
167-
overrides: .init(commandLine: .init(table: settings)),
172+
overrides: .init(synthesized: .init(table: settings)),
168173
activeRunDestination: runDestination
169174
)
170175

@@ -226,7 +231,7 @@ struct XCBBuildParameters: Encodable {
226231
}
227232

228233
struct SettingsOverride: Encodable {
229-
var commandLine: XCBSettingsTable? = nil
234+
var synthesized: XCBSettingsTable? = nil
230235
}
231236

232237
var configurationName: String
@@ -247,7 +252,8 @@ extension PIFBuilderParameters {
247252
public init(_ buildParameters: BuildParameters) {
248253
self.init(
249254
enableTestability: buildParameters.enableTestability,
250-
shouldCreateDylibForDynamicProducts: buildParameters.shouldCreateDylibForDynamicProducts
255+
shouldCreateDylibForDynamicProducts: buildParameters.shouldCreateDylibForDynamicProducts,
256+
toolchainLibDir: buildParameters.toolchain.toolchainLibDir
251257
)
252258
}
253259
}

Tests/XCBuildSupportTests/PIFBuilderTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,8 @@ extension PIFBuilderParameters {
22952295
) -> Self {
22962296
PIFBuilderParameters(
22972297
enableTestability: false,
2298-
shouldCreateDylibForDynamicProducts: shouldCreateDylibForDynamicProducts
2298+
shouldCreateDylibForDynamicProducts: shouldCreateDylibForDynamicProducts,
2299+
toolchainLibDir: AbsolutePath("/toolchain/lib")
22992300
)
23002301
}
23012302
}

0 commit comments

Comments
 (0)