bazelbuild / bazelbuild/rules_apple
UIKit.h not found to build swift library with objc library
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
### Description of the bug:
Attempting to build iOS framework following this guide here https://medium.com/baracoda-engineering/build-an-ios-framework-for-distribution-with-bazel-838ace7444c8
Had to update the WORKSPACE with newer versions of libraries. Running into this problem below...
When building swift_library with objc_library, build fails with `UIKit.h file is not found`.
when building objc_library directly, no such error. Only when building swift_library with the same objc_library, error occurs
Below is an error dump
```
INFO: Analyzed target //framework/objc:TestFrameworkProvider (60 packages loaded, 1301 targets configured).
INFO: Found 1 target...
ERROR: /Users/jimji/Code/bazel-swift-objective-c-framework/framework/objc/BUILD:24:14: Compiling Swift module //framework/objc:TestFrameworkProvider failed: (Exit 1): worker failed: error executing command (from target //framework/objc:TestFrameworkProvider)
(cd /private/var/tmp/_bazel_jimji/a011e649c4aef6bee0e4fd7e702d6135/execroot/bazel-framework-test && \
exec env - \
APPLE_SDK_PLATFORM=MacOSX \
APPLE_SDK_VERSION_OVERRIDE=13.1 \
SWIFT_AVOID_WARNING_USING_OLD_DRIVER=1 \
XCODE_VERSION_OVERRIDE=14.2.0.14C18 \
bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/darwin_arm64-fastbuild/bin/framework/objc/TestFrameworkProvider.swiftmodule-0.params)
# Configuration: 913265144afa5073ab2925a40f47c1b06b3e702fb3af6e4203d81054e02d7a5d
# Execution platform: @local_config_platform//:host
error: emit-module command failed with exit code 1 (use -v to see invocation)
:1:9: note: in file included from :1:
#import "../../../../../framework/objc/TestFrameworkController.h"
^
/private/var/tmp/_bazel_jimji/a011e649c4aef6bee0e4fd7e702d6135/execroot/bazel-framework-test/bazel-out/applebin_ios-ios_x86_64-fastbuild-ST-5557854aa1ac/bin/framework/objc/../../../../../framework/objc/TestFrameworkController.h:2:9: error: 'UIKit/UIKit.h' file not found
#import
^
framework/objc/TestFrameworkProvider.swift:3:8: error: could not build Objective-C module 'TestFramework'
import TestFramework
^
:1:9: note: in file included from :1:
#import "../../../../../framework/objc/TestFrameworkController.h"
^
/private/var/tmp/_bazel_jimji/a011e649c4aef6bee0e4fd7e702d6135/execroot/bazel-framework-test/bazel-out/applebin_ios-ios_x86_64-fastbuild-ST-5557854aa1ac/bin/framework/objc/../../../../../framework/objc/TestFrameworkController.h:2:9: error: 'UIKit/UIKit.h' file not found
#import
^
framework/objc/TestFrameworkProvider.swift:3:8: error: could not build Objective-C module 'TestFramework'
import TestFramework
^
Target //framework/objc:TestFrameworkProvider failed to build
INFO: Elapsed time: 11.605s, Critical Path: 3.44s
INFO: 4 processes: 2 internal, 2 darwin-sandbox.
FAILED: Build did NOT complete successfull
```
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
repo was created with the code/file used to reproduce the issue here https://github.com/jimji1005/bazel-ios-framework-test
cmd used `bazel build --config=ios_simulator framework/objc:TestFrameworkProvider --verbose_failures`
In a nutshell objc_library builds fine, by itself
```
objc_library(
name = "TestFramework",
srcs = [
"TestFrameworkController.mm"
],
hdrs = [
"TestFrameworkController.h"
],
module_name = "TestFramework",
visibility = ["//:framework"],
target_compatible_with = ["@platforms//os:macos"],
)
```
but swift_library does not build when importing objc_library
```
swift_library(
name = "TestFrameworkProvider",
srcs = [
"TestFrameworkProvider.swift",
],
module_name = "TestFrameworkProvider",
visibility = ["//:framework"],
deps = [
"TestFramework"
]
)
```
### Which operating system are you running Bazel on?
Macos ventura 13.2.1
### What is the output of `bazel info release`?
release 6.1.1-homebrew
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
```text
git@github.com:jimji1005/bazel-ios-framework-test.git
71d0b2c7784a658d4d61d32592273d0fb780019f
71d0b2c7784a658d4d61d32592273d0fb780019f
```
### Have you found anything relevant by searching the web?
unable to find issues similar to this, closest one was this issue here
https://github.com/bazelbuild/bazel/issues/126
I attempted to designate versions but made no difference
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start by running `bazel build --config=ios_simulator framework/objc:TestFrameworkProvider --verbose_failures` from the linked reproduction repository. Read the framework/objc/BUILD targets, TestFrameworkProvider.swift, and TestFrameworkController.h/.mm, then compare the failing swift_library build with the standalone objc_library build. Done means the Swift target imports the Objective-C module and builds successfully without the UIKit/UIKit.h error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, 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