Skip to content

Commit 84db3b8

Browse files
authored
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 3450711 commit 84db3b8

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
@@ -11,6 +11,7 @@
1111
* SyncUser::all_sessions() included sessions in every state *except* for waiting for access token, which was weirdly inconsistent. It now includes all sessions. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
1212
* App::all_users() included logged out users only if they were logged out while the App instance existed. It now always includes all logged out users. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
1313
* Deleting the active user left the active user unset rather than selecting another logged-in user as the active user like logging out and removing users did. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
14+
* Fix compilation errors when using command-line `swift build` ([#7587](https://github.com/realm/realm-core/pull/7587), since v14.5.1).
1415

1516
### Breaking changes
1617
* The following things have been renamed or moved as part of moving all of the App Services functionality to the app namespace:

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)