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

Unable to build XCFramework with swift library that has a dependency to an Objc Library #2547

Open
prasadpamidi opened this issue Sep 27, 2024 · 1 comment

Comments

@prasadpamidi
Copy link

Hi,

I'm currently exploring the use of Bazel to build and distribute our internal SDK but running into an issue where the apple_xcframework action fails while i try to build a swift_library due to missing reference to an Objc library that the swift_library depends on.. Also apple_xcframework works fine when i try to build an objc_library target directly instead of swift_library. I'm curious if this is not supported or if i am doing this wrong. Also this doesn't happen if add the swift_library to ios_application target and try to build the application target.. I did try to explore different options via copts and linkopts to provide the directory to look for the ObjcLib framework/lib during build step, but none worked.

Here's the error:

bazel-out/darwin_x86_64-opt-exec-ST-4b127f4e9eac/bin/external/rules_swift~/tools/worker/worker swiftc @bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-1a614b7cee85/bin/SwiftLib.swiftmodule-0.params)
# Configuration: e78661a1df9c1b862432476a17f727734c4389d9eb2b54e457242104cf4bfca4
# Execution platform: @@platforms//host:host
error: verify-emitted-module-interface command failed with exit code 1 (use -v to see invocation)
bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-1a614b7cee85/bin/SwiftLib.swiftinterface:4:8: error: no such module 'ObjcLib'
import ObjcLib
       ^
bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-1a614b7cee85/bin/SwiftLib.swiftinterface:1:1: error: failed to verify module interface of 'SwiftLib' due to the errors above; the textual interface may be broken by project issues or a compiler bug
// swift-interface-format-version: 1.0
^
error: fatalError

Here's the BUILD file.

load("@rules_cc//cc:defs.bzl", "objc_library")
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_xcframework")
load("@rules_swift//swift:swift.bzl", "swift_library")

filegroup(
    name = "ObjcLibHeaders",
    srcs = [
        "ObjcLib/Classes/Util.h",
    ],
)

objc_library(
    name = "ObjcLib",
    srcs = glob([
        "ObjcLib/Classes/*.h",
        "ObjcLib/Classes/*.m",
    ]),
    hdrs = [":ObjcLibHeaders"],
    includes = [
        "ObjcLib/Classes",
    ],
    module_name = "ObjcLib",
    enable_modules = True,
    visibility = ["//visibility:public"],
)

swift_library(
    name = "SwiftLib",
    srcs = glob(["SwiftLib/Classes/**/*.swift"]),
    module_name = "SwiftLib",
    tags = ["manual"],
    visibility = ["//visibility:public"],
    deps = [
        ":ObjcLib",
    ],
)

apple_xcframework(
    name = "SwiftLibXCFramework",
    deps = [
        ":SwiftLib",
    ],
    infoplists = ["SwiftLib/Info.plist"],
    ios = {
        "device": ["arm64"],
        "simulator": [
            "x86_64",
            "arm64",
        ],
    },
    minimum_os_versions = {
        "ios": "16.0",
    },
    bundle_id = "com.bazel.ios.sample",
    bundle_name = "SwiftLib",
    visibility = ["//visibility:public"],
)

Here's the project to try https://github.com/prasadpamidi/bazel-ios-sample

Am I missing something?

@prasadpamidi
Copy link
Author

Not sure whether if this is an issue with apple_xcframework or swift_library rule in rules_swift repo bazelbuild/rules_swift#1314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant