为 Bazel 构建设置 MacOS 目标版本

Setting MacOS target version for Bazel build

我正在尝试在 MacOS 11.4 上构建 TensorFlow Lite C 库。我需要构建的库能够 运行 在 MacOS 10.13 或更高版本上。然而,构建工具链中的某些东西将目标 OS 设置为 11.3,因此 -s 打印的完整编译命令看起来像这样

(cd /private/var/tmp/_bazel_ojs/8ce6bb5f0f6d53a52ea9c48238c2c3a8/execroot/org_tensorflow && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=11.3 \
    PATH=/Users/ojs/Library/Caches/bazelisk/downloads/bazelbuild/bazel-3.7.2-darwin-x86_64/bin:/Users/ojs/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/ojs/Library/Android/sdk/platform-tools \
    TF2_BEHAVIOR=1 \
    XCODE_VERSION_OVERRIDE=12.5.0.12E262 \
  external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG '-DNS_BLOCK_ASSERTIONS=1' '-std=c++11' -iquote external/ruy -iquote bazel-out/darwin-opt/bin/external/ruy -iquote external/cpuinfo -iquote bazel-out/darwin-opt/bin/external/cpuinfo -iquote external/clog -iquote bazel-out/darwin-opt/bin/external/clog -Ibazel-out/darwin-opt/bin/external/cpuinfo/_virtual_includes/cpuinfo -Ibazel-out/darwin-opt/bin/external/clog/_virtual_includes/clog -MD -MF bazel-out/darwin-opt/bin/external/ruy/ruy/_objs/frontend/frontend.d '-DCLOG_VISIBILITY=' '-frandom-seed=bazel-out/darwin-opt/bin/external/ruy/ruy/_objs/frontend/frontend.o' -isysroot __BAZEL_XCODE_SDKROOT__ -F__BAZEL_XCODE_SDKROOT__/System/Library/Frameworks -F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/MacOSX.platform/Developer/Library/Frameworks '-mmacosx-version-min=11.3' -DGRPC_BAZEL_BUILD -w -mavx '-std=c++14' -Wall -Wextra -Wc++14-compat -Wundef -O3 -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/ruy/ruy/frontend.cc -o bazel-out/darwin-opt/bin/external/ruy/ruy/_objs/frontend/frontend.o)

在命令行上使用--copt='-mmacosx-version-min=10.13'生成的编译命令在参数列表中同时包含'-mmacosx-version-min=11.3''-mmacosx-version-min=10.13',生成的二进制文件似乎有更高的要求。将 APPLE_SDK_VERSION_OVERRIDE 设置为环境变量或使用 --action_env 不会更改构建日志中显示的值。我在项目的 bazel 构建文件中找不到 APPLE_SDK_VERSION_OVERRIDE 的任何实例。如何设置目标平台?

工作方式是 Bazel 命令行选项 --macos_minimum_os(或相关 --macos_minimum_os)。

如果您知道要搜索什么,它就在文档中,但 Google 显然无法发现。我通过阅读 Bazel 源代码找到它。