Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xcode 11] swift package generate-xcodeproj with RealmSwift dependency does not build. #6345

Closed
marc-medley opened this issue Nov 13, 2019 · 6 comments
Assignees
Labels
Blocked This issue is blocked by another issue O-Community

Comments

@marc-medley
Copy link

marc-medley commented Nov 13, 2019

Bug: An Xcode 11 project which is generated from an executable-type Swift Package which has RealmSwift as a dependency does not build.

Goals

The goal is to have an Xcode 11 project which is generated from an executable-type Swift Package which has RealmSwift as a dependency that can successfully build and run.

Expected Results

What Swift Package that builds from the command line is also expected to build in an Xcode 11 project generated from the same package.

Actual Results

Build fails as show below in the steps to reproduced.

Steps to Reproduce

  1. Setup an executable type Swift Package with RealmSwift as a dependency.
  1. Verify build from the command line on has only a few warnings.
swift build

# RealmSPMXcode/.build/checkouts/realm-cocoa/Realm/RLMRealm.mm:135:17: 
# warning: method definition for 'privilegesForRealm' not found [-Wincomplete-implementation]
# @implementation RLMRealm {

# RealmSPMXcode/.build/checkouts/realm-cocoa/include/Realm/RLMRealm.h:658:1: 
# note: method 'privilegesForRealm' declared here
# - (struct RLMRealmPrivileges)privilegesForRealm;

## ... snip ...

# warnings generated.
# [139/139] Linking RealmSPMXcode
  1. Generate an Xcode 11 project from the Swift Package.
swift package generate-xcodeproj 
# generated: ./RealmSPMXcode.xcodeproj
open RealmSPMXcode.xcodeproj/
  1. Build in Xcode with "My Mac" as the target.

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!01!

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!02!

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!03!

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!04!

Workaround: Edit RealmCore 5.23.5/realm/util/terminate.cpp to remove the REALM_VER_CHUNK expansion related error:

REALM_NORETURN void terminate(const char* message, const char* file, long line) noexcept
{
    std::stringstream ss;
    // ss << file << ":" << line << ": " REALM_VER_CHUNK " " << message << '\n'; // :BEFORE:
    ss << file << ":" << line << ": [realm-core-5.23.5] " << message << '\n';    // :AFTER:
    terminate_internal(ss);
}

After the about workaround more errors occur:

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!05!

Notice that .build/checkouts/realm-cocoa/Realm/ObjectStore/src/impl/results_notifier.hpp
and .build/checkouts/realm-cocoa/Realm/ObjectStore/src/impl/results_notifier.cpp are in the same directly.

Next attempted workaround ...

// #include "impl/results_notifier.hpp"
#include "results_notifier.hpp"

... leads to yet more errors:

XcodeUNITO-UNDERSCORE!Errors!UNITO-UNDERSCORE!06!

Code Sample

Version of Realm and Tooling

Realm framework version: REALM_COCOA_VERSION 3.21.0

Realm Object Server version: REALM_VERSION 5.23.5

Xcode version: 11.2

iOS/OSX version: macOS Mojave 10.14.6 (18G1012)

Dependency manager + version: swift-tools-version 5.1

@tgoyne
Copy link
Member

tgoyne commented Nov 13, 2019

swift build and swift generate-xcodeproj do significantly different things and AFAICT it isn't possible to support both of them at the same time.

@marc-medley
Copy link
Author

marc-medley commented Nov 13, 2019

I have several projects which build and run with both in the Swift Package Manager CLI swift build environment and as an Xcode project created by swift generate-xcodeproj. Both can work.

It's actually a more rigorous process to test with both because sometimes one environment identifies weaknesses which the other environment does not. I've been using this multi-environment SPM-centered approach for almost 2 years on multi-environment Linux/iOS/macOS C/Swift headless packages.

The version auto-generated for the Xcode environment by SPM has certain GUI debugging conveniences. However, a Swift Package which builds and runs warning-free across all three environment (swift build macOS, swift generate-xcodeproj and swift build Linux) is pretty solid.

So, at least in my experience, this SPM-centered (i.e. all environments are derived from the Swift Package) multi-enviroment approach can work; and, it can also help provide higher quality code.

@tgoyne
Copy link
Member

tgoyne commented Nov 13, 2019

Well, if you can figure out a way to deal with the problems I'd certainly be interested in them, but I couldn't. The REALM_VER_CHUNK error is because .define("REALM_VERSION_STRING", to: "\"\(coreVersionStr)\"") results in -DREALM_VERSION_STRING="5.23.6" being passed to the compiler with swift build, but -DREALM_VERSION_STRING=5.23.6 with the generated xcode project (note how it has stripped the quotes). The header inclusion failures are because the generated xcode project ignores .headerSearchPath("Realm/ObjectStore/src").

@marc-medley
Copy link
Author

@tgoyne Thank you for the clarifying information. It's apparent that there are some upstream Package Manager issues to be addressed for a swift package generate-xcodeproj with RealmSwift dependency to build successfully.

The following issues have now been reported as SwiftPM bugs:

@AdieOlami
Copy link

Hi, any update on this please.

@dianaafanador3
Copy link
Collaborator

Closing this as we don't need to generate an xcodeproj to be able to open a Package project as the warning mentions when running swift package generate-xcodeproj
Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
If this is needed for other uses case, @AdieOlami @marc-medley please reopen the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Blocked This issue is blocked by another issue O-Community
Projects
None yet
Development

No branches or pull requests

4 participants