Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.4.0] Add --incompatible_disable_objc_library_transition #19393

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ public final class BuildLanguageOptions extends OptionsBase {
help = "If enabled, targets that have unknown attributes set to None fail.")
public boolean incompatibleFailOnUnknownAttributes;

@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
Expand Down Expand Up @@ -754,6 +765,9 @@ public StarlarkSemantics toStarlarkSemantics() {
EXPERIMENTAL_GET_FIXED_CONFIGURED_ACTION_ENV,
experimentalGetFixedConfiguredEnvironment)
.setBool(INCOMPATIBLE_FAIL_ON_UNKNOWN_ATTRIBUTES, incompatibleFailOnUnknownAttributes)
.setBool(
INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION,
incompatibleDisableObjcLibraryTransition)
.build();
return INTERNER.intern(semantics);
}
Expand Down Expand Up @@ -844,6 +858,8 @@ public StarlarkSemantics toStarlarkSemantics() {
"-experimental_get_fixed_configured_action_env";
public static final String INCOMPATIBLE_FAIL_ON_UNKNOWN_ATTRIBUTES =
"-incompatible_fail_on_unknown_attributes";
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>.",
Expand Down
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
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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 =
Expand Down