bazelbuild / rules_apple

Bazel rules to build apps for Apple platforms.
Apache License 2.0
503 stars 261 forks source link

Can `build --enable_platform_specific_config` automatically detect the right APPLE_SDK_PLATFORM for build target? #2501

Open tinder-kaijing opened 1 month ago

tinder-kaijing commented 1 month ago

Hi,

When we upgrade Bazel from 6.x to 7.x, it seems that the flag build --apple_platform_type=ios no longer works. We expect to use the below config in .bazelrc, to detect the targets automatically. If the build target is ios_arm64, it will include all ios standard libraries. If the build target is "macos_arm64", it will include all macOS libraries.

build --enable_platform_specific_config
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain

However, likely it doesn't work that way. when we try to build an iOS build target, it still misses some standard ios libraries. for instance,

fatal error: 'UIKit/UIKit.h' file not found

import <UIKit/UIKit.h>

    ^~~~~~~~~~~~~~~

1 error generated. Error in child process '/usr/bin/xcrun'. 1

luispadron commented 1 month ago

As far as I understand --enable_platform_specific_config is for the host machine not the specific platform target.

You'd still need to use --apple_platform_type=ios if you want to build swift_library for iOS or use the packaging rules like ios_framework

This was recently documented to be more clear in rules_swift: https://github.com/bazelbuild/rules_swift/blob/master/doc/faq.md

luispadron commented 1 month ago

Also FWIW in Bazel 7 you should not need the flags you listed in the .bazelrc (that was only required for Bazel 6):

build --enable_platform_specific_config
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain

See: https://github.com/bazelbuild/apple_support?tab=readme-ov-file#bazel-7-setup

tinder-kaijing commented 1 month ago

As far as I understand --enable_platform_specific_config is for the host machine not the specific platform target.

You'd still need to use --apple_platform_type=ios if you want to build swift_library for iOS or use the packaging rules like ios_framework

This was recently documented to be more clear in rules_swift: https://github.com/bazelbuild/rules_swift/blob/master/doc/faq.md

Thanks.