Skip to content

Commit 68f29c6

Browse files
googlewaltcopybara-github
authored andcommitted
Support rest of objc-specific features in CcCommon.configureFeatures
This requires migrating the dead_strip and generate_linkmap options to CppOptions / CppConfiguration. For now, we keep the corresponding information in ObjcConfiguration, but we can eventually delete them. PiperOrigin-RevId: 455232743 Change-Id: I68cdeafe24064a7d3c56e6c090063179d1635c42
1 parent d308c17 commit 68f29c6

9 files changed

Lines changed: 92 additions & 86 deletions

File tree

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ public void collectMetadataArtifacts(Iterable<Artifact> objectFiles,
155155
.addAll(ALL_OTHER_ACTIONS)
156156
.build();
157157

158+
public static final ImmutableSet<String> OBJC_ACTIONS =
159+
ImmutableSet.of(
160+
CppActionNames.OBJC_COMPILE,
161+
CppActionNames.OBJCPP_COMPILE,
162+
CppActionNames.OBJC_ARCHIVE,
163+
CppActionNames.OBJC_FULLY_LINK,
164+
CppActionNames.OBJC_EXECUTABLE,
165+
CppActionNames.OBJCPP_EXECUTABLE);
166+
158167
/** An enum for the list of supported languages. */
159168
public enum Language {
160169
CPP("c++"),
@@ -1031,6 +1040,12 @@ public static FeatureConfiguration configureFeaturesOrThrowEvalException(
10311040

10321041
if (language == Language.OBJC || language == Language.OBJCPP) {
10331042
allRequestedFeaturesBuilder.add(CppRuleClasses.LANG_OBJC);
1043+
if (cppConfiguration.objcGenerateLinkmap()) {
1044+
allRequestedFeaturesBuilder.add(CppRuleClasses.GENERATE_LINKMAP_FEATURE_NAME);
1045+
}
1046+
if (cppConfiguration.objcShouldStripBinary()) {
1047+
allRequestedFeaturesBuilder.add(CppRuleClasses.DEAD_STRIP_FEATURE_NAME);
1048+
}
10341049
}
10351050

10361051
ImmutableSet<String> allUnsupportedFeatures = unsupportedFeaturesBuilder.build();
@@ -1059,6 +1074,10 @@ public static FeatureConfiguration configureFeaturesOrThrowEvalException(
10591074
.addAll(toolchain.getFeatures().getDefaultFeaturesAndActionConfigs())
10601075
.addAll(cppConfiguration.getAppleBitcodeMode().getFeatureNames());
10611076

1077+
if (language == Language.OBJC || language == Language.OBJCPP) {
1078+
allFeatures.addAll(OBJC_ACTIONS);
1079+
}
1080+
10621081
if (!cppConfiguration.dontEnableHostNonhost()) {
10631082
if (toolchain.isToolConfiguration()) {
10641083
allFeatures.add("host");

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,15 @@ public boolean objcShouldGenerateDotdFiles() {
867867
return cppOptions.objcGenerateDotdFiles;
868868
}
869869

870+
@Override
871+
public boolean objcGenerateLinkmap() {
872+
return cppOptions.objcGenerateLinkmap;
873+
}
874+
875+
public boolean objcEnableBinaryStripping() {
876+
return cppOptions.objcEnableBinaryStripping;
877+
}
878+
870879
@StarlarkMethod(
871880
name = "experimental_cc_interface_deps",
872881
documented = false,
@@ -975,4 +984,9 @@ public boolean getExperimentalPlatformCcTest(StarlarkThread thread) throws EvalE
975984
public AppleBitcodeMode getAppleBitcodeMode() {
976985
return appleBitcodeMode;
977986
}
987+
988+
@Override
989+
public boolean objcShouldStripBinary() {
990+
return objcEnableBinaryStripping() && getCompilationMode() == CompilationMode.OPT;
991+
}
978992
}

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,25 @@ public Label getPropellerOptimizeLabel() {
957957
help = "Whether to force enable generating debug symbol(.dSYM) file(s) for dbg builds.")
958958
public boolean appleEnableAutoDsymDbg;
959959

960+
@Option(
961+
name = "objc_generate_linkmap",
962+
defaultValue = "false",
963+
documentationCategory = OptionDocumentationCategory.OUTPUT_SELECTION,
964+
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
965+
help = "Specifies whether to generate a linkmap file.")
966+
public boolean objcGenerateLinkmap;
967+
968+
@Option(
969+
name = "objc_enable_binary_stripping",
970+
defaultValue = "false",
971+
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
972+
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES},
973+
help =
974+
"Whether to perform symbol and dead-code strippings on linked binaries. Binary "
975+
+ "strippings will be performed if both this flag and --compilation_mode=opt are "
976+
+ "specified.")
977+
public boolean objcEnableBinaryStripping;
978+
960979
@Option(
961980
name = "experimental_starlark_cc_import",
962981
defaultValue = "false",

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ public static ToolchainTypeRequirement ccToolchainTypeRequirement(RuleDefinition
470470
*/
471471
public static final String NO_GENERATE_DEBUG_SYMBOLS_FEATURE_NAME = "no_generate_debug_symbols";
472472

473+
/** A feature to indicate whether to generate linkmap. For Apple platform only. */
474+
public static final String GENERATE_LINKMAP_FEATURE_NAME = "generate_linkmap";
475+
476+
/** A feature to indicate whether to do linker deadstrip. For Apple platform only. */
477+
public static final String DEAD_STRIP_FEATURE_NAME = "dead_strip";
478+
473479
/**
474480
* A feature which indicates that this target is a test (rather than a binary). This can be used
475481
* to select test-only options.

‎src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java‎

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,6 @@ public class CompilationSupport implements StarlarkValue {
142142
private static final Predicate<Artifact> ALWAYS_LINKED_CC_LIBRARY =
143143
input -> LINK_LIBRARY_FILETYPES.matches(input.getFilename());
144144

145-
private static final String DEAD_STRIP_FEATURE_NAME = "dead_strip";
146-
147-
private static final String GENERATE_LINKMAP_FEATURE_NAME = "generate_linkmap";
148-
149-
private static final ImmutableList<String> OBJC_ACTIONS =
150-
ImmutableList.of(
151-
"objc-compile",
152-
"objc++-compile",
153-
"objc-archive",
154-
"objc-fully-link",
155-
"objc-executable",
156-
"objc++-executable");
157-
158145
/** Returns the location of the xcrunwrapper tool. */
159146
public static final FilesToRunProvider xcrunwrapper(RuleContext ruleContext) {
160147
return ruleContext.getExecutablePrerequisite("$xcrunwrapper");
@@ -171,34 +158,6 @@ public static final FilesToRunProvider xcrunwrapper(RuleContext ruleContext) {
171158
.withSourceAttributes("srcs", "non_arc_srcs", "hdrs")
172159
.withDependencyAttributes("deps", "data", "binary", "xctest_app");
173160

174-
private FeatureConfiguration getFeatureConfiguration(
175-
RuleContext ruleContext,
176-
CcToolchainProvider ccToolchain,
177-
BuildConfigurationValue configuration,
178-
CppSemantics cppSemantics) {
179-
ImmutableSet.Builder<String> activatedCrosstoolSelectables =
180-
ImmutableSet.<String>builder().addAll(ruleContext.getFeatures()).addAll(OBJC_ACTIONS);
181-
182-
if (configuration.getFragment(ObjcConfiguration.class).shouldStripBinary()) {
183-
activatedCrosstoolSelectables.add(DEAD_STRIP_FEATURE_NAME);
184-
}
185-
if (configuration.getFragment(ObjcConfiguration.class).generateLinkmap()) {
186-
activatedCrosstoolSelectables.add(GENERATE_LINKMAP_FEATURE_NAME);
187-
}
188-
189-
ImmutableSet.Builder<String> disabledFeatures =
190-
ImmutableSet.<String>builder().addAll(ruleContext.getDisabledFeatures());
191-
192-
return CcCommon.configureFeaturesOrReportRuleError(
193-
ruleContext,
194-
buildConfiguration,
195-
activatedCrosstoolSelectables.build(),
196-
disabledFeatures.build(),
197-
Language.OBJC,
198-
ccToolchain,
199-
cppSemantics);
200-
}
201-
202161
/** Iterable wrapper providing strong type safety for arguments to binary linking. */
203162
static final class ExtraLinkArgs extends IterableWrapper<String> {
204163
ExtraLinkArgs(String... args) {
@@ -562,7 +521,14 @@ CompilationSupport registerLinkActions(
562521

563522
Artifact binaryToLink = getBinaryToLink();
564523
FeatureConfiguration featureConfiguration =
565-
getFeatureConfiguration(ruleContext, toolchain, buildConfiguration, cppSemantics);
524+
CcCommon.configureFeaturesOrReportRuleError(
525+
ruleContext,
526+
buildConfiguration,
527+
ruleContext.getFeatures(),
528+
ruleContext.getDisabledFeatures(),
529+
Language.OBJC,
530+
toolchain,
531+
cppSemantics);
566532

567533
Label binaryLabel = null;
568534
try {

‎src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ public class ObjcCommandLineOptions extends FragmentOptions {
8888
+ "devicetypes' on the machine the simulator will be run on.")
8989
public String tvosSimulatorDevice;
9090

91-
@Option(
92-
name = "objc_generate_linkmap",
93-
defaultValue = "false",
94-
documentationCategory = OptionDocumentationCategory.OUTPUT_SELECTION,
95-
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
96-
help = "Specifies whether to generate a linkmap file."
97-
)
98-
public boolean generateLinkmap;
99-
10091
@Option(
10192
name = "ios_memleaks",
10293
defaultValue = "false",
@@ -128,17 +119,6 @@ public class ObjcCommandLineOptions extends FragmentOptions {
128119
)
129120
public List<String> fastbuildOptions;
130121

131-
@Option(
132-
name = "objc_enable_binary_stripping",
133-
defaultValue = "false",
134-
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
135-
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES},
136-
help =
137-
"Whether to perform symbol and dead-code strippings on linked binaries. Binary "
138-
+ "strippings will be performed if both this flag and --compilation_mode=opt are "
139-
+ "specified.")
140-
public boolean enableBinaryStripping;
141-
142122
@Option(
143123
name = "ios_signing_cert_name",
144124
defaultValue = "null",

‎src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ public class ObjcConfiguration extends Fragment implements ObjcConfigurationApi<
5353
private final String watchosSimulatorDevice;
5454
private final DottedVersion tvosSimulatorVersion;
5555
private final String tvosSimulatorDevice;
56+
// TODO(b/236152224): Delete after Starlark uses are migrated to CppConfiguration.
5657
private final boolean generateLinkmap;
5758
private final boolean runMemleaks;
59+
// TODO(b/236152224): Delete after Starlark uses are migrated to CppConfiguration.
5860
private final ImmutableList<String> copts;
5961
private final CompilationMode compilationMode;
6062
private final ImmutableList<String> fastbuildOptions;
63+
// TODO(b/236152224): Delete after Starlark uses are migrated to CppConfiguration.
6164
private final boolean enableBinaryStripping;
6265
@Nullable private final String signingCertName;
6366
private final boolean debugWithGlibcxx;
@@ -75,12 +78,12 @@ public ObjcConfiguration(BuildOptions buildOptions) {
7578
this.watchosSimulatorVersion = DottedVersion.maybeUnwrap(objcOptions.watchosSimulatorVersion);
7679
this.tvosSimulatorDevice = objcOptions.tvosSimulatorDevice;
7780
this.tvosSimulatorVersion = DottedVersion.maybeUnwrap(objcOptions.tvosSimulatorVersion);
78-
this.generateLinkmap = objcOptions.generateLinkmap;
81+
this.generateLinkmap = cppOptions.objcGenerateLinkmap;
7982
this.runMemleaks = objcOptions.runMemleaks;
8083
this.copts = ImmutableList.copyOf(cppOptions.objcoptList);
8184
this.compilationMode = Preconditions.checkNotNull(options.compilationMode, "compilationMode");
8285
this.fastbuildOptions = ImmutableList.copyOf(objcOptions.fastbuildOptions);
83-
this.enableBinaryStripping = objcOptions.enableBinaryStripping;
86+
this.enableBinaryStripping = cppOptions.objcEnableBinaryStripping;
8487
this.signingCertName = objcOptions.iosSigningCertName;
8588
this.debugWithGlibcxx = objcOptions.debugWithGlibcxx;
8689
this.deviceDebugEntitlements = objcOptions.deviceDebugEntitlements;

‎src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CppConfigurationApi.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ boolean fissionActiveForCurrentCompilationModeStarlark(StarlarkThread thread)
164164
structField = true)
165165
boolean appleGenerateDsym();
166166

167+
@StarlarkMethod(
168+
name = "objc_generate_linkmap",
169+
doc = "(Apple-only) Whether to generate linkmap artifacts.",
170+
structField = true)
171+
boolean objcGenerateLinkmap();
172+
173+
@StarlarkMethod(
174+
name = "objc_should_strip_binary",
175+
structField = true,
176+
doc = "(Apple-only) whether to perform symbol and dead-code strippings on linked binaries.")
177+
boolean objcShouldStripBinary();
178+
167179
@StarlarkMethod(name = "strip_opts", documented = false, useStarlarkThread = true)
168180
Sequence<String> getStripOptsStarlark(StarlarkThread thread) throws EvalException;
169181

‎src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,10 @@ def _build_common_variables(
111111
)
112112

113113
def _build_feature_configuration(common_variables, for_swift_module_map, support_parse_headers):
114-
activated_crosstool_selectables = []
115114
ctx = common_variables.ctx
116-
OBJC_ACTIONS = [
117-
"objc-compile",
118-
"objc++-compile",
119-
"objc-archive",
120-
"objc-fully-link",
121-
"objc-executable",
122-
"objc++-executable",
123-
]
124-
activated_crosstool_selectables.extend(ctx.features)
125-
activated_crosstool_selectables.extend(OBJC_ACTIONS)
126-
if common_variables.objc_config.should_strip_binary:
127-
activated_crosstool_selectables.append("dead_strip")
128-
129-
if common_variables.objc_config.generate_linkmap:
130-
activated_crosstool_selectables.append("generate_linkmap")
115+
116+
enabled_features = []
117+
enabled_features.extend(ctx.features)
131118

132119
disabled_features = []
133120
disabled_features.extend(ctx.disabled_features)
@@ -141,18 +128,18 @@ def _build_feature_configuration(common_variables, for_swift_module_map, support
141128
disabled_features.append("parse_headers")
142129

143130
if for_swift_module_map:
144-
activated_crosstool_selectables.append("module_maps")
145-
activated_crosstool_selectables.append("compile_all_modules")
146-
activated_crosstool_selectables.append("only_doth_headers_in_module_maps")
147-
activated_crosstool_selectables.append("exclude_private_headers_in_module_maps")
148-
activated_crosstool_selectables.append("module_map_without_extern_module")
131+
enabled_features.append("module_maps")
132+
enabled_features.append("compile_all_modules")
133+
enabled_features.append("only_doth_headers_in_module_maps")
134+
enabled_features.append("exclude_private_headers_in_module_maps")
135+
enabled_features.append("module_map_without_extern_module")
149136
disabled_features.append("generate_submodules")
150137

151138
return cc_common.configure_features(
152139
ctx = common_variables.ctx,
153140
cc_toolchain = common_variables.toolchain,
154141
language = "objc",
155-
requested_features = activated_crosstool_selectables,
142+
requested_features = enabled_features,
156143
unsupported_features = disabled_features,
157144
)
158145

0 commit comments

Comments
 (0)