Skip to content

Commit

Permalink
Fix compilation with swift build (#7588)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgoyne authored Apr 12, 2024
1 parent 3450711 commit 84db3b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* 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)).
* 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)).
* 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)).
* Fix compilation errors when using command-line `swift build` ([#7587](https://github.com/realm/realm-core/pull/7587), since v14.5.1).

### Breaking changes
* The following things have been renamed or moved as part of moving all of the App Services functionality to the app namespace:
Expand Down
20 changes: 16 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ let package = Package(
products: [
.library(
name: "RealmCore",
targets: ["RealmCore"]),
targets: ["RealmCoreResources"]),
.library(
name: "RealmQueryParser",
targets: ["RealmQueryParser"]),
Expand Down Expand Up @@ -417,12 +417,10 @@ let package = Package(
"realm/tools",
"realm/util/config.h.in",
"realm/version_numbers.hpp.in",
"spm",
"swift",
"win32",
] + syncExcludes + syncServerSources) as [String],
resources: [
.copy("realm/PrivacyInfo.xcprivacy")
],
publicHeadersPath: ".",
cxxSettings: ([
.headerSearchPath("external"),
Expand All @@ -433,6 +431,20 @@ let package = Package(
.linkedFramework("Foundation", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .macCatalyst])),
.linkedFramework("Security", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .macCatalyst])),
]),
// Adding resources to a target makes command line swift build (but not
// xcodebuild) force-include Foundation.h without properly excluding
// non-objc c++ files. Adding the resources in a separate target which
// depends on RealmCore works around this. This target needs a single
// source file (dummy.mm) to work around a different bug in xcodebuild
// (but not swift build) that makes empty targets not work.
.target(
name: "RealmCoreResources",
dependencies: ["RealmCore"],
path: "src/spm",
resources: [
.copy("PrivacyInfo.xcprivacy")
],
publicHeadersPath: "."),
.target(
name: "RealmQueryParser",
dependencies: ["RealmCore"],
Expand Down
File renamed without changes.
Empty file added src/spm/dummy.mm
Empty file.

0 comments on commit 84db3b8

Please sign in to comment.