apple_binary()
This is liable to change in the future.
An apple_binary()
rule builds a native executable—such as an iOS or OSX app—from the supplied set of Objective-C/C++ source files and dependencies. It is similar to a cxx_binary
rule with which it shares many attributes. In addition to those common attributes, apple_binary()
has a some additional attributes that are specific to binaries intended to be built using the Apple toolchain. Note, however, that apple_binary()
and cxx_binary()
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.
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 [apple].replacement
and [apple].xcode_tool_name_override
for more information.
Arguments
name
(required) #The short name for this build target.
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.
'foo/bar.m'
) or a tuple of a string specifying a source file and a list of compilation flags (e.g.('foo/bar.m', ['-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).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.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'sheader_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, theheader_path_prefix
attribute is ignored. In either case, quotes in the import statements can be replaced with angle brackets.entitlements_file
(required) #An optional name of a plist file to be embedded in the binary. Some platforms like
iphonesimulator
require this to run properly.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'sheader_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, theheader_path_prefix
attribute is ignored. In either case, quotes in the import statements can be replaced with angle brackets.header_path_prefix
(defaults toname
) #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 mappingLibrary/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. Seeheaders
for more information.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.preprocessor_flags
(defaults to[]
) #Flags to use when preprocessing any of the above sources (which require preprocessing).
exported_preprocessor_flags
(defaults to[]
) #Just as
preprocessor_flags
, flags to use when preprocessing any of the above sources (which require preprocessing). However, unlikepreprocessor_flags
, these preprocessor flags are also used by rules that transitively depend on this rule when preprocessing their own sources.compiler_flags
(defaults to[]
) #Flags to use when compiling any of the above sources (which require compilation).
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.linker_extra_outputs
(defaults to[]
) #Declares extra outputs that the linker emits. These identifiers can be used in
$(output ...)
macros inlinker_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.
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.
platform_linker_flags
(defaults to[]
) #Platform-specific linker flags. 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 is used in a link operation.link_style
(defaults tostatic
) #Determines whether to build and link this rule's dependencies statically or dynamically. Can be either
static
,static_pic
orshared
.target_sdk_version
(defaults toNone
) #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.tests
(defaults to[]
) #List of build targets that identify the test rules that exercise this target. Note that non
apple_test
targets will not be included in generated projects due to Xcode's limitations but will still work withbuck test
.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.
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".
visibility
(defaults to[]
) #List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their
deps
orexported_deps
attributes. For more information, see visibility.licenses
(defaults to[]
) #Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use
buck query
.labels
(defaults to[]
) #Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using
buck query attrfilter()
.
Examples
apple_binary( name = 'MyBinary', deps = [ ':MyLibrary', '//Libraries:AnotherLibrary', ], preprocessor_flags = ['-fobjc-arc'], headers = [ 'MyHeader.h', ], srcs = [ 'MySource.m', ], frameworks = [ '$SDKROOT/System/Library/Frameworks/UIKit.framework', '$SDKROOT/System/Library/Frameworks/Foundation.framework', ], )