grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
2.05k stars 420 forks source link

duplicate symbols error. if used with Firestore(Firebase) at the same time #1134

Closed 1amageek closed 3 years ago

1amageek commented 3 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

When I use grpc-swift and Firestore with SwiftPackageManager, I get the following error.

duplicate symbol 'ssl_ctx_st::ssl_ctx_st(ssl_method_st const*)' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_ctx_st::ssl_ctx_st(ssl_method_st const*)' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_ctx_st::~ssl_ctx_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_ctx_st::~ssl_ctx_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_session_st::~ssl_session_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_session_st::~ssl_session_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_st::ssl_st(ssl_ctx_st*)' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_st::ssl_st(ssl_ctx_st*)' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_st::~ssl_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
duplicate symbol 'ssl_st::~ssl_st()' in:
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/CNIOBoringSSL.o
    /Users/1amageek/Library/Developer/Xcode/DerivedData/HOPTestProject-bbsmxhrxezzefnafzdsclfnjqkgd/Build/Products/Debug-iphonesimulator/openssl_grpc.o
ld: 10 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce:

  1. Create new SPM project.
  2. Set package.swift
    
    import PackageDescription

let package = Package( name: "SampleProject", platforms: [.iOS(.v10), .macOS(.v10_12), .tvOS(.v10), .watchOS(.v6)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "SampleProject", targets: ["SampleProject"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: / package url /, from: "1.0.0"), .package(name: "grpc-swift", url: "git@github.com:grpc/grpc-swift.git", .upToNextMajor(from: "1.0.0")), .package(name: "Firebase", url: "git@github.com:firebase/firebase-ios-sdk.git", .upToNextMajor(from: "7.5.0"))

],
targets: [
    // Targets are the basic building blocks of a package. A target can define a module or a test suite.
    // Targets can depend on other targets in this package, and on products in packages this package depends on.
    .target(
        name: "SampleProject",
        dependencies: [
            .product(name: "GRPC", package: "grpc-swift"),
            .product(name: "FirebaseFirestore", package: "Firebase")
        ]),
    .testTarget(
        name: "SampleProjectTests",
        dependencies: [
            "SampleProject",
            .product(name: "GRPC", package: "grpc-swift"),
            .product(name: "FirebaseFirestore", package: "Firebase")
        ]),
]

)


#### Relevant Code:

import FirebaseFirestore import GRPC

struct SampleProject { var text = "Hello, World!" }

1amageek commented 3 years ago

https://github.com/firebase/firebase-ios-sdk/issues/7508

Lukasa commented 3 years ago

Ugh, these duplicate symbols are going to be extremely difficult to solve.

It's not currently possible for NIO's existing name-spacing strategy to namespace those symbols as they are not directly called, but instead produced by the C++ runtime. The result is that swift-nio-ssl and boringSSL-SwiftPM are fundamentally conflicting: they cannot currently co-exist in the same package.

On Apple platforms this could be solved by placing a dynamic library boundary in the way. On Linux if we could control symbol visibility the same solution would work there (though it's moot given that the Firebase iOS SDK is an iOS SDK). A long-term solution is going to be harder.

Lukasa commented 3 years ago

The ideal solution would be for there to be a clang feature that would automatically namespace these symbols. That's...quite a lot of work! I'll chat to the boringssl folks and see if we can come up with an alternative solution.

1amageek commented 3 years ago

@Lukasa Thanks for the reply. I appreciate your response.

Lukasa commented 3 years ago

See apple/swift-nio-ssl#269 for a proposed solution.