rules_apple
rules_apple copied to clipboard
UIKit.h not found to build swift library with objc library
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)
<module-includes>:1:9: note: in file included from <module-includes>: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 <UIKit/UIKit.h>
^
framework/objc/TestFrameworkProvider.swift:3:8: error: could not build Objective-C module 'TestFramework'
import TestFramework
^
<module-includes>:1:9: note: in file included from <module-includes>: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 <UIKit/UIKit.h>
^
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
?
[email protected]: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
the method mentioned in the blog post around using --apple_platform_type=ios
to force the library to be built for iOS is no longer valid. the recommendation is that you don't build *_library
targets directly and instead build them indirectly as dependencies of some ios_*
target like ios_application
or ios_build_test
from rules_apple. Some folks even add tags = ["manual"]
to *_library
targets so they won't be built if you run bazel build ...
@Keith much thanks for the pointer, going to look into this in the AM