Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.4] Add --incompatible_disable_objc_library_transition
Browse files Browse the repository at this point in the history
This is a migration for #16870

Users who rely on the current behavior should instead wrap their library in a target from [rules_apple](https://github.com/bazelbuild/rules_apple).

Fixes #19204

Closes #19256.

PiperOrigin-RevId: 561253613
Change-Id: I1b1b24a08caa33e86881bfe376a525060c9887a9
(cherry picked from commit 0f34e76)
keith committed Sep 1, 2023
1 parent 1cd0ab0 commit 4b9b6e5
Showing 6 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -652,6 +652,17 @@ public final class BuildLanguageOptions extends OptionsBase {
+ " specified through features configuration.")
public boolean experimentalGetFixedConfiguredEnvironment;

@Option(
name = "incompatible_disable_objc_library_transition",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help =
"Disable objc_library's custom transition and inherit "
+ "from the top level target instead")
public boolean incompatibleDisableObjcLibraryTransition;

/**
* An interner to reduce the number of StarlarkSemantics instances. A single Blaze instance should
* never accumulate a large number of these and being able to shortcut on object identity makes a
@@ -743,6 +754,9 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(
EXPERIMENTAL_GET_FIXED_CONFIGURED_ACTION_ENV,
experimentalGetFixedConfiguredEnvironment)
.setBool(
INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION,
incompatibleDisableObjcLibraryTransition)
.build();
return INTERNER.intern(semantics);
}
@@ -831,6 +845,8 @@ public StarlarkSemantics toStarlarkSemantics() {
"-incompatible_disable_starlark_host_transitions";
public static final String EXPERIMENTAL_GET_FIXED_CONFIGURED_ACTION_ENV =
"-experimental_get_fixed_configured_action_env";
public static final String INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION =
"-incompatible_disable_objc_library_transition";

// non-booleans
public static final StarlarkSemantics.Key<String> EXPERIMENTAL_BUILTINS_BZL_PATH =
Original file line number Diff line number Diff line change
@@ -1113,6 +1113,14 @@ public void checkExperimentalStarlarkCcImport(StarlarkActionFactory starlarkActi
}
}

@Override
public boolean getIncompatibleDisableObjcLibraryTransition(StarlarkThread thread)
throws EvalException {
return thread
.getSemantics()
.getBool(BuildLanguageOptions.INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION);
}

@Override
public CcLinkingContext createCcLinkingInfo(
Object linkerInputs,
Original file line number Diff line number Diff line change
@@ -777,6 +777,12 @@ LinkerInputT createLinkerInput(
void checkExperimentalStarlarkCcImport(StarlarkActionFactoryT starlarkActionFactoryApi)
throws EvalException;

@StarlarkMethod(
name = "incompatible_disable_objc_library_transition",
useStarlarkThread = true,
documented = false)
boolean getIncompatibleDisableObjcLibraryTransition(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "create_linking_context",
doc = "Creates a <code>LinkingContext</code>.",
4 changes: 4 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/semantics.bzl
Original file line number Diff line number Diff line change
@@ -144,6 +144,9 @@ def _check_experimental_cc_shared_library(ctx):
if not cc_common.check_experimental_cc_shared_library():
fail("Pass --experimental_cc_shared_library to use cc_shared_library")

def _incompatible_disable_objc_library_transition():
return cc_common.incompatible_disable_objc_library_transition()

def _get_linkstatic_default(ctx):
if ctx.attr._is_test:
# By default Tests do not link statically. Except on Windows.
@@ -194,4 +197,5 @@ semantics = struct(
get_coverage_attrs = _get_coverage_attrs,
get_coverage_env = _get_coverage_env,
get_proto_aspects = _get_proto_aspects,
incompatible_disable_objc_library_transition = _incompatible_disable_objc_library_transition,
)
3 changes: 2 additions & 1 deletion src/main/starlark/builtins_bzl/common/objc/objc_library.bzl
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ load("@_builtins//:common/objc/compilation_support.bzl", "compilation_support")
load("@_builtins//:common/objc/attrs.bzl", "common_attrs")
load("@_builtins//:common/objc/transitions.bzl", "apple_crosstool_transition")
load("@_builtins//:common/cc/cc_helper.bzl", "cc_helper")
load("@_builtins//:common/cc/semantics.bzl", "semantics")

objc_internal = _builtins.internal.objc_internal
CcInfo = _builtins.toplevel.CcInfo
@@ -102,7 +103,7 @@ objc_library = rule(
common_attrs.XCRUN_RULE,
),
fragments = ["objc", "apple", "cpp"],
cfg = apple_crosstool_transition,
cfg = None if semantics.incompatible_disable_objc_library_transition() else apple_crosstool_transition,
toolchains = cc_helper.use_cpp_toolchain(),
incompatible_use_toolchain_transition = True,
)
Original file line number Diff line number Diff line change
@@ -109,6 +109,30 @@ public void testConfigTransitionWithTopLevelAppleConfiguration() throws Exceptio
assertThat(objcObject.getExecPathString()).contains("ios_x86_64");
}

@Test
public void testNoTransition() throws Exception {
scratch.file(
"bin/BUILD",
"objc_library(",
" name = 'objc',",
" srcs = ['objc.m'],",
")",
"cc_binary(",
" name = 'cc',",
" srcs = ['cc.cc'],",
" deps = [':objc'],",
")");

setBuildLanguageOptions("--incompatible_disable_objc_library_transition");
useConfiguration("--macos_cpus=arm64,x86_64");

ConfiguredTarget cc = getConfiguredTarget("//bin:cc");
Artifact objcObject =
ActionsTestUtil.getFirstArtifactEndingWith(
actionsTestUtil().artifactClosureOf(getFilesToBuild(cc)), "objc.o");
assertThat(objcObject.getExecPathString()).contains("k8-fastbuild");
}

@Test
public void testFilesToBuild() throws Exception {
ConfiguredTarget target =

0 comments on commit 4b9b6e5

Please sign in to comment.