Skip to content

Latest commit

 

History

History
143 lines (102 loc) · 6.42 KB

rules.md

File metadata and controls

143 lines (102 loc) · 6.42 KB

Helper rules for Apple platforms

On this page:

apple_genrule

apple_genrule(name, srcs, outs, cmd, executable, message, no_sandbox, tools)

Genrule which provides Apple specific environment and make variables.

This mirrors the native genrule except that it provides a different set of make variables. This rule will only run on a Mac.

Example of use:

load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")

apple_genrule(
    name = "world",
    outs = ["hi"],
    cmd = "touch $@",
)

This rule also does location expansion, much like the native genrule. For example, $(location hi) may be used to refer to the output in the above example.

The set of make variables that are supported for this rule:

  • OUTS: The outs list. If you have only one output file, you can also use $@.
  • SRCS: The srcs list (or more precisely, the pathnames of the files corresponding to labels in the srcs list). If you have only one source file, you can also use $<.
  • <: srcs, if it's a single file.
  • @: outs, if it's a single file.
  • @D: The output directory. If there is only one filename in outs, this expands to the directory containing that file. If there are multiple filenames, this variable instead expands to the package's root directory in the genfiles tree, even if all the generated files belong to the same subdirectory.

The following environment variables are defined when the rule is executed:

  • DEVELOPER_DIR: The base developer directory as defined on Apple architectures, most commonly used in invoking Apple tools such as xcrun.
  • SDKROOT: The base SDK directory as defined on Apple architectures, most commonly used in invoking Apple tools such as xcrun.

NOTE: DEVELOPER_DIR and SDKROOT are environment variables and not make variables. To refer to them in cmd you must use environment variable syntax (i.e. using $$). Example: cmd = "xcrun --sdkroot $$SDKROOT clang...

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs A list of inputs for this rule, such as source files to process. List of labels optional []
outs A list of files generated by this rule. If the executable flag is set, outs must contain exactly one label. List of labels required
cmd The command to run. Subject the variable substitution. String required
executable Declare output to be executable. Setting this flag to 1 means the output is an executable file and can be run using the run command. The genrule must produce exactly one output in this case. Boolean optional False
message A progress message to be reported as the rule runs. String optional ""
no_sandbox If the sandbox should be disabled when the action is run. Boolean optional False
tools A list of tool dependencies for this rule, they will be available when the action is run. List of labels optional []

toolchain_substitution

toolchain_substitution(name, src, var_name)

Register a subsitution, from a variable to a file, for use in arguments in a target's attributes. Useful for passing custom tools to a compile or link.

Example:

load("@build_bazel_apple_support//rules:toolchain_substitution.bzl", "toolchain_substitution")

toolchain_substitution(
    name = "resource_rules",
    src = "resource_rules.plist",
    var_name = "RULES",
)

ios_application(
    ...
    codesignopts = ["--resource-rules=$(RULES)"],
    codesign_inputs = [":resource_rules"],
    toolchains = [":resource_rules"],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
src Source file to substitute Label required
var_name Name of the variable to substitute, ex: FOO String required

universal_binary

universal_binary(name, binary)

This rule produces a multi-architecture ("fat") binary targeting Apple macOS platforms regardless of the architecture of the macOS host platform. The lipo tool is used to combine built binaries of multiple architectures. For non-macOS platforms, this simply just creates a symbolic link of the input binary.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
binary Target to generate a 'fat' binary from. Label required