realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.18k stars 2.14k forks source link

Duplicated symbol `gcov_flush` (SPM, Xcode 12) #6814

Closed natalia-osa closed 3 years ago

natalia-osa commented 3 years ago

Goals

To be able to compile project with Realm dependency added via SPM using Xcode 12.

Expected Results

The dependency (realm) shouldn't have duplicated symbols.

Actual Results

While locally I can make things happen, on CI (Bitrise) I receive following logs. It rather looks like an issue from Realm than from Bitrise, but please correct me if I'm wrong.

[...]
▸ Compiling MySomethingViewCell.swift
▸ Linking MyAppName
❌  duplicate symbol '___gcov_flush' in
> Realm.o
> RealmCore.o
❌  ld: 1 duplicate symbol for architecture x86_64
❌  clang: error: linker command failed with exit code 1 (use -v to see invocation)

and in detailed logs:

duplicate symbol '___gcov_flush' in:
    /Users/vagrant/Library/Developer/Xcode/DerivedData/MyAppName-bovnkatmzqfuxmgxfczktvjiwuqp/Build/Products/Staging-iphonesimulator/Realm.o
    /Users/vagrant/Library/Developer/Xcode/DerivedData/MyAppName-bovnkatmzqfuxmgxfczktvjiwuqp/Build/Products/Staging-iphonesimulator/RealmCore.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Steps for others to Reproduce

Hard to say, especially since I can't reproduce it locally, where it's working. Maybe just the step in Bitrise where it fails:

- xcode-test:
          inputs:
            - project_path: $XCODEBUILD_PROJECT
            - scheme: $XCODEBUILD_SCHEME
            - xcodebuild_test_options: $XCODEBUILD_OPTIONS
            - simulator_device: iPad Air (4th generation)
            - generate_code_coverage_files: 'yes'
            - should_build_before_test: 'no'
            - output_tool: 'xcpretty'

Code Sample

No sample code, since it fails on the compilation of the library.

Version of Realm and Tooling

Realm framework version: 5.4.4

Realm Object Server version: None

Xcode version: 12.0

iOS version: iOS 11 and newer (trying to run tests on a simulator of iPad Air 4Gen, iOS 14) OSX version: macOS 10.15.6 (Catalina) on CI (same version locally on my machine where it compiles)

Dependency manager + version: SPM included with Xcode SPM rules for this library- repository (https://github.com/realm/realm-cocoa.git), version EXACT to 5.4.4 (but tested 5.4.3 as well, and it also didn't work). When importing via SPM I ticked both Package Products: Realm and RealmSwift. By the way, you're missing installation via SPM in your documentation (https://realm.io/docs/swift/latest#installation).

leemaguire commented 3 years ago

Can you delete the derived data on your CI box and rebuild? I've never actually seen that build error before.

Also we are currently working on adding SPM installation docs.

tgoyne commented 3 years ago

gcov_flush is a function injected by the compiler for code coverage, so this suggests something is wrong with how something is being configured for that. Does it compile if you enable code coverage locally? If so it's probably a bitrise bug.

natalia-osa commented 3 years ago

@tgoyne In project settings, both locally and on CI (since it's running the same commit) I have flags

So locally Xcode calculates code coverage.

@leemaguire I've removed derived data on CI. It didn't help and is still failing.

I've contacted Bitrise and will point them this ticket. Maybe it's something wrong on their side as you've mentioned. Maybe they will reach you out or fix it.

natalia-osa commented 3 years ago

So we were diving into the topic with a person from Bitrise, and it went out that if I locally run the build from Xcode it worked, but with a command, it didn't. In Bitrise configuration there was an additional flag "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES", which in my project is set to NO. This flag causes Realm to fail with the duplicated symbol.

Unfortunately, if you want to turn that flag off, you have to turn off entire code coverage, what's at least inconvenient. So is there any chance you'll be able to get rid of that duplicated symbol in the case when GCC_INSTRUMENT_PROGRAM_FLOW_ARCS is turned on?

Worth to add, that it happens when using SPM or Xcode 12. Maybe just one of these two are sufficient, but I changed both at once.

petrpavlik commented 3 years ago

Hi there, I've run into the same issue and asked a question on apple developer forum https://developer.apple.com/forums/thread/663007. This seems to be a bug in Xcode build system.

natalia-osa commented 3 years ago

@petrpavlik FYI (since you say you have the same issue), in Bitrise if you set generate code coverage files to NO, then it compiles properly. Since it's not handly not to have code coverage files in a project which does contain unit tests, Customer Engineer from Bitrise suggested to do the following:

There might be a more efficient workaround that I just thought of. You could potentially turn the "generate code coverage" section off, then use the "Additional options for xcodebuild build test call" section to add the "GCC_GENERATE_TEST_COVERAGE_FILES=YES" argument.

This is a pretty handy workaround to both have code coverage and not have that instrument program flow, which breaks command compilation.

I guess the issue can be closed.