README.md

October 15, 2022 ยท View on GitHub

apple_linker_inputs

apple_linker_inputs(name, linker_inputs, linkopts)

Provides additional inputs to Apple rules' linker action.

Unlike C++ rules like cc_binary and cc_test, Apple rules don't have any mechanism to allow providing additional inputs to the linker action. This little rule helps mitigate that.

To use this rule in your BUILD files, load it with:

load("@rules_apple_line//apple:apple_linker_inputs.bzl", "apple_linker_inputs")

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
linker_inputsExtra files to be passed to the linker action.List of labelsoptional[]
linkoptsExtra flags to be passed to Clang's linker command. Subject to "Make" variable substitution and label expansion.List of stringsoptional[]

metal_library

metal_library(name, hdrs, includes, out, srcs)

Compiles Metal Shading Language source code into a Metal library. To use this rule in your BUILD files, load it with:

load("@rules_apple_line//apple:metal_library.bzl", "metal_library")

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
hdrsA list of headers that you need import to metal source.List of labelsoptional[]
includesA list of header search paths.List of stringsoptional[]
outAn output .metallib filename. Defaults to default.metallib if unspecified.Stringoptional"default.metallib"
srcsA list of .metal source files that will be compiled into the library.List of labelsrequired

pkg_dsym

pkg_dsym(name, mode, out, srcs, timestamp)

Creates a .dSYM.zip file given targets that produce dSYMs.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
modeSet the mode of files added by the srcs attribute.Stringoptional"0555"
outThe output filename.Labeloptional
srcsA list of executable targets that produce dSYM, and/or a list of imported dSYMs if they're prebuilt.List of labelsoptional[]
timestampThe time to use for every file in the zip, expressed as seconds since Unix Epoch, RFC 3339.

Due to limitations in the format of zip files, values before Jan 1, 1980 will be rounded up and the precision in the zip file is limited to a granularity of 2 seconds.
Integeroptional315532800

swiftgen

swiftgen(name, out, srcs, template_file, template_params)

Generates Swift code from the given resource files.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
outThe output Swift filename.Labelrequired
srcsThe list of input resource files.List of labelsrequired
template_fileThe template file which will be used to generate Swift code.Labelrequired
template_paramsAn optional dictionary of parameters that you want to pass to the template.Dictionary: String -> Stringoptional{}

apple_library

apple_library(kwargs)

Compiles and links Objective-C and Swift code into a static library.

To use this rule in your BUILD files, load it with:

load("@rules_apple_line//apple:apple_library.bzl", "apple_library")

See mixed_static_framework for the documentation of each attribute.

PARAMETERS

NameDescriptionDefault Value
kwargs

-

none

apple_preprocessed_plist

apple_preprocessed_plist(name, src, out, substitutions, kwargs)

PARAMETERS

NameDescriptionDefault Value
name

-

none
src

-

none
out

-

none
substitutions

-

none
kwargs

-

none

mixed_static_framework

mixed_static_framework(name, srcs, non_arc_srcs, hdrs, textual_hdrs, enable_modules, includes,
                       copts, objc_copts, swift_copts, use_defines, swiftc_inputs, objc_deps,
                       swift_deps, avoid_deps, deps, data, umbrella_header, visibility,
                       minimum_os_version, features, kwargs)

Builds and bundles a static framework for Xcode consumption or third-party distribution.

This supports Swift only targets and mixed language targets. If your target only contains Objective-C source code, use objc_static_framework rule instead.

This rule in general is very similar to build_bazel_rules_apple's ios_static_framework rule, with some differences:

  • It supports Swift as well as mixed Objective-C and Swift targets.
  • It supports bundling a swift_library target that depend transitively on any other swift_library targets. By default, it will not link any of its dependencies into the final framework binary - the same way Xcode does when it builds frameworks - which means you can prebuild your dependencies as static frameworks for Xcode consumption.
  • It supports header maps out of the box--you don't need to change your imports to make your code build with Bazel.
  • It always collects the Swift generated header and bundles a module.modulemap file. For a mixed language target, the module map file is an extended module map.
  • It bundles swiftmodule and swiftdoc files (ios_static_framework rule bundles swiftinterface instead of swiftmodule file).

This rule uses the native objc_library rule and rules_swift's swift_library in its implementation. Even if you're not building a static framework for Xcode consumption or third-party distribution, this can still be used as a convenient way to declare a library target that compiles mixed Objective-C and Swift source code.

The macro contains 3 underlying rules--given name is Greet:

  • Greet_swift: a swift_library target. This target has private visibility by default, hence it can't be a dependency of any other target. It should not be used directly.
  • GreetModule: a module_map target. This has the same visibility as Greet. The common use-case is using it in an objc_library's copts attribute to import the generated module map file (e.g. -fmodule-map-file=$(execpath //path/to/package:GreetModule)). This will be done automatically if the dependent target is also a mixed_static_framework target.
  • Greet: an objc_library target. This is the wrapper library target. This can be depended on any objc_library or swift_library target.

Examples

load("@rules_apple_line//apple:mixed_static_framework.bzl", "mixed_static_framework")

mixed_static_framework(
    name = "Mixed",
    srcs = glob([
        "*.m",
        "*.swift",
    ]),
    hdrs = glob(["*.h"]),
)

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target. This will be the name of the library target that the framework depends on. The framework target will be named ${name}Framework.none
srcsThe list of Objective-C and Swift source files to compile.none
non_arc_srcsThe Objective-C source files to compile that do not use ARC. Provide both srcs and non_arc_srcs explicitly if both kinds of source files should be included.[]
hdrsThe list of C, C++, Objective-C, and Objective-C++ header files published by this library to be included by sources in dependent rules. These headers describe the public interface for the library and will be made available for inclusion by sources in this rule or in dependent rules. Headers not meant to be included by a client of this library should be listed in the srcs attribute instead. These will be compiled separately from the source if modules are enabled.[]
textual_hdrsThe list of C, C++, Objective-C, and Objective-C++ files that are included as headers by source files in this rule or by users of this library. Unlike hdrs, these will not be compiled separately from the sources.[]
enable_modulesEnables clang module support (via -fmodules).

Note: This is True by default. Changing this to False might no longer work. This attribute is here because there are still targets which are referencing to it.
True
includesList of header search paths to add to this target and all depending targets. Unlike copts, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-iquote" flags to copts instead.

Usage of this is rarely necessary because all headers will be visible to their depended targets with the help of header maps.
[]
coptsAdditional compiler options that should be passed to clang and swiftc.[]
objc_coptsAdditional compiler options that should be passed to clang.[]
swift_coptsAdditional compiler options that should be passed to swiftc.[]
use_defines

-

None
swiftc_inputsAdditional files that are referenced using (rootpath...)</code>and<code>(rootpath ...)</code> and <code>(execpath ...) in attributes that support location expansion (e.g. copts).[]
objc_depsDependencies of the underlying objc_library target.[]
swift_depsDependencies of the underlying swift_library target.[]
avoid_depsA list of objc_library and swift_library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. By default this is the same as deps, that is none of the depependencies will be linked into the framework's binary. For example, providing an empty list ([]) here will result in a fully static link binary.None
depsDependencies of the both objc_library and swift_library targets.[]
dataThe list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework).[]
umbrella_headerAn optional single .h file to use as the umbrella header for this framework. Usually, this header will have the same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an umbrella header will be generated under the same name as this target.None
visibilityThe visibility specifications for this target.["//visibility:public"]
minimum_os_versionMinimum os version."11.0"
featuresFeatures of the underlying swift_library target.[]
kwargsAdditional arguments being passed through.none

objc_library

objc_library(kwargs)

Produces a static library from the given Objective-C source files.

A drop-in replacement of the native objc_library rule, with added supports for header maps and modules.

To use this rule in your BUILD files, load it with:

load("@rules_apple_line//apple:objc_library.bzl", "objc_library")

See objc_static_framework for the documentation of each attribute.

PARAMETERS

NameDescriptionDefault Value
kwargs

-

none

objc_static_framework

objc_static_framework(name, srcs, non_arc_srcs, hdrs, archives, deps, avoid_deps, data, use_defines,
                      module_name, textual_hdrs, includes, testonly, enable_modules,
                      minimum_os_version, pch, visibility, umbrella_header, kwargs)

Builds and bundles a Objective-C static framework for Xcode consumption or third-party distribution.

This rule in general is very similar to build_bazel_rules_apple's ios_static_framework rule, with support for modules and header maps out of the box--which means you don't need to change your imports to make your code build with Bazel. Note that, unlike build_bazel_rules_apple's ios_static_framework, by default, it will not link any of its dependencies into the final framework binary - the same way Xcode does when it builds frameworks.

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target. This will be the name of the objc_library target that the framework depends on. The framework target will be named ${name}Framework.none
srcsThe Objective-C source files to compile.[]
non_arc_srcsThe Objective-C source files to compile that do not use ARC. Provide both srcs and non_arc_srcs explicitly if both kinds of source files should be included.[]
hdrsThe list of C, C++, Objective-C, and Objective-C++ header files published by this library to be included by sources in dependent rules. These headers describe the public interface for the library and will be made available for inclusion by sources in this rule or in dependent rules. Headers not meant to be included by a client of this library should be listed in the srcs attribute instead. These will be compiled separately from the source if modules are enabled.[]
archivesThe list of .a files provided to Objective-C targets that depend on this target.[]
depsDependencies of the objc_library target being compiled.[]
avoid_depsA list of objc_library and swift_library targets on which this framework depends in order to compile, but you don't want to link to the framework binary. Defaults to deps if not specified.None
dataThe list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework).[]
use_defines

-

None
module_nameThe name of the module being built. If not provided, the name is used.None
textual_hdrsThe list of C, C++, Objective-C, and Objective-C++ files that are included as headers by source files in this rule or by users of this library. Unlike hdrs, these will not be compiled separately from the sources.[]
includesList of header search paths to add to this target and all depending targets. Unlike copts, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-iquote" flags to copts instead.[]
testonlyIf True, only testonly targets (such as tests) can depend on the objc_library target. The default is False.False
enable_modulesEnables clang module support (via -fmodules). Setting this to True will allow you to @import system headers and other targets).False
minimum_os_versionThe minimum OS version supported by the framework."11.0"
pchHeader file to prepend to every source file being compiled (both arc and non-arc). Use of pch files is actively discouraged in BUILD files, and this should be considered deprecated. Since pch files are not actually precompiled this is not a build-speed enhancement, and instead is just a global dependency. From a build efficiency point of view you are actually better including what you need directly in your sources where you need it.None
visibilityThe visibility specifications for this target.["//visibility:public"]
umbrella_headerAn optional single .h file to use as the umbrella header for this framework. Usually, this header will have the same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an umbrella header will be generated under the same name as this target.None
kwargsAdditional arguments being passed through to the underlying objc_library rule.none

swift_library

swift_library(kwargs)

Compiles and links Swift code into a static library and Swift module.

A drop-in replacement of the official swift_library rule, with added supports for header maps, and better integration with other rules in this repository.

To use this rule in your BUILD files, load it with:

load("@rules_apple_line//apple:objc_library.bzl", "objc_library")

See swift_static_framework for the documentation of each attribute.

PARAMETERS

NameDescriptionDefault Value
kwargs

-

none

swift_static_framework

swift_static_framework(name, srcs, copts, use_defines, swiftc_inputs, deps, avoid_deps, data,
                       visibility, minimum_os_version, features, kwargs)

Builds and bundles a Swift static framework for Xcode consumption or third-party distribution.

This rule in general is very similar to build_bazel_rules_apple's ios_static_framework rule, with some differences:

  • It supports bundling a swift_library target that depend transitively on any other swift_library targets. By default, it will not link any of its dependencies into the final framework binary - the same way Xcode does when it builds frameworks - which means you can prebuild your dependencies as static frameworks for Xcode consumption.
  • It supports header maps out of the box--you don't need to change your imports to make your code build with Bazel.
  • It always collects the Swift generated header and bundles a module.modulemap file.
  • It bundles swiftmodule and swiftdoc files (ios_static_framework rule bundles swiftinterface instead of swiftmodule file).

Under the hood, this uses an objc_library target to wrap a swift_library target -- so by a sense, it's still a mixed Obj-C and Swift target - to make use of objc_library's configuration transition.

Examples

load("@rules_apple_line//apple:swift_static_framework.bzl", "swift_static_framework")

swift_static_framework(
    name = "MyLibrary",
    srcs = glob(["**/*.swift"]),
)

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target. This will be the name of the library target that the framework depends on. The framework target will be named ${name}Framework.none
srcsThe list of Swift source files to compile.none
coptsAdditional compiler options that should be passed to swiftc.[]
use_defines

-

None
swiftc_inputsAdditional files that are referenced using (rootpath...)</code>and<code>(rootpath ...)</code> and <code>(execpath ...) in attributes that support location expansion (e.g. copts).[]
depsA list of targets that are dependencies of the target being built. Note that, by default, none of these and all of their transitive dependencies will be linked into the final binary when building the ${name}Framework target.[]
avoid_depsA list of objc_library and swift_library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. By default this is the same as deps, that is none of the depependencies will be linked into the framework's binary. For example, providing an empty list ([]) here will result in a fully static link binary.None
dataThe list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework).[]
visibilityThe visibility specifications for this target.["//visibility:public"]
minimum_os_version

-

"11.0"
featuresFeatures of the underlying swift_library target.[]
kwargsAdditional arguments being passed through.none