bazel-ios / cocoapods-bazel

A Cocoapods plugin for automatically generating Bazel BUILD files
Apache License 2.0
110 stars 21 forks source link

sim_arm64 Slice missing for XCFrameworks #84

Closed sanju-naik closed 1 year ago

sanju-naik commented 1 year ago

Hi,

I am trying to Integrate FBSDKCoreKit (https://github.com/facebook/facebook-ios-sdk) Cocoapod into Bazel Project, FBSDKCoreKit is distributed as XCFramework, and when the plugin generates BUILD file its missing sim_arm64 in supported_archs .

Here is the generated BUILD file containing only simulator Slice for FBSDKCoreKit, As it can be seen sim_arm64 is missing supported_archs.

apple_framework(
    name = "FBSDKCoreKit",
    platforms = {"ios": "10.0"},
    vendored_xcframeworks = [
        {
            "name": "FBSDKCoreKit",
            "slices": [
                {
                    "identifier": "ios-arm64_i386_x86_64-simulator",
                    "platform": "ios",
                    "platform_variant": "simulator",
                    "supported_archs": [
                        "arm64",
                        "i386",
                        "x86_64",
                    ],
                    "path": "XCFrameworks/FBSDKCoreKit.xcframework/ios-arm64_i386_x86_64-simulator/FBSDKCoreKit.framework",
                    "build_type": {
                        "linkage": "dynamic",
                        "packaging": "framework",
                    },
                },
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//Pods/FBAEMKit",
        "//Pods/FBSDKCoreKit_Basics",
    ],
)

With this BUILD file, when I run bazel build --ios_multi_cpus=sim_arm64 //target , Build fails with a missing Slice error

Pods/FBSDKCoreKit/BUILD.bazel:3:16: configurable attribute "actual" in //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframeworkdefault_vfs doesn't match this configuration. Would a default condition help?

Conditions checked:
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-tvos_simulator_arm64
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-tvos_simulator_x86_64
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-ios_simulator_i386
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-ios_simulator_x86_64
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-ios_arm64
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-ios_armv7
 //Pods/FBSDKCoreKit:FBSDKCoreKit-import-FBSDKCoreKit.xcframework-tvos_arm64
jerrymarino commented 1 year ago

Hey @sanju-naik the build file looks valid and it's hard to tell why you hit the error. We've got a test case for a similar BUILD file inside of:

tests/ios/xcframeworks/Basic/BasicXCFramework/BUILD.bazel

This said, the test case in rules_ios is ran with --features apple.arm64_simulator_use_device_deps: a lot of the code was written when there wasn't many pods on Apple Silicon yet - is it possible there's a bug if you don't use the feature? The code should still give you the simulator slice - I'd suggest trying your invocation with:

bazel build --ios_multi_cpus=sim_arm64 --features apple.arm64_simulator_use_device_deps //target 
sanju-naik commented 1 year ago

Thank you @jerrymarino This worked.

I believe this flag --features apple.arm64_simulator_use_device_deps works with all CPU archs such as arm64 or x86_64 or sim_arm64, so its safe to add this to .bazelrc and use it as default build option?

jerrymarino commented 1 year ago

@sanju-naik you got it - glad that fixes it for you.

Yeah the feature is safe to use 100% of the time: you often just add it to the .bazelrc. It's definitely a rules_ios bug and something we should turn on by default / fix the bug by removing the disabled codepath.

sanju-naik commented 1 year ago

Perfect. Thank you!