Skip to content

Commit 3697ed8

Browse files
benlangmuiraciidgh
authored andcommitted
[Xcodeproj] Add -DSWIFT_PACKAGE=1 to the C/C++ preprocessor defines
It was already set for swift, but needed to be added for C/C++/etc. to match how this works for a command-line `swift build` invocation. Also fixes a subtle bug in inherited resolution for build settings.
1 parent b3cb538 commit 3697ed8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Sources/Xcodeproj/XcodeProjectModelSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ fileprivate func combineBuildSettingsPropertyLists(
441441
// Iterate over the overlay values and apply them to the base.
442442
var resultDict = baseDict
443443
for (name, value) in overlayDict {
444-
if let array = baseDict[name]?.array, array.first?.string == "$(inherited)" {
445-
resultDict[name] = .array(array + (value.array ?? []))
444+
if let array = baseDict[name]?.array, let overlayArray = value.array, overlayArray.first?.string == "$(inherited)" {
445+
resultDict[name] = .array(array + overlayArray.dropFirst())
446446
} else {
447447
resultDict[name] = value
448448
}

Sources/Xcodeproj/pbxproj().swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ func xcodeProject(
146146
projectSettings.common.COMBINE_HIDPI_IMAGES = "YES"
147147

148148
// Defined for regular `swift build` instantiations, so also should be defined here.
149-
projectSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["SWIFT_PACKAGE"]
149+
projectSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["$(inherited)", "SWIFT_PACKAGE"]
150+
projectSettings.common.GCC_PREPROCESSOR_DEFINITIONS += ["$(inherited)", "SWIFT_PACKAGE=1"]
150151

151152
// Opt out of headermaps. The semantics of the build should be explicitly
152153
// defined by the project structure, so that we don't get any additional
@@ -161,10 +162,10 @@ func xcodeProject(
161162
projectSettings.debug.DEBUG_INFORMATION_FORMAT = "dwarf"
162163
projectSettings.debug.ENABLE_NS_ASSERTIONS = "YES"
163164
projectSettings.debug.GCC_OPTIMIZATION_LEVEL = "0"
164-
projectSettings.debug.GCC_PREPROCESSOR_DEFINITIONS = ["DEBUG=1", "$(inherited)"]
165+
projectSettings.debug.GCC_PREPROCESSOR_DEFINITIONS = ["$(inherited)", "DEBUG=1"]
165166
projectSettings.debug.ONLY_ACTIVE_ARCH = "YES"
166167
projectSettings.debug.SWIFT_OPTIMIZATION_LEVEL = "-Onone"
167-
projectSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["SWIFT_PACKAGE", "DEBUG"]
168+
projectSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS += ["$(inherited)", "DEBUG"]
168169

169170
// Add some release-specific settings.
170171
projectSettings.release.COPY_PHASE_STRIP = "YES"

Tests/XcodeprojTests/PackageGraphTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ class PackageGraphTests: XCTestCase {
109109
XCTAssertEqual(project.buildSettings.common.CLANG_ENABLE_OBJC_ARC, "YES")
110110
XCTAssertEqual(project.buildSettings.release.SWIFT_OPTIMIZATION_LEVEL, "-Owholemodule")
111111
XCTAssertEqual(project.buildSettings.debug.SWIFT_OPTIMIZATION_LEVEL, "-Onone")
112-
XCTAssertEqual(project.buildSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["SWIFT_PACKAGE", "DEBUG"])
113-
XCTAssertEqual(project.buildSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["SWIFT_PACKAGE"])
112+
XCTAssertEqual(project.buildSettings.debug.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["$(inherited)", "DEBUG"])
113+
XCTAssertEqual(project.buildSettings.common.SWIFT_ACTIVE_COMPILATION_CONDITIONS!, ["$(inherited)", "SWIFT_PACKAGE"])
114+
XCTAssertEqual(project.buildSettings.common.GCC_PREPROCESSOR_DEFINITIONS, ["$(inherited)", "SWIFT_PACKAGE=1"])
114115

115116
result.check(target: "Foo") { targetResult in
116117
targetResult.check(productType: .framework)

0 commit comments

Comments
 (0)