bazelbuild / bazelbuild/rules_apple
Unable to build XCFramework with swift library that has a dependency to an Objc Library
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
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?
Contributor guide
Research direction
Start with the BUILD file in the linked bazel-ios-sample project and reproduce the failure through the apple_xcframework target, focusing on the SwiftLib dependency on ObjcLib. Compare this with the working objc_library and ios_application builds to determine where the ObjcLib module is omitted. Done means SwiftLibXCFramework builds successfully without the “no such module 'ObjcLib'” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- objective-c, swift
- Domain
- build-system, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100