Skip to content

Commit

Permalink
Add --incompatible_disable_objc_library_transition
Browse files Browse the repository at this point in the history
This is a migration for bazelbuild#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).
  • Loading branch information
keith committed Aug 15, 2023
1 parent 5806691 commit 31fe00e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,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
Expand Down Expand Up @@ -772,6 +783,9 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(
EXPERIMENTAL_GET_FIXED_CONFIGURED_ACTION_ENV,
experimentalGetFixedConfiguredEnvironment)
.setBool(
INCOMPATIBLE_DISABLE_OBJC_LIBRARY_TRANSITION,
incompatibleDisableObjcLibraryTransition)
.build();
return INTERNER.intern(semantics);
}
Expand Down Expand Up @@ -858,6 +872,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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,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,13 @@ LinkerInputT createLinkerInput(
documented = false)
boolean checkExperimentalCcSharedLibrary(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "incompatible_disable_objc_library_transition",
doc = "DO NOT USE.",
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 @@ -556,6 +556,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 @@ -839,6 +843,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,7 +134,7 @@ 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(),
incompatible_use_toolchain_transition = True,
)

0 comments on commit 31fe00e

Please sign in to comment.