Search code examples
objective-cmacosbazel

Where does bazel look for OSX SDKs (and what to do if it's not finding them)?


I have an objc_library rule that tells me that it can't find any SDK framework header (this problem is not specific to IOKit, I can't find any frameworks at all).

#import <IOKit/IOKitLib.h>

fatal error: 'IOKit/IOKitLib.h' file not found

I already have "IOKit" in my sdk_frameworks. If I take a peek in /System/Library/Frameworks/IOKit.framework, I find that there is no directory Headers which would contain this file. Perhaps no surprise if that's where Bazel is looking.

If I look a little harder, I find more results for the SDK.

$ find /Applications/Xcode.app/ -name IOKit.framework

/Applications/Xcode.app//Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/IOKit.framework
/Applications/Xcode.app//Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/IOKit.framework
/Applications/Xcode.app//Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/IOKit.framework
/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/IOKit.framework
/Applications/Xcode.app//Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/Frameworks/IOKit.framework
/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/System/Library/Frameworks/IOKit.framework

I would think that this is the one I want, since I'm developing for MacOSX.

/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/IOKit.framework

Can I tell Bazel to use that SDK? Should I have to? How can I figure out where Bazel is looking for these things? I'm pretty familiar with using Bazel, but I'm really not sure how to debug when the most basic of things is failing.

Here is the simplest example that fails.

BUILD:

objc_library(
    name = "test",
    srcs = ["test.cpp"],
    copts = ["-ObjC++"],
    sdk_frameworks = ["IOKit"],
)

// test.cpp

#import <IOKit/IOKitLib.h>

I posted this on bazel-discuss, but it isn't getting much traction. I'm using Bazel 0.5.2. https://groups.google.com/forum/#!topic/bazel-discuss/HhAjKblwHwk


Solution

  • Resolved in the bazel-discuss thread, but I'll summarize here:

    The issue you are finding here is most likely because IOKIt is a MacOS-only SDK, and you're building this library for iPhoneSimulator. (I think the former is the case, anyway. It looks like there is indeed an IOKit.framework directory under iPhoneSimulator9.3.sdk, but it doesn't include headers -- I'm not sure what the point of that is)

    Correctly building the library for MacOS is key here and should fix your issues. You can either do that by depending on this library via an apple_binary with platform_type="macos", or you can tailor command line flags to this end. I believe --apple_platform_type=macos --cpu=darwin_x86_64 should do the trick