Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Latest commit

 

History

History
executable file
·
442 lines (306 loc) · 30.9 KB

README.md

File metadata and controls

executable file
·
442 lines (306 loc) · 30.9 KB

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

Name Description Type Mandatory Default
name A unique name for this target. Name required
linker_inputs Extra files to be passed to the linker action. List of labels optional []
linkopts Extra flags to be passed to Clang's linker command. Subject to "Make" variable substitution and label expansion. List of strings optional []

metal_library

metal_library(name, 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

Name Description Type Mandatory Default
name A unique name for this target. Name required
out An output .metallib filename. Defaults to default.metallib if unspecified. String optional "default.metallib"
srcs A list of .metal source files that will be compiled into the library. List of labels required

module_map

module_map(name, add_to_provider, deps, hdrs, module_name, textual_hdrs)

Generates a module map given a list of header files.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
add_to_provider Whether to add the generated module map to the returning provider. Targets imported via apple_static_framework_import or apple_dynamic_framework_import already have their module maps provided to swift_library targets depending on them. Set this to False in that case to avoid duplicate modules. Boolean optional True
deps The list of swift_library targets. A ${module_name}.Swift submodule will be generated if non-empty. List of labels optional []
hdrs The list of C, C++, Objective-C, and Objective-C++ header files used to construct the module map. List of labels optional []
module_name The name of the module. String required
textual_hdrs The list of C, C++, Objective-C, and Objective-C++ header files used to construct the module map. Unlike hdrs, these will be declared as 'textual header' in the module map. List of labels optional []

pkg_dsym

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

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

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
mode Set the mode of files added by the srcs attribute. String optional "0555"
out The output filename. Label optional
srcs A list of executable targets that produce dSYM, and/or a list of imported dSYMs if they're prebuilt. List of labels optional []
timestamp The 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.
Integer optional 315532800

swiftgen

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

Generates Swift code from the given resource files.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
out The output Swift filename. Label required
srcs The list of input resource files. List of labels required
template_file The template file which will be used to generate Swift code. Label required
template_params An optional dictionary of parameters that you want to pass to the template. Dictionary: String -> String optional {}

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

Name Description Default Value
kwargs

-

none

apple_preprocessed_plist

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

PARAMETERS

Name Description Default 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, swiftc_inputs, objc_deps, swift_deps,
                       avoid_deps, deps, data, umbrella_header, visibility, minimum_os_version,
                       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

Name Description Default Value
name A 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
srcs The list of Objective-C and Swift source files to compile. none
non_arc_srcs The 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. []
hdrs The 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_hdrs The 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_modules Enables 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
includes List 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.
[]
copts Additional compiler options that should be passed to clang and swiftc. []
objc_copts Additional compiler options that should be passed to clang. []
swift_copts Additional compiler options that should be passed to swiftc. []
swiftc_inputs Additional files that are referenced using $(rootpath ...) and $(execpath ...) in attributes that support location expansion (e.g. copts). []
objc_deps Dependencies of the underlying objc_library target. []
swift_deps Dependencies of the underlying swift_library target. []
avoid_deps A 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
deps Dependencies of the both objc_library and swift_library targets. []
data The 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_header An 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
visibility The visibility specifications for this target. ["//visibility:public"]
minimum_os_version Minimum os version. "11.0"
kwargs Additional 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

Name Description Default Value
kwargs

-

none

objc_static_framework

objc_static_framework(name, srcs, non_arc_srcs, hdrs, archives, deps, avoid_deps, data, 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

Name Description Default Value
name A 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
srcs The Objective-C source files to compile. []
non_arc_srcs The 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. []
hdrs The 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. []
archives The list of .a files provided to Objective-C targets that depend on this target. []
deps Dependencies of the objc_library target being compiled. []
avoid_deps A 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
data The 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). []
module_name The name of the module being built. If not provided, the name is used. None
textual_hdrs The 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. []
includes List 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. []
testonly If True, only testonly targets (such as tests) can depend on the objc_library target. The default is False. False
enable_modules Enables clang module support (via -fmodules). Setting this to True will allow you to @import system headers and other targets). False
minimum_os_version The minimum OS version supported by the framework. "11.0"
pch Header 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
visibility The visibility specifications for this target. ["//visibility:public"]
umbrella_header An 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
kwargs Additional 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

Name Description Default Value
kwargs

-

none

swift_static_framework

swift_static_framework(name, srcs, copts, swiftc_inputs, deps, avoid_deps, data, visibility,
                       minimum_os_version, 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

Name Description Default Value
name A 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
srcs The list of Swift source files to compile. none
copts Additional compiler options that should be passed to swiftc. []
swiftc_inputs Additional files that are referenced using $(rootpath ...) and $(execpath ...) in attributes that support location expansion (e.g. copts). []
deps A 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_deps A 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
data The 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). []
visibility The visibility specifications for this target. ["//visibility:public"]
minimum_os_version

-

"11.0"
kwargs Additional arguments being passed through. none