Skip to content

Commit

Permalink
Remove most Objective-C dbg and opt compiler flags
Browse files Browse the repository at this point in the history
Currently, Bazel sticks some extra compiler flags in when you compile
Objective-C in dbg or opt mode. These flags should really be set in a
CROSSTOOL rather than in the Bazel core, so remove them.

RELNOTES:
Bazel uses fewer compiler flags by default when building Objective-C. In
particular, Bazel no longer sets `-O0`, `-DDEBUG=1`,
`-fstack-protector`, `-fstack-protector-all`, or `-g` in dbg mode, and
Bazel no longer sets `-Os`, `-DNDEBUG=1`, `-Wno-unused-variable`,
`-Winit-self`, or `-Wno-extra` in opt mode. If you want to apply these
flags to your project, you can reenable them in your CROSSTOOL.
PiperOrigin-RevId: 305065752
  • Loading branch information
bbarenblat authored and copybara-github committed Apr 6, 2020
1 parent 5261655 commit 0bbe381
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@
public class ObjcConfiguration extends BuildConfiguration.Fragment
implements ObjcConfigurationApi<PlatformType> {
@VisibleForTesting
static final ImmutableList<String> DBG_COPTS =
ImmutableList.of("-O0", "-DDEBUG=1", "-fstack-protector", "-fstack-protector-all", "-g");

@VisibleForTesting
static final ImmutableList<String> GLIBCXX_DBG_COPTS =
ImmutableList.of(
"-D_GLIBCXX_DEBUG", "-D_GLIBCXX_DEBUG_PEDANTIC", "-D_GLIBCPP_CONCEPT_CHECKS");

@VisibleForTesting
static final ImmutableList<String> OPT_COPTS =
ImmutableList.of(
"-Os", "-DNDEBUG=1", "-Wno-unused-variable", "-Winit-self", "-Wno-extra");

private final DottedVersion iosSimulatorVersion;
private final String iosSimulatorDevice;
private final DottedVersion watchosSimulatorVersion;
Expand Down Expand Up @@ -180,17 +171,14 @@ public ImmutableList<String> getCoptsForCompilationMode() {
switch (compilationMode) {
case DBG:
if (this.debugWithGlibcxx) {
return ImmutableList.<String>builder()
.addAll(DBG_COPTS)
.addAll(GLIBCXX_DBG_COPTS)
.build();
return GLIBCXX_DBG_COPTS;
} else {
return DBG_COPTS;
return ImmutableList.of();
}
case FASTBUILD:
return fastbuildOptions;
case OPT:
return OPT_COPTS;
return ImmutableList.of();
default:
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,6 @@ private static String compilationModeFlag(CompilationMode mode) {
throw new AssertionError();
}

private static List<String> compilationModeCopts(CompilationMode mode) {
switch (mode) {
case DBG:
return ImmutableList.<String>builder()
.addAll(ObjcConfiguration.DBG_COPTS)
.build();
case OPT:
return ObjcConfiguration.OPT_COPTS;
case FASTBUILD:
return FASTBUILD_COPTS;
}
throw new AssertionError();
}

@Override
protected void useConfiguration(String... args) throws Exception {
ImmutableList<String> extraArgs = MockObjcSupport.requiredObjcCrosstoolFlags();
Expand Down Expand Up @@ -972,9 +958,8 @@ protected void checkErrorsWrongFileTypeForSrcsWhenCompiling(RuleType ruleType)

protected void checkClangCoptsForCompilationMode(RuleType ruleType, CompilationMode mode,
CodeCoverageMode codeCoverageMode) throws Exception {
ImmutableList.Builder<String> allExpectedCoptsBuilder = ImmutableList.<String>builder()
.addAll(CompilationSupport.DEFAULT_COMPILER_FLAGS)
.addAll(compilationModeCopts(mode));
ImmutableList.Builder<String> allExpectedCoptsBuilder =
ImmutableList.<String>builder().addAll(CompilationSupport.DEFAULT_COMPILER_FLAGS);

switch (codeCoverageMode) {
case NONE:
Expand Down Expand Up @@ -1008,9 +993,8 @@ protected void checkClangCoptsForCompilationMode(RuleType ruleType, CompilationM
}

protected void checkClangCoptsForDebugModeWithoutGlib(RuleType ruleType) throws Exception {
ImmutableList.Builder<String> allExpectedCoptsBuilder = ImmutableList.<String>builder()
.addAll(CompilationSupport.DEFAULT_COMPILER_FLAGS)
.addAll(ObjcConfiguration.DBG_COPTS);
ImmutableList.Builder<String> allExpectedCoptsBuilder =
ImmutableList.<String>builder().addAll(CompilationSupport.DEFAULT_COMPILER_FLAGS);

useConfiguration(
"--apple_platform_type=ios", "--compilation_mode=dbg", "--objc_debug_with_GLIBCXX=false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,15 +812,12 @@ public void testSkylarkCanAccessObjcConfiguration() throws Exception {

@SuppressWarnings("unchecked")
List<String> copts = (List<String>) myInfo.getValue("copts");
@SuppressWarnings("unchecked")
List<String> compilationModeCopts = (List<String>) myInfo.getValue("compilation_mode_copts");
Object iosSimulatorDevice = myInfo.getValue("ios_simulator_device");
Object iosSimulatorVersion = myInfo.getValue("ios_simulator_version");
Object signingCertificateName = myInfo.getValue("signing_certificate_name");
Boolean generateDsym = (Boolean) myInfo.getValue("generate_dsym");

assertThat(copts).contains("-DTestObjcCopt");
assertThat(compilationModeCopts).containsExactlyElementsIn(ObjcConfiguration.OPT_COPTS);
assertThat(iosSimulatorDevice).isEqualTo("'iPhone 6'");
assertThat(iosSimulatorVersion).isEqualTo("8.4");
assertThat(signingCertificateName).isEqualTo("'Apple Developer'");
Expand Down

0 comments on commit 0bbe381

Please sign in to comment.