Skip to main content

apple_library

An apple_library() rule represents a set of Objective-C/C++/Swift source files and is similar to a cxx_library() rule with which it shares many attributes. In addition to those common attributes, apple_library() has a some additional attributes that are specific to binaries intended to be built using the Apple toolchain. Note, however, that apple_library() and cxx_library() differ in the way that they import header files, in order to better accommodate existing conventions. See the sections for the headers and exported_headers attributes for more details.

Details

Buck enables you to override components of the Apple toolchain with alternate tools, either from the Xcode search paths or from directories that you specify. See .buckconfig and .buckconfig for more information.

Function Signature

def apple_library(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_apple_toolchain: str = "gh_facebook_buck2_shims_meta//:apple-default",
_apple_tools: str = "prelude//apple/tools:apple-tools",
_apple_xctoolchain: str = "gh_facebook_buck2_shims_meta//:apple-xctoolchain",
_apple_xctoolchain_bundle_id: str = "gh_facebook_buck2_shims_meta//:apple-xctoolchain-bundle-id",
_archive_objects_locally_override: None | bool = None,
_dsymutil_extra_flags: list[str],
_dsymutil_verify_dwarf: str,
_enable_library_evolution: bool = select({"prelude//features/apple:swift_library_evolution_enabled": True, "DEFAULT": False}),
_meta_apple_library_validation_enabled: bool = False,
_skip_swift_incremental_outputs: bool = False,
_stripped_default: bool = False,
_swift_enable_testing: bool = select({"prelude//features/apple:swift_enable_testing_enabled": True, "DEFAULT": False}),
allow_cache_upload: None | bool = None,
attrs_validators: None | list[str] = None,
bridging_header: None | str = None,
can_be_asset: None | bool = None,
compiler_flags: list[str] = [],
contacts: list[str] = [],
cxx_runtime_type: None | str = None,
default_host_platform: None | str = None,
default_platform: None | str = None,
defaults: dict[str, str] = {},
deps: list[str] = [],
devirt_enabled: bool = False,
diagnostics: dict[str, str] = {},
dist_thin_lto_codegen_flags: list[str] = [],
dsym_uses_parallel_linker: bool = select({"prelude//features/apple:dsym_uses_parallel_linker_enabled": True, "DEFAULT": False}),
enable_cxx_interop: bool = False,
enable_distributed_thinlto: bool = select({"prelude//build_mode/constraints:distributed-thin-lto-enabled": True, "DEFAULT": False}),
enable_library_evolution: None | bool = None,
enable_private_swift_module: bool = False,
executable_name: None | str = None,
exported_deps: list[str] = [],
exported_header_style: str = "local",
exported_headers: list[str] | dict[str, str] = [],
exported_lang_platform_preprocessor_flags: dict[str, list[(str, list[str])]] = {},
exported_lang_preprocessor_flags: dict[str, list[str]] = {},
exported_linker_flags: list[str] = [],
exported_platform_deps: list[(str, list[str])] = [],
exported_platform_headers: list[(str, list[str] | dict[str, str])] = [],
exported_platform_linker_flags: list[(str, list[str])] = [],
exported_platform_preprocessor_flags: list[(str, list[str])] = [],
exported_post_linker_flags: list[str] = [],
exported_post_platform_linker_flags: list[(str, list[str])] = [],
exported_preprocessor_flags: list[str] = [],
extra_xcode_files: list[str] = [],
extra_xcode_sources: list[str] = [],
fat_lto: bool = False,
focused_list_target: None | str = None,
force_static: None | bool = None,
frameworks: list[str] = [],
header_mode: None | str = None,
header_namespace: None | str = None,
header_path_prefix: None | str = None,
headers: list[str] | dict[str, str] = [],
headers_as_raw_headers_mode: None | str = None,
include_directories: list[str] = [],
info_plist: None | str = None,
info_plist_substitutions: dict[str, str] = {},
labels: list[str] = [],
lang_compiler_flags: dict[str, list[str]] = {},
lang_platform_compiler_flags: dict[str, list[(str, list[str])]] = {},
lang_platform_preprocessor_flags: dict[str, list[(str, list[str])]] = {},
lang_preprocessor_flags: dict[str, list[str]] = {},
libraries: list[str] = [],
licenses: list[str] = [],
link_execution_preference: None | str = None,
link_group: None | str = None,
link_group_map: None | str | list[(str, list[(None | str | list[None | str], str, None | str | list[str], None | str)], None | dict[str, typing.Any])] = None,
link_ordering: None | str = None,
link_style: None | str = None,
link_whole: None | bool = None,
linker_extra_outputs: list[str] = [],
linker_flags: list[str] = [],
modular: bool = False,
module_name: None | str = None,
module_requires_cxx: bool = False,
platform_compiler_flags: list[(str, list[str])] = [],
platform_deps: list[(str, list[str])] = [],
platform_headers: list[(str, list[str] | dict[str, str])] = [],
platform_linker_flags: list[(str, list[str])] = [],
platform_preprocessor_flags: list[(str, list[str])] = [],
platform_srcs: list[(str, list[str | (str, list[str])])] = [],
post_linker_flags: list[str] = [],
post_platform_linker_flags: list[(str, list[str])] = [],
precompiled_header: None | str = None,
preferred_linkage: str = "any",
prefix_header: None | str = None,
preprocessor_flags: list[str] = [],
propagated_target_sdk_version: None | str = None,
public_framework_headers: list[str] | dict[str, str] = [],
public_include_directories: list[str] = [],
public_system_include_directories: list[str] = [],
raw_headers: list[str] = [],
raw_headers_as_headers_mode: None | str = None,
reexport_all_header_dependencies: None | bool = None,
sdk_modules: list[str] = [],
serialize_debugging_options: None | bool = None,
shared_library_macho_file_type: str = "dylib",
soname: None | str = None,
srcs: list[str | (str, list[str])] = [],
static_library_basename: None | str = None,
stripped: None | bool = None,
supported_platforms_regex: None | str = None,
supports_header_symlink_subtarget: bool = False,
supports_merged_linking: None | bool = None,
supports_shlib_interfaces: bool = True,
swift_compilation_mode: str = "wmo",
swift_compiler_flags: list[str] = [],
swift_incremental_file_hashing: bool = False,
swift_interface_compilation_enabled: bool = True,
swift_macro_deps: list[str] = [],
swift_module_skip_function_bodies: bool = True,
swift_package_name: None | str = None,
swift_version: None | str = None,
target_sdk_version: None | str = None,
thin_lto: bool = False,
use_archive: None | bool = None,
use_submodules: bool = True,
uses_cxx_explicit_modules: bool = False,
uses_explicit_modules: bool = False,
uses_modules: bool = False,
validation_deps: list[str] = [],
) -> None

Parameters

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • allow_cache_upload: (defaults to: None)

    Whether to allow uploading the output of this rule to be uploaded to cache when the action is executed locally if the configuration allows (i.e. there is a cache configured and the client has permission to write to it).

  • compiler_flags: (defaults to: [])

    Flags to use when compiling any of the above sources (which require compilation).

  • exported_deps: (defaults to: [])

    Dependencies that will also appear to belong to any rules that depend on this one. This has two effects: * Exported dependencies will also be included in the link line of dependents of this rules, but normal dependencies will not. * When reexport_all_header_dependencies = False, only exported headers of the rules specified here are re-exported.

  • exported_headers: (defaults to: [])

    The set of header files that are made available for inclusion to the source files in this target and all targets that transitively depend on this one. These should be specified as either a list of header files or a dictionary of header names to header files. The header names can contain forward slashes (/). If a list of header files is specified, the headers can be imported with #import "$HEADER_PATH_PREFIX/$HEADER_NAME" or, if a header file that belongs to the same rule is being imported, with #import "$HEADER_NAME", where $HEADER_PATH_PREFIX is the value of the target's header_path_prefix attribute, and $HEADER_NAME is the filename of the header file. If a dictionary is specified, each header can be imported with #import "$HEADER_NAME", where $HEADER_NAME is the key corresponding to this file. In this case, the header_path_prefix attribute is ignored. In either case, quotes in the import statements can be replaced with angle brackets.

  • exported_linker_flags: (defaults to: [])

    Flags to add to the linker command line when the output from this rule, or the output from any rule that transitively depends on this rule, is used in a link operation.

  • exported_platform_linker_flags: (defaults to: [])

    Platform-specific linker flags for this rule and for all rules that transitively depend on this rule. This argument is specified as a list of pairs where the first element in each pair is an un-anchored regex against which the platform name is matched. The regex should use java.util.regex.Pattern syntax. The second element in each pair is a list of linker flags. If the regex matches the platform, these flags are added to the linker command line when the output from this rule, or the output from any rule that transitively depends on this rule, is used in a link operation.

  • extra_xcode_files: (defaults to: [])

    When the project is generated, this is the list of files that will added to the project. Those files won't be added to the build phase "Compile Sources".

  • extra_xcode_sources: (defaults to: [])

    When the project is generated, this is the list of files that will added to the build phase "Compile Sources" of the given target.

  • frameworks: (defaults to: [])

    A list of system frameworks that the code in this target uses. Each entry should be a path starting with $SDKROOT or $PLATFORM_DIR to denote that the rest of the path is relative to the root of the SDK used for the build or to the platform toolchain directory.

  • header_namespace: (defaults to: None)

    A path prefix when including headers of this target. Defaults to the path from the root of the repository to the directory where this target is defined. Can contain forward slashes (/), but cannot start with one. See headers for more information.

  • header_path_prefix: (defaults to: None)

    A path prefix when including headers of this target. For example, headers from a library defined using

    apple_library(
    name = "Library",
    headers = glob(["**/*.h"]),
    header_path_prefix = "Lib",
    )

    can be imported using following mapping

    Library/SubDir/Header1.h -> Lib/Header1.h
    Library/Header2.h -> Lib/Header2.h

    Defaults to the short name of the target. Can contain forward slashes (/), but cannot start with one. See headers for more information.

  • headers: (defaults to: [])

    The set of header files that are made available for inclusion to the source files in this target. These should be specified as either a list of header files or a dictionary of header names to header files. The header names can contain forward slashes (/). If a list of header files is specified, the headers can be imported with #import "$HEADER_PATH_PREFIX/$HEADER_NAME" or #import "$HEADER_NAME", where $HEADER_PATH_PREFIX is the value of the target's header_path_prefix attribute, and $HEADER_NAME is the filename of the header file. If a dictionary is specified, each header can be imported with #import "$HEADER_NAME", where $HEADER_NAME is the key corresponding to this file. In this case, the header_path_prefix attribute is ignored. In either case, quotes in the import statements can be replaced with angle brackets.

  • include_directories: (defaults to: [])

    A list of include directories (with raw_headers) to be added to the compile command for compiling this target (via -I). An include directory is relative to the current package.

  • info_plist_substitutions: (defaults to: {})

    A dictionary that assigns variable names to their values. It is used for variable substitution when processing the file specified in info_plist. For example if this argument is set to {'VAR': 'MyValue'}, then each occurrence of $(VAR) or ${VAR} in the file will be replaced by MyValue.

  • link_execution_preference: (defaults to: None)

    The execution preference for linking. Options are:

    • any : No preference is set, and the link action will be performed based on buck2's executor configuration.
    • full_hybrid : The link action will execute both locally and remotely, regardless of buck2's executor configuration (if the executor is capable of hybrid execution). The use_limited_hybrid setting of the hybrid executor is ignored.
    • local : The link action will execute locally if compatible on current host platform.
    • local_only : The link action will execute locally, and error if the current platform is not compatible.
    • remote : The link action will execute remotely if a compatible remote platform exists, otherwise locally.

    The default is None, expressing that no preference has been set on the target itself.

  • link_style: (defaults to: None)

    Determines whether to build and link this rule's dependencies statically or dynamically. Can be either static, static_pic or shared.

  • linker_extra_outputs: (defaults to: [])

    Declares extra outputs that the linker emits. These identifiers can be used in $(output ...) macros in linker_flags to interpolate the output path into the linker command line. Useful for custom linkers that emit extra output files.

  • linker_flags: (defaults to: [])

    Flags to add to the linker command line whenever the output from this rule is used in a link operation, such as linked into an executable or a shared library.

  • platform_compiler_flags: (defaults to: [])

    Platform specific compiler flags. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of flags to use when compiling the target's sources. See compiler_flags for more information.

  • platform_srcs: (defaults to: [])

    Platform specific source files. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is either a list of source files or a list of tuples of source files and a list of compilation flags to be preprocessed, compiled and assembled if the platform matches the regex. See srcs for more information.

  • preprocessor_flags: (defaults to: [])

    Flags to use when preprocessing any of the above sources (which require preprocessing).

  • public_include_directories: (defaults to: [])

    A list of include directories (with raw_headers) to be added to the compile command for compiling this target and every target that depends on it (via -I). An include directory is relative to the current package.

  • public_system_include_directories: (defaults to: [])

    A list of include directories (with raw_headers) to be added to the compile command for compiling this target and every target that depends on it (via -isystem if the compiler supports it of via -I otherwise). An include directory is relative to the current package.

  • raw_headers: (defaults to: [])

    The set of header files that can be used for inclusion to the source files in the target and all targets that transitively depend on it. Buck doesn't add raw headers to the search path of a compiler/preprocessor automatically. include_directories and public_include_directories are the recommended way to add raw headers to the search path (they will be added via -I). compiler_flags, preprocessor_flags and exported_preprocessor_flags can also be used to add such raw headers to the search path if inclusion via -isystem or -iquote is needed. raw_headers cannot be used together with headers or exported_headers in the same target.

  • raw_headers_as_headers_mode: (defaults to: None)

    Controls whether raw_headers and *include_directories attributes should be automatically converted to headers and symlink trees and/or header maps via headers. Only has an effect if the cxx_toolchain has explicitly opted into supporting this behavior via a non-default value, even if the value is disabled.

  • reexport_all_header_dependencies: (defaults to: None)

    Whether to automatically re-export the exported headers of all dependencies.

    When this is set to false, only exported headers from exported_deps are re-exported.

  • srcs: (defaults to: [])

    The set of C, C++, Objective-C, Objective-C++, or assembly source files to be preprocessed, compiled, and assembled by this rule. We determine which stages to run on each input source based on its file extension. See the GCC documentation for more detail on how file extensions are interpreted. Each element can be either a string specifying a source file (e.g. '') or a tuple of a string specifying a source file and a list of compilation flags (e.g. ('', ['-Wall', '-Werror']) ). In the latter case the specified flags will be used in addition to the rule's other flags when preprocessing and compiling that file (if applicable).

  • supported_platforms_regex: (defaults to: None)

    If present, an un-anchored regex (in java.util.regex.Pattern syntax) that matches all platforms that this library supports. It will not be built for other platforms.

  • target_sdk_version: (defaults to: None)

    The minimum OS version that the library target should support, overriding the minimum set in .buckconfig. When set, Buck will automatically add flags to both Objective-C and Swift compilation that will allow the use of the new APIs without guarding code inside availability checks.

Examples



apple_library(
name = 'MyLibrary',
deps = [
':OtherLibrary',
'//Libraries:YetAnotherLibrary',
],
preprocessor_flags = ['-fobjc-arc'],
headers = [
'MyHeader.h',
],
srcs = [
'MySource.m',
'MySource.swift',
],
frameworks = [
'$SDKROOT/System/Library/Frameworks/UIKit.framework',
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
],
)