Buck: apple_binary()

apple_binary()

This is liable to change in the future.

An apple_binary() rule builds a native executable from the supplied set of Objective-C/C++ source files and dependencies and is similar to a cxx_binary() rule with which it shares many attributes. In addition to those common attributes, apple_binary() has a few more that are specific to binaries intended to be built using the Apple toolchain. Please also note that the way header files are imported differs between apple_binary() and cxx_binary() to better accommodate existing conventions (see the documentation of the headers and exported_headers attributes for more details).

Arguments

  • name (required) #

    The name of the rule.

  • 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'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_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.

  • header_path_prefix (defaults to name) #

    A path prefix when including headers of this target. Defaults to the short name of the target. Can contain forward slashes (/), but cannot start with one. See headers 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, unlike preprocessor_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_flags (defaults to []) #

    Flags to use whenever this rule is involved in a link operation (e.g linked into an executable or shared library).

  • exported_linker_flags (defaults to []) #

    Linker flags to add to this library and to libraries that depend on this library.

  • platform_linker_flags (defaults to []) #

    Platform specific linker 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 this target is involved in a link operation. See linker_flags for more information.

  • 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 with buck 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 in its deps.

  • 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',
  ],
)