Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apple/internal/linking_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _link_multi_arch_binary(
legacy_debug_outputs.setdefault(platform_info.target_arch, {})["dsym_binary"] = dsym_binary

linkmap = None
if ctx.fragments.cpp.objc_generate_linkmap:
if ctx.attr.generate_linkmap or ctx.fragments.cpp.objc_generate_linkmap:
linkmap = intermediates.file(
actions = ctx.actions,
target_name = ctx.label.name,
Expand Down Expand Up @@ -371,7 +371,8 @@ def _debug_outputs_by_architecture(link_outputs):

for link_output in link_outputs:
dsym_binaries[link_output.architecture] = link_output.dsym_binary
linkmaps[link_output.architecture] = link_output.linkmap
if link_output.linkmap:
linkmaps[link_output.architecture] = link_output.linkmap

return struct(
dsym_binaries = dsym_binaries,
Expand Down Expand Up @@ -548,13 +549,17 @@ def _register_binary_linking_action(
linkopts.extend(["-bundle_loader", bundle_loader_file.path])
link_inputs.append(bundle_loader_file)

requested_features = list(extra_requested_features)
if ctx.attr.generate_linkmap or ctx.fragments.cpp.objc_generate_linkmap:
requested_features.append("generate_linkmap")

linking_outputs = _link_multi_arch_binary(
ctx = ctx,
avoid_deps = all_avoid_deps,
cc_toolchains = cc_toolchains,
extra_linkopts = linkopts,
extra_link_inputs = link_inputs,
extra_requested_features = extra_requested_features,
extra_requested_features = requested_features,
# TODO(321109350): Disable include scanning to work around issue with GrepIncludes actions
# being routed to the wrong exec platform.
extra_disabled_features = extra_disabled_features + ["cc_include_scanning"],
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/partials/debug_symbols.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _debug_symbols_partial_impl(
direct_dsym_bundles.append(dsym_bundle_dir)
direct_dsyms.extend(dsym_files)

if platform_prerequisites.cpp_fragment.objc_generate_linkmap:
if linkmaps:
linkmaps = _collect_linkmaps(
actions = actions,
debug_output_filename = debug_output_filename,
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/providers/apple_debug_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ partial and the resource aspect.
Depset of `File` references to dSYM files if requested in the build with --apple_generate_dsym.
""",
"linkmaps": """
Depset of `File` references to linkmap files if requested in the build with --objc_generate_linkmap.
Depset of `File` references to linkmap files when linkmap generation is requested.
""",
},
)
9 changes: 9 additions & 0 deletions apple/internal/rule_attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ were marked as `__private_extern__` (aka `visibility=hidden`) and will not be gl
file.

See the man page documentation for `ld(1)` on macOS for more details.
""",
),
"generate_linkmap": attr.bool(
default = False,
doc = """
Whether to generate a linkmap file for this target's linked binary.

This attribute augments `--objc_generate_linkmap`; if the command-line flag is set, a linkmap is
still generated even when this attribute is `False`.
""",
),
"linkopts": attr.string_list(
Expand Down
3 changes: 2 additions & 1 deletion apple/internal/xcframework_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def _group_link_outputs_by_library_identifier(
# static library linking does not support dsym, and linkmaps yet.
if linking_type == "binary":
dsym_binaries[link_output.architecture] = link_output.dsym_binary
linkmaps[link_output.architecture] = link_output.linkmap
if link_output.linkmap:
linkmaps[link_output.architecture] = link_output.linkmap

environment = link_outputs[0].environment
platform = link_outputs[0].platform
Expand Down
37 changes: 34 additions & 3 deletions doc/common_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ which files are requested:
* `linkmaps`: This output group contains all linkmap files generated during
the build, for the top level target **and** its embedded dependencies. To
request this output group to be built, use the `--output_groups=+linkmaps`
flag. In order to generate the linkmap files you still need to pass the
`--objc_generate_linkmap` flag.
flag. Linkmap generation can be requested either per-target with the
`generate_linkmap` attribute or globally with the `--objc_generate_linkmap`
flag.

### dSYMs Generation {#apple_generate_dsym}

Expand Down Expand Up @@ -116,12 +117,23 @@ flags yourself.

Linkmaps can be useful for figuring out how the `deps` going into a target are
contributing to the final size of the binary. Bazel will generate a link map
when linking by adding `--objc_generate_linkmap` to a `bazel build`.
when linking if either the rule's `generate_linkmap` attribute is `True` or
`--objc_generate_linkmap` is added to a `bazel build`.

```shell
bazel build --objc_generate_linkmap //your/target
```

Or:

```bzl
ios_application(
name = "app",
generate_linkmap = True,
# ...
)
```

By default, only the top level linkmap file is built when this flag is
specified. If you require the linkmap file of the top level target dependencies,
you'll need to specify the `--output_groups=+linkmaps` flag.
Expand Down Expand Up @@ -260,6 +272,25 @@ ios_application(
)
```

### Running applications

When using `bazel run` with Apple application targets, the generated simulator
and device runners support additional control via the
`BAZEL_APPLE_RUN_MODE` environment variable.

Supported values are:

* `install_and_run` (default): Terminates any existing instance, installs the
app, and launches it.
* `install_without_running`: Terminates any existing instance, installs the
app, and exits without launching it.
* `run_without_installing`: Terminates any existing instance and launches the
existing installed app without reinstalling it.

If `BAZEL_APPLE_RUN_MODE=install_without_running` is used together with
`BAZEL_APPLE_LAUNCH_INFO_PATH`, the runner removes any stale launch info file
and does not write a new one, since no process is launched.

### Localization Handling

The Apple bundling rules have two flags for limiting which \*.lproj directories
Expand Down
6 changes: 4 additions & 2 deletions doc/rules-apple.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ load("@rules_apple//apple:apple.bzl", "apple_xcframework")

apple_xcframework(<a href="#apple_xcframework-name">name</a>, <a href="#apple_xcframework-deps">deps</a>, <a href="#apple_xcframework-data">data</a>, <a href="#apple_xcframework-additional_linker_inputs">additional_linker_inputs</a>, <a href="#apple_xcframework-bundle_id">bundle_id</a>, <a href="#apple_xcframework-bundle_name">bundle_name</a>,
<a href="#apple_xcframework-codesign_inputs">codesign_inputs</a>, <a href="#apple_xcframework-codesignopts">codesignopts</a>, <a href="#apple_xcframework-exported_symbols_lists">exported_symbols_lists</a>, <a href="#apple_xcframework-extension_safe">extension_safe</a>,
<a href="#apple_xcframework-families_required">families_required</a>, <a href="#apple_xcframework-infoplists">infoplists</a>, <a href="#apple_xcframework-ios">ios</a>, <a href="#apple_xcframework-linkopts">linkopts</a>, <a href="#apple_xcframework-macos">macos</a>, <a href="#apple_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>,
<a href="#apple_xcframework-minimum_os_versions">minimum_os_versions</a>, <a href="#apple_xcframework-public_hdrs">public_hdrs</a>, <a href="#apple_xcframework-stamp">stamp</a>, <a href="#apple_xcframework-tvos">tvos</a>, <a href="#apple_xcframework-umbrella_header">umbrella_header</a>, <a href="#apple_xcframework-version">version</a>, <a href="#apple_xcframework-visionos">visionos</a>)
<a href="#apple_xcframework-families_required">families_required</a>, <a href="#apple_xcframework-generate_linkmap">generate_linkmap</a>, <a href="#apple_xcframework-infoplists">infoplists</a>, <a href="#apple_xcframework-ios">ios</a>, <a href="#apple_xcframework-linkopts">linkopts</a>, <a href="#apple_xcframework-macos">macos</a>,
<a href="#apple_xcframework-minimum_deployment_os_versions">minimum_deployment_os_versions</a>, <a href="#apple_xcframework-minimum_os_versions">minimum_os_versions</a>, <a href="#apple_xcframework-public_hdrs">public_hdrs</a>, <a href="#apple_xcframework-stamp">stamp</a>, <a href="#apple_xcframework-tvos">tvos</a>,
<a href="#apple_xcframework-umbrella_header">umbrella_header</a>, <a href="#apple_xcframework-version">version</a>, <a href="#apple_xcframework-visionos">visionos</a>)
</pre>

Builds and bundles an XCFramework for third-party distribution.
Expand All @@ -323,6 +324,7 @@ Builds and bundles an XCFramework for third-party distribution.
| <a id="apple_xcframework-exported_symbols_lists"></a>exported_symbols_lists | A list of targets containing exported symbols lists files for the linker to control symbol resolution.<br><br>Each file is expected to have a list of global symbol names that will remain as global symbols in the compiled binary owned by this framework. All other global symbols will be treated as if they were marked as `__private_extern__` (aka `visibility=hidden`) and will not be global in the output file.<br><br>See the man page documentation for `ld(1)` on macOS for more details. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="apple_xcframework-extension_safe"></a>extension_safe | If true, compiles and links this framework with `-application-extension`, restricting the binary to use only extension-safe APIs. | Boolean | optional | `False` |
| <a id="apple_xcframework-families_required"></a>families_required | A list of device families supported by this extension, with platforms such as `ios` as keys. Valid values are `iphone` and `ipad` for `ios`; at least one must be specified if a platform is defined. Currently, this only affects processing of `ios` resources. | <a href="https://bazel.build/rules/lib/core/dict">Dictionary: String -> List of strings</a> | optional | `{}` |
| <a id="apple_xcframework-generate_linkmap"></a>generate_linkmap | Whether to generate a linkmap file for this target's linked binary.<br><br>This attribute augments `--objc_generate_linkmap`; if the command-line flag is set, a linkmap is still generated even when this attribute is `False`. | Boolean | optional | `False` |
| <a id="apple_xcframework-infoplists"></a>infoplists | A list of .plist files that will be merged to form the Info.plist for each of the embedded frameworks. At least one file must be specified. Please see [Info.plist Handling](https://github.com/bazelbuild/rules_apple/blob/main/doc/common_info.md#infoplist-handling) for what is supported. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="apple_xcframework-ios"></a>ios | A dictionary of strings indicating which platform variants should be built for the iOS platform ( `device` or `simulator`) as keys, and arrays of strings listing which architectures should be built for those platform variants (for example, `x86_64`, `arm64`) as their values. | <a href="https://bazel.build/rules/lib/core/dict">Dictionary: String -> List of strings</a> | optional | `{}` |
| <a id="apple_xcframework-linkopts"></a>linkopts | A list of strings representing extra flags that should be passed to the linker. | List of strings | optional | `[]` |
Expand Down
Loading