bazel 在哪里寻找 OSX SDK(如果找不到它们该怎么办)?
Where does bazel look for OSX SDKs (and what to do if it's not finding them)?
我有一个objc_library规则告诉我它找不到任何SDK框架header(这个问题不是IOKit特有的,我根本找不到任何框架) .
#import <IOKit/IOKitLib.h>
致命错误:'IOKit/IOKitLib.h' 找不到文件
我的 sdk_frameworks 中已经有 "IOKit"。如果我查看 /System/Library/Frameworks/IOKit.framework,我会发现没有包含此文件的目录 Headers。如果那是 Bazel 正在寻找的地方,也许就不足为奇了。
如果我再仔细一点,我会找到更多关于 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
我认为这就是我想要的,因为我正在为 MacOSX 开发。
/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/IOKit.framework
我可以告诉 Bazel 使用那个 SDK 吗?我应该这样做吗?我怎样才能弄清楚 Bazel 在哪里寻找这些东西?我对使用 Bazel 非常熟悉,但我真的不确定在最基本的事情失败时如何调试。
这是失败的最简单示例。
构建:
objc_library(
name = "test",
srcs = ["test.cpp"],
copts = ["-ObjC++"],
sdk_frameworks = ["IOKit"],
)
// test.cpp
#import <IOKit/IOKitLib.h>
我在 bazel-discuss 上发布了这篇文章,但关注度不高。我正在使用 Bazel 0.5.2。
https://groups.google.com/forum/#!topic/bazel-discuss/HhAjKblwHwk
已在 bazel-discuss 线程中解决,但我将在此处进行总结:
您在这里发现的问题很可能是因为 IOKIt 是一个仅限 MacOS 的 SDK,而您正在为 iPhoneSimulator 构建这个库。
(反正我觉得是前者,iPhoneSimulator9.3.sdk下好像确实有一个IOKit.framework目录,但是里面没有header——不知道有什么意义其中是)
正确构建适用于 MacOS 的库是这里的关键,应该可以解决您的问题。您可以通过 apple_binary
和 platform_type="macos"
依赖此库来完成此操作,或者您可以为此定制命令行标志。我相信 --apple_platform_type=macos --cpu=darwin_x86_64
应该可以解决问题
我有一个objc_library规则告诉我它找不到任何SDK框架header(这个问题不是IOKit特有的,我根本找不到任何框架) .
#import <IOKit/IOKitLib.h>
致命错误:'IOKit/IOKitLib.h' 找不到文件
我的 sdk_frameworks 中已经有 "IOKit"。如果我查看 /System/Library/Frameworks/IOKit.framework,我会发现没有包含此文件的目录 Headers。如果那是 Bazel 正在寻找的地方,也许就不足为奇了。
如果我再仔细一点,我会找到更多关于 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
我认为这就是我想要的,因为我正在为 MacOSX 开发。
/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/IOKit.framework
我可以告诉 Bazel 使用那个 SDK 吗?我应该这样做吗?我怎样才能弄清楚 Bazel 在哪里寻找这些东西?我对使用 Bazel 非常熟悉,但我真的不确定在最基本的事情失败时如何调试。
这是失败的最简单示例。
构建:
objc_library(
name = "test",
srcs = ["test.cpp"],
copts = ["-ObjC++"],
sdk_frameworks = ["IOKit"],
)
// test.cpp
#import <IOKit/IOKitLib.h>
我在 bazel-discuss 上发布了这篇文章,但关注度不高。我正在使用 Bazel 0.5.2。 https://groups.google.com/forum/#!topic/bazel-discuss/HhAjKblwHwk
已在 bazel-discuss 线程中解决,但我将在此处进行总结:
您在这里发现的问题很可能是因为 IOKIt 是一个仅限 MacOS 的 SDK,而您正在为 iPhoneSimulator 构建这个库。 (反正我觉得是前者,iPhoneSimulator9.3.sdk下好像确实有一个IOKit.framework目录,但是里面没有header——不知道有什么意义其中是)
正确构建适用于 MacOS 的库是这里的关键,应该可以解决您的问题。您可以通过 apple_binary
和 platform_type="macos"
依赖此库来完成此操作,或者您可以为此定制命令行标志。我相信 --apple_platform_type=macos --cpu=darwin_x86_64
应该可以解决问题