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

Add --incompatible_disable_objc_library_transition #19256

Closed
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 @@ -701,6 +701,17 @@ public final class BuildLanguageOptions extends OptionsBase {
help = "If set to true, the ObjcProvider's APIs for linking info will be removed.")
public boolean incompatibleObjcProviderRemoveLinkingInfo;

@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 @@ -800,6 +811,9 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(
INCOMPATIBLE_OBJC_PROVIDER_REMOVE_LINKING_INFO,
incompatibleObjcProviderRemoveLinkingInfo)
.setBool(
INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION,
incompatibleDisableObjcLibraryTransition)
.build();
return INTERNER.intern(semantics);
}
Expand Down Expand Up @@ -890,6 +904,8 @@ public StarlarkSemantics toStarlarkSemantics() {
"-experimental_merge_fixed_and_default_shell_env";
public static final String INCOMPATIBLE_OBJC_PROVIDER_REMOVE_LINKING_INFO =
"-incompatible_objc_provider_remove_linking_info";
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 @@ -1161,6 +1161,12 @@ public boolean checkExperimentalCcSharedLibrary(StarlarkThread thread) throws Ev
return thread.getSemantics().getBool(BuildLanguageOptions.EXPERIMENTAL_CC_SHARED_LIBRARY);
}

@Override
public boolean getIncompatibleDisableObjcLibraryTransition(StarlarkThread thread) throws EvalException {
isCalledFromStarlarkCcCommon(thread);
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 @@ -1102,6 +1102,12 @@ LinkerInputT createLinkerInput(
documented = false)
boolean checkExperimentalCcSharedLibrary(StarlarkThread thread) 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
5 changes: 5 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ def _check_experimental_cc_shared_library():
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.check_experimental_cc_shared_library()

def _incompatible_disable_objc_library_transition():
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.incompatible_disable_objc_library_transition()

def _create_module_map(*, file, name, umbrella_header = None):
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.create_module_map(
Expand Down Expand Up @@ -914,6 +918,7 @@ cc_common = struct(
merge_cc_infos = _merge_cc_infos,
create_compilation_context = _create_compilation_context,
legacy_cc_flags_make_variable_do_not_use = _legacy_cc_flags_make_variable_do_not_use,
incompatible_disable_objc_library_transition = _incompatible_disable_objc_library_transition,
is_cc_toolchain_resolution_enabled_do_not_use = _is_cc_toolchain_resolution_enabled_do_not_use,
create_cc_toolchain_config_info = _create_cc_toolchain_config_info,
create_linking_context_from_compilation_outputs = _create_linking_context_from_compilation_outputs,
Expand Down
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
Expand Up @@ -21,6 +21,7 @@ load("@_builtins//:common/objc/objc_common.bzl", "extensions", "objc_common")
load("@_builtins//:common/objc/semantics.bzl", "semantics")
load("@_builtins//:common/objc/transitions.bzl", "apple_crosstool_transition")
load(":common/objc/providers.bzl", "J2ObjcEntryClassInfo", "J2ObjcMappingFileInfo")
load(":common/cc/cc_common.bzl", "cc_common")
load(":common/cc/cc_info.bzl", "CcInfo")

objc_internal = _builtins.internal.objc_internal
Expand Down Expand Up @@ -133,6 +134,6 @@ objc_library = rule(
common_attrs.SDK_FRAMEWORK_DEPENDER_RULE,
),
fragments = ["objc", "apple", "cpp"],
cfg = apple_crosstool_transition,
cfg = None if cc_common.incompatible_disable_objc_library_transition() else apple_crosstool_transition,
toolchains = cc_helper.use_cpp_toolchain(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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
Loading