Skip to content

Request: Specify CPU arch in arguments for objc_library #10061

Closed

Description

@rajivshah3

Description of the feature request:

Can it possible to specify the target CPU arch in the BUILD file for a objc_library? For example:

objc_library(
    name = "myLib",
    srcs = ["Interface.m"],
    hdrs = ["Interface.h"],
    ios_multi_cpus = ["armv7", "arm64"],
)

Feature requests: what underlying problem are you trying to solve with this feature?

We want to make a universal (aka "fat") framework which includes device and simulator architectures (i386, x86_64, armv7, and arm64). Currently, we build it with the following command:

bazel build //mobile/ios:myFramework --ios_multi_cpus=i386,x86_64,armv7,arm64

We recently added NEON extensions which are specific to ARM processors, such as the ones found in physical iPhone devices. To do this, we add --define ptrit_platform=neon to the bazel command so that a certain macro is defined. However, when attempting to compile with the following command, we get errors because NEON extensions are not supported on i386 and x86_64 architectures:

bazel build //mobile/ios:myFramework --ios_multi_cpus=i386,x86_64,armv7,arm64 --define ptrit_platform=neon
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include/arm_neon.h:28:2: error: "NEON support not enabled"
#error "NEON support not enabled"
 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include/arm_neon.h:48:24: error: 'neon_vector_type' attribute is not supported for this target
typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t;
                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include/arm_neon.h:49:24: error: 'neon_vector_type' attribute is not supported for this target
typedef __attribute__((neon_vector_type(16))) int8_t int8x16_t;
...

While we could accomplish this by using individual commands (since the ios_multi_cpus argument can only be set on the command line) and then assembling the universal library using the lipo command, it would be ideal to use Bazel rules for this so everything can be stored in a BUILD file. As an example:

objc_library(
    name = "myLib_iphoneos",
    srcs = ["Interface.m"],
    hdrs = ["Interface.h"],
    defines = ["ptrit_platform=neon"],
    ios_multi_cpus = ["armv7", "arm64"], # New option
)

objc_library(
    name = "myLib_iphonesimulator",
    srcs = ["Interface.m"],
    hdrs = ["Interface.h"],
    defines = ["ptrit_platform=64"],
    ios_multi_cpus = ["i386", "x86_64"], # New option
)

ios_static_framework(
    name = "myFramework",
    hdrs = ["Interface.h"],
    bundle_name = "MyFramework",
    minimum_os_version = "9.0",
    deps = [":myLib_iphoneos", ":myLib_iphonesimulator"],
)

What operating system are you running Bazel on?

macOS Catalina 10.15.1 Beta

What's the output of bazel info release?

release 0.29.1-homebrew

Have you found anything relevant by searching the web?

Nope. I tried implementing this myself but I'm not entirely sure how/where to make the appropriate change (maybe src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java?)

Activity

  1. changed the title [-]Specify CPU arch in arguments for objc_library[/-] [+]Request: Specify CPU arch in arguments for objc_library[/+] on Oct 18, 2019
  2. added
    z-team-Apple
    untriaged
    on Oct 23, 2019
  3. rupertks commented on Oct 24, 2019

    @rupertks
    Contributor

    Have you tried writing a custom Starlark rule/macro to do this? Just wondering if there is some reason that wouldn't work.

  4. rupertks commented on Oct 24, 2019

    @rupertks
    Contributor
  5. rajivshah3 commented on Oct 24, 2019

    @rajivshah3
    Author
  6. rupertks commented on Oct 24, 2019

    @rupertks
    Contributor

    Thanks! If you were able to get a Starlark rule/macro working that might also be useful to others.

    (Also this issue might actually belong at https://github.com/bazelbuild/rules_apple)

  7. rajivshah3 commented on Oct 24, 2019

    @rajivshah3
    Author

    If you were able to get a Starlark rule/macro working that might also be useful to others.

    Yep, if I make one I'll post it here

    Also this issue might actually belong at https://github.com/bazelbuild/rules_apple

    I almost opened an issue there but I felt that it should be opened here instead as objc_library is a built-in rule and not part of rules_apple

  8. added
    team-Configurability
    and removed
    z-team-Apple
    on Oct 31, 2019
  9. jmmv commented on Oct 31, 2019

    @jmmv
    Contributor

    This really feels like an issue for the configurability team. At least to get guidance on what to do.

  10. katre commented on Nov 8, 2019

    @katre
    Collaborator

    This is part of the configurability roadmap, tracked specifically as flagless multiplatform builds.

    Short answer: we want to support this, but we're not ready yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    team-Configurabilityuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions