cgrindel / rules_swift_package_manager

Collection of utilities and Bazel rules to aid in the development and maintenance of Swift repositories using Bazel.
Apache License 2.0
74 stars 26 forks source link

Unable to use Agora package #230

Open cgrindel opened 1 year ago

cgrindel commented 1 year ago
          @cgrindel I also tried adding Agora and it built but when I run the application in the iOS simulator it's crashing with this message:
Warning: Error creating LLDB target at path '/Users/logan/Library/Developer/Xcode/DerivedData/Phono-birejekbhxukppblfutmohyojdym/Build/Products/bazel-out/ios-x86_64-min14.0-applebin_ios-ios_x86_64-dbg-ST-3d49fca66c8d/bin/Phono/Phono/Phono.app'- using an empty LLDB target which can cause slow memory reads from remote devices: the specified architecture 'arm64-*-*' is not compatible with 'x86_64-apple-ios14.0.0-simulator' in '/Users/logan/Library/Developer/Xcode/DerivedData/Phono-birejekbhxukppblfutmohyojdym/Build/Products/bazel-out/ios-x86_64-min14.0-applebin_ios-ios_x86_64-dbg-ST-3d49fca66c8d/bin/Phono/Phono/Phono.app/Phono'
dyld[78318]: Library not loaded: @rpath/AgoraCore.framework/AgoraCore
  Referenced from: <CFDCA36E-5D08-3378-964B-7FA9AF503399> /Users/logan/Library/Developer/CoreSimulator/Devices/05D87724-92DF-41DD-9AA6-0E25DE53CF5E/data/Containers/Bundle/Application/93F98452-6026-491C-9C48-B13BA31AB45B/Phono.app/Frameworks/AgoraRtcKit.framework/AgoraRtcKit
Message from debugger: Terminated due to signal 6
  Reason: tried: '/Users/logan/Library/Developer/Xcode/DerivedData/Phono-birejekbhxukppblfutmohyojdym/Build/Products/bazel-out/ios-x86_64-min14.0-applebin_ios-ios_x86_64-dbg-ST-3d49fca66c8d/bin/Phono/Phono/AgoraCore.framework/AgoraCore' (errno=2), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/AgoraCore.framework/AgoraCore' (errno=2), '/usr/lib/swift/AgoraCore.framework/AgoraCore' (errno=2, no dyld cache), '/Users/logan/Library/Developer/CoreSimulator/Devices/05D87724-92DF-41DD-9AA6-0E25DE53CF5E/data/Containers/Bundle/Application/93F98452-6026-491C-9C48-B13BA31AB45B/Phono.app/Frameworks/AgoraCore.framework/AgoraCore' (errno=2), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/AgoraCore.framework/AgoraCore' (errno=2), '/usr/lib/swift/AgoraCore.framework/AgoraCore' (errno=2, no dyld cache), '/Users/logan/Library/Developer/CoreSimulator/Devices/05D87724-92DF-41DD-9AA6-0E25DE53CF5E/data/Containers/Bundle/Application/93F98452-6026-491C-9C48-B13BA31AB45B/Phono.app/Frameworks/AgoraCore.framework/AgoraCore' (errno=2), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/AgoraCore.framework/AgoraCore' (errno=2)

My Package.swift has:

.package(url: "https://github.com/AgoraIO/AgoraRtcEngine_iOS", .upToNextMajor(from: "3.4.8")),

And my BUILD file has:

"@swiftpkg_agorartcengine_ios//:remote_archive_AgoraRtcKit.xcframework.zip_AgoraRtcKit",

_Originally posted by @AttilaTheFun in https://github.com/cgrindel/swift_bazel/issues/153#issuecomment-1430074173_

cgrindel commented 1 year ago

@AtlilaTheFun Can you share a Swift file showing the imports and how you use Agora?

AttilaTheFun commented 1 year ago

Thanks! I also created a separate issue for the Firebase version 10+ failure here: https://github.com/cgrindel/swift_bazel/issues/231

I might be able to downgrade to version 8 in the meantime.

cgrindel commented 1 year ago

Which libraries are you using from Firebase? Right now, some of the libraries won't work due to #208. This is related to how Bazel Objc support does not fully support @import. I am going to dig back into that once release 0.3.0 is out the door.

AttilaTheFun commented 1 year ago

I think just the same ones you're currently using in your examples -- FirebaseAnalyticsWithoutAtIdSupport and FirebaseCrashlytics. I was just using a newer version of the dependency than your example.

AttilaTheFun commented 1 year ago

Can you share a Swift file showing the imports and how you use Agora?

@cgrindel I only use the voice call functionality from the core AgoraRtcKit library.

It's basically the same as their QuickStart guide here but using more of the functionality: https://docs.agora.io/en/voice-calling/get-started/get-started-sdk?platform=ios

In my Package.swift file I depend on it like this:

.package(url: "https://github.com/AgoraIO/AgoraRtcEngine_iOS", .upToNextMajor(from: "3.4.8")),

And then in Swift I import it like:

import AgoraRtcKit

You could just verify you can construct their singleton with:

private var agoraKit: AgoraRtcEngineKit!

init() {
    self.agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: appID, delegate: self)
}

I did notice they've updated the APIs a bit since I wrote this code -- I could try pulling the newer version and see if that works better.

AttilaTheFun commented 1 year ago

@cgrindel Update: I managed to get it working (or at least, not crashing). After I updated to their 4.X version the error was a bit easier to understand. It seems like they use dylibs for their libraries so you can install the specific subset that's relevant to your application and they weakly reference symbols defined in the other dylibs.

Initially I tried just depending on:

"@swiftpkg_agoraaudio_ios//:remote_archive_AgoraRtcKit.xcframework.zip_AgoraRtcKit",

And the app crashed because the Agorafdkaac dylib was not loaded. I added this dependency:

"@swiftpkg_agoraaudio_ios//:remote_archive_Agorafdkaac.xcframework.zip_Agorafdkaac",

And then it crashed because the AgoraSoundTouch dylib was not loaded.

Finally I added:

"@swiftpkg_agoraaudio_ios//:remote_archive_AgoraSoundTouch.xcframework.zip_AgoraSoundTouch",

And it didn't crash. I'll have to do some more testing to make sure I can still make voice calls and such but at least it's not crashing anymore.

Looking at their Package.swift, I see they define a RtcBasic product with these three dependencies:

.library(name: "RtcBasic", targets: ["AgoraRtcKit", "Agorafdkaac", "AgoraSoundTouch"]),

Does swift_bazel have a way to depend on the product rather than the individual targets to ensure that I get all of them if this changes in the future?

cgrindel commented 1 year ago

Does swift_bazel have a way to depend on the product rather than the individual targets to ensure that I get all of them if this changes in the future?

@AttilaTheFun The short answer is yes and no. Bazel does not have a mechanism to group one or more targets to a single referenceable label. The filegroup sort of does this for source files.

Under the covers, the Gazelle extension for swift_bazel does resolve to SPM product(s). When it is time to add the deps, to a swift_xxx, it retrieves all of the targets associated with the product(s). I have a related issue to ensure that byName references discovered while processing swift_package rules resolve to a product name, then fallback to a target name.

cgrindel commented 1 year ago

@AttilaTheFun I put together a branch with a basic example that uses AgoraRtcEngine_iO. The test that I added seems to build and execute successfully. Is that package working properly for you?

cgrindel commented 1 year ago

@AttilaTheFun Just wanted to check in to see if Agora was working for you now. If so, I am inclined to close the issue.