Skip to content

Commit b14e1e4

Browse files
tgoynejedelbo
authored andcommitted
Fix compilation with swift build (#7588)
Adding a resource to a target makes `swift build` try to force-include Foundation.h when building source files in that target, which breaks if any of the source files aren't obj-c. To work around this, the resources need to be in a separate target from the source files. xcodebuild breaks if a target has zero source files, so add an empty obj-c file to build as part of this new resource target.
1 parent 81be530 commit b14e1e4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 14.5.2 Release notes
22

33
### Fixed
4+
* Fix compilation errors when using command-line `swift build` ([#7587](https://github.com/realm/realm-core/pull/7587), since v14.5.1).
45

56
### Compatibility
67
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10. If you want to upgrade from an earlier file format version you will have to use RealmCore v13.x.y or earlier.

Package.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ let package = Package(
364364
products: [
365365
.library(
366366
name: "RealmCore",
367-
targets: ["RealmCore"]),
367+
targets: ["RealmCoreResources"]),
368368
.library(
369369
name: "RealmQueryParser",
370370
targets: ["RealmQueryParser"]),
@@ -417,12 +417,10 @@ let package = Package(
417417
"realm/tools",
418418
"realm/util/config.h.in",
419419
"realm/version_numbers.hpp.in",
420+
"spm",
420421
"swift",
421422
"win32",
422423
] + syncExcludes + syncServerSources) as [String],
423-
resources: [
424-
.copy("realm/PrivacyInfo.xcprivacy")
425-
],
426424
publicHeadersPath: ".",
427425
cxxSettings: ([
428426
.headerSearchPath("external"),
@@ -433,6 +431,20 @@ let package = Package(
433431
.linkedFramework("Foundation", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .macCatalyst])),
434432
.linkedFramework("Security", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .macCatalyst])),
435433
]),
434+
// Adding resources to a target makes command line swift build (but not
435+
// xcodebuild) force-include Foundation.h without properly excluding
436+
// non-objc c++ files. Adding the resources in a separate target which
437+
// depends on RealmCore works around this. This target needs a single
438+
// source file (dummy.mm) to work around a different bug in xcodebuild
439+
// (but not swift build) that makes empty targets not work.
440+
.target(
441+
name: "RealmCoreResources",
442+
dependencies: ["RealmCore"],
443+
path: "src/spm",
444+
resources: [
445+
.copy("PrivacyInfo.xcprivacy")
446+
],
447+
publicHeadersPath: "."),
436448
.target(
437449
name: "RealmQueryParser",
438450
dependencies: ["RealmCore"],

src/spm/dummy.mm

Whitespace-only changes.

0 commit comments

Comments
 (0)