tree: 19ce2eb452e2110ca781b2bb1d6c95efde3ad3f2 [path history] [tgz]
  1. AppleBinary.java
  2. AppleCrosstoolTransition.java
  3. AppleDebugOutputsInfo.java
  4. AppleDynamicFrameworkInfo.java
  5. AppleExecutableBinaryInfo.java
  6. AppleLinkingOutputs.java
  7. AppleStarlarkCommon.java
  8. ArtifactListAttribute.java
  9. BazelObjcStarlarkInternal.java
  10. BUILD
  11. CompilationArtifacts.java
  12. CompilationAttributes.java
  13. CompilationSupport.java
  14. IntermediateArtifacts.java
  15. Interspersing.java
  16. IterableWrapper.java
  17. J2ObjcAspect.java
  18. J2ObjcCommandLineOptions.java
  19. J2ObjcConfiguration.java
  20. J2ObjcEntryClassProvider.java
  21. J2ObjcLibrary.java
  22. J2ObjcLibraryBaseRule.java
  23. J2ObjcMappingFileProvider.java
  24. J2ObjcSource.java
  25. MultiArchBinarySupport.java
  26. MultiArchSplitTransitionProvider.java
  27. ObjcCommandLineOptions.java
  28. ObjcCommon.java
  29. ObjcCompilationContext.java
  30. ObjcConfiguration.java
  31. ObjcImportBaseRule.java
  32. ObjcLibraryBaseRule.java
  33. ObjcProvider.java
  34. ObjcProviderStarlarkConverters.java
  35. ObjcRuleClasses.java
  36. ObjcStarlarkInternal.java
  37. ObjcVariablesExtension.java
  38. README.md
  39. Value.java
src/main/java/com/google/devtools/build/lib/rules/objc/README.md

The Apple Rule Implementations:

The packages devtools/build/lib/rules/objc and devtools/build/lib/rules/apple implement the objc and ios Bazel rules.

Interfacing from Starlark

Information exchange between Starlark rules and native objc_* or ios_* rules occurs by three mechanisms:

  1. AppleToolchain:

AppleToolchain.java houses constants and static methods for use in rule implementations. It is accessed in Starlark through the global apple_common namespace:

def __impl(ctx):
    platform_dir = apple_common.apple_toolchain().platform_dir('iphoneos')
    sdk_dir = apple_common.apple_toolchain().sdk_dir()
  1. AppleConfiguration and ObjcConfiguration:

In Bazel, configuration fragments are used as containers for invocation-specific build information (that is, information that cannot always be derived strictly from BUILD files). The contents of these configurations can be inspected by looking at rules/objc/ObjcConfiguration.java and rules/apple/AppleConfiguration.java. To access a configuration fragment from Starlark, the fragment must be declared in the rule definition:

def __impl(ctx):
    cpu = ctx.fragments.apple.single_arch_cpu
my_rule = rule(
  implementation = __impl
  fragments = ['apple']
)
  1. ObjcProvider:

The ObjcProvider maps “keys” to NestedSet instances, where “keys” are singleton objects defined in ObjcProvider that identify a category of transitive information to be communicated between targets in a dependency chain.

Native objc/ios rules export ObjcProvider instances, which are made available to Starlark dependants:

def __impl(ctx):
    dep = ctx.attr.deps[0]
    objc_provider = dep.objc

The provider can be queried by accessing fields that correspond to ObjcProvider keys.

    libraries = objc_provider.library  # A Depset of Artifacts

A Starlark rule that is intended to be a dependency of native objc rules should export an ObjcProvider itself. An ObjcProvider is constructed using a constructor exposed on the apple_common namespace.

def __impl(ctx):
    define = 'some_define'
    objc_provider = apple_common.new_objc_provider(define=define)
    return struct(objc = objc_provider)

Arguments to new_objc_provider should correspond to ObjcProvider keys, and values should be Starlark sets that should be added to the provider. Other instances of ObjcProvider can also be used in provider construction.

def __impl(ctx):
    dep = ctx.attr.deps[0]
    define = 'some_define'
    objc_provider = apple_common.new_objc_provider(providers=[dep.objc], define=define)
    return struct(objc = objc_provider)