Skip to content

Commit

Permalink
Remove runtime_deps from objc_library
Browse files Browse the repository at this point in the history
This change removes objc_library `runtime_deps` rule attribute.

Previously, `runtime_deps` propagated Apple frameworks built with
rules_apple framework rules (eg. `ios_framework`) to be bundled at
top-level bundle rules (e.g. `ios_application`) but avoid linking the
framework to allow deferred loading using `NSBundle` APIs.

Apple BUILD rules now support propagating Apple frameworks through the
`data` rule attribute from `objc_library` and `swift_library` rules to
replace this functionality.

Fixes #17643

PiperOrigin-RevId: 516909309
Change-Id: I19d20745b23b1ec62cb512ee7a084f38cdb2ea21
  • Loading branch information
Googler authored and Copybara-Service committed Mar 15, 2023
1 parent 67d9d75 commit 3ea60b7
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 62 deletions.
Expand Up @@ -102,7 +102,6 @@ static class Builder {
private Optional<CompilationAttributes> compilationAttributes = Optional.absent();
private Optional<CompilationArtifacts> compilationArtifacts = Optional.absent();
private Iterable<ObjcProvider> objcProviders = ImmutableList.of();
private Iterable<ObjcProvider> runtimeObjcProviders = ImmutableList.of();
private Iterable<PathFragment> includes = ImmutableList.of();
private IntermediateArtifacts intermediateArtifacts;
private boolean alwayslink;
Expand Down Expand Up @@ -307,7 +306,6 @@ ObjcCommon build() {
objcCompilationContextBuilder
.addIncludes(includes)
.addObjcProviders(objcProviders)
.addObjcProviders(runtimeObjcProviders)
.addDirectCcCompilationContexts(directCCompilationContexts)
// TODO(bazel-team): This pulls in stl via
// CcCompilationHelper.getStlCcCompilationContext(), but probably shouldn't.
Expand Down
Expand Up @@ -384,15 +384,6 @@ Header file to prepend to every source file being compiled (both arc
.direct_compile_time_input()
.mandatoryProviders(CcInfo.PROVIDER.id())
.allowedFileTypes())
/* <!-- #BLAZE_RULE($objc_compiling_rule).ATTRIBUTE(runtime_deps) -->
The list of framework targets that are late loaded at runtime. They are included in the
app bundle but not linked against at build time.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
attr("runtime_deps", LABEL_LIST)
.direct_compile_time_input()
.mandatoryProviders(AppleDynamicFrameworkInfo.STARLARK_CONSTRUCTOR.id())
.allowedFileTypes())
/* <!-- #BLAZE_RULE($objc_compiling_rule).ATTRIBUTE(defines) -->
Extra <code>-D</code> flags to pass to the compiler. They should be in
the form <code>KEY=VALUE</code> or simply <code>KEY</code> and are
Expand Down
4 changes: 0 additions & 4 deletions src/main/starlark/builtins_bzl/common/objc/attrs.bzl
Expand Up @@ -40,10 +40,6 @@ _COMPILING_RULE = {
allow_single_file = [".pch"],
flags = ["DIRECT_COMPILE_TIME_INPUT"],
),
"runtime_deps": attr.label_list(
providers = [AppleDynamicFrameworkInfo],
flags = ["DIRECT_COMPILE_TIME_INPUT"],
),
"defines": attr.string_list(),
"enable_modules": attr.bool(),
"linkopts": attr.string_list(),
Expand Down
Expand Up @@ -40,7 +40,6 @@ def _build_common_variables(
use_pch = False,
empty_compilation_artifacts = False,
deps = [],
runtime_deps = [],
extra_disabled_features = [],
extra_enabled_features = [],
extra_import_libraries = [],
Expand All @@ -63,7 +62,6 @@ def _build_common_variables(
compilation_attributes = compilation_attributes,
compilation_artifacts = compilation_artifacts,
deps = deps,
runtime_deps = runtime_deps,
intermediate_artifacts = intermediate_artifacts,
alwayslink = alwayslink,
has_module_map = has_module_map,
Expand Down
10 changes: 1 addition & 9 deletions src/main/starlark/builtins_bzl/common/objc/objc_common.bzl
Expand Up @@ -47,7 +47,6 @@ def _create_context_and_provider(
has_module_map,
extra_import_libraries,
deps,
runtime_deps,
attr_linkopts):
objc_providers = []
cc_compilation_contexts = []
Expand All @@ -70,13 +69,6 @@ def _create_context_and_provider(
cc_compilation_contexts.append(dep[CcInfo].compilation_context)
cc_linking_contexts.append(dep[CcInfo].linking_context)

runtime_objc_providers = []
for runtime_dep in runtime_deps:
if apple_common.Objc in runtime_dep:
runtime_objc_providers.append(runtime_dep[apple_common.Objc])
if CcInfo in runtime_dep:
cc_compilation_contexts.append(runtime_dep[CcInfo].compilation_context)

link_order_keys = [
"imported_library",
"cc_library",
Expand All @@ -100,7 +92,7 @@ def _create_context_and_provider(
}

objc_compilation_context_kwargs = {
"providers": objc_providers + runtime_objc_providers,
"providers": objc_providers,
"cc_compilation_contexts": cc_compilation_contexts,
"public_hdrs": [],
"private_hdrs": [],
Expand Down
Expand Up @@ -61,7 +61,6 @@ def _objc_library_impl(ctx):
toolchain = cc_toolchain,
use_pch = True,
deps = ctx.attr.deps,
runtime_deps = ctx.attr.runtime_deps,
attr_linkopts = ctx.attr.linkopts,
alwayslink = ctx.fragments.objc.target_should_alwayslink(ctx),
)
Expand Down
Expand Up @@ -2415,41 +2415,6 @@ public void testModuleMapFileAccessed() throws Exception {
getConfiguredTarget("//x:foo");
}

@Test
public void testRuntimeDeps() throws Exception {
scratch.file(
"x/defs.bzl",
"def _var_providing_rule_impl(ctx):",
" return [",
" CcInfo(),",
" apple_common.new_dynamic_framework_provider(",
" cc_info=ctx.attr.dep[CcInfo],",
" objc=ctx.attr.dep[apple_common.Objc],",
" )",
" ]",
"var_providing_rule = rule(",
" implementation = _var_providing_rule_impl,",
" attrs = { 'dep': attr.label(),}",
")");
scratch.file(
"x/BUILD",
"load('//x:defs.bzl', 'var_providing_rule')",
"objc_library(",
" name = 'baz',",
" srcs = ['baz.m'],",
")",
"var_providing_rule(",
" name = 'foo',",
" dep = 'baz',",
")",
"objc_library(",
" name = 'bar',",
" srcs = ['bar.m'],",
" runtime_deps = [':foo'],",
")");
getConfiguredTarget("//x:bar");
}

@Test
public void testRightOrderCcLibs() throws Exception {
scratch.file(
Expand Down

0 comments on commit 3ea60b7

Please sign in to comment.