Skip to content

Commit

Permalink
Set a default value for --host_crosstool_top.
Browse files Browse the repository at this point in the history
Previously it was unset and defaulted to --crosstool_top, but that
doesn't make sense for android/apple/etc builds.

Ideally we would set --host_crosstool_top to the value of
--crosstool_top at the beginning of the build, but that isn't currently
possible.
  • Loading branch information
katre committed Sep 14, 2020
1 parent aa42a99 commit cdb1f0f
Showing 1 changed file with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,35 @@ public Label getFdoPrefetchHintsLabel() {
+ "except bar.o.")
public List<PerLabelOptions> perFileLtoBackendOpts;

/** See {@link #hostCrosstoolTop} documentation. * */
private static final String HOST_CROSSTOOL_TOP_NOT_YET_SET = "HOST CROSSTOOL TOP NOT YET SET";

/**
* The value of "--crosstool_top" to use for building tools.
*
* <p>We want to make sure this stays bound to the top-level configuration when not explicitly set
* (as opposed to a configuration that comes out of a transition). Otherwise we risk using the
* wrong crosstool (i.e., trying to build tools with an Android-specific crosstool).
*
* <p>To accomplish this, we initialize this to a special value that means "I haven't been set
* yet" and use {@link #getNormalized} to rewrite it to {@link #hostCrosstoolTop} <b>only</b> from
* that default. Blaze always evaluates top-level configurations first, so they'll trigger this.
* But no followup transitions can.
*/
@Option(
name = "host_crosstool_top",
defaultValue = "null",
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {
OptionEffectTag.LOADING_AND_ANALYSIS,
OptionEffectTag.CHANGES_INPUTS,
OptionEffectTag.AFFECTS_OUTPUTS
},
help =
"By default, the --crosstool_top and --compiler options are also used "
+ "for the host configuration. If this flag is provided, Bazel uses the default libc "
+ "and compiler for the given crosstool_top."
)
name = "host_crosstool_top",
defaultValue = HOST_CROSSTOOL_TOP_NOT_YET_SET,
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {
OptionEffectTag.LOADING_AND_ANALYSIS,
OptionEffectTag.CHANGES_INPUTS,
OptionEffectTag.AFFECTS_OUTPUTS
},
help =
"By default, the --crosstool_top and --compiler options are also used "
+ "for the host configuration. If this flag is provided, Bazel uses the default libc "
+ "and compiler for the given crosstool_top.")
public Label hostCrosstoolTop;

@Option(
Expand Down Expand Up @@ -1004,10 +1018,20 @@ public Label getFdoPrefetchHintsLabel() {
/** See {@link #targetLibcTopLabel} documentation. * */
@Override
public FragmentOptions getNormalized() {
CppOptions newOptions = (CppOptions) this.clone();
boolean changed = false;
if (targetLibcTopLabel != null
&& targetLibcTopLabel.getName().equals(TARGET_LIBC_TOP_NOT_YET_SET)) {
CppOptions newOptions = (CppOptions) this.clone();
newOptions.targetLibcTopLabel = libcTopLabel;
changed = true;
}
if (hostCrosstoolTop != null
&& hostCrosstoolTop.getName().equals(HOST_CROSSTOOL_TOP_NOT_YET_SET)) {
// Default to the initial target crosstoolTop.
newOptions.hostCrosstoolTop = crosstoolTop;
changed = true;
}
if (changed) {
return newOptions;
}
return this;
Expand All @@ -1017,14 +1041,8 @@ public FragmentOptions getNormalized() {
public FragmentOptions getHost() {
CppOptions host = (CppOptions) getDefault();

// The crosstool options are partially copied from the target configuration.
if (hostCrosstoolTop == null) {
host.cppCompiler = cppCompiler;
host.crosstoolTop = crosstoolTop;
} else {
host.crosstoolTop = hostCrosstoolTop;
host.cppCompiler = hostCppCompiler;
}
host.crosstoolTop = hostCrosstoolTop;
host.cppCompiler = hostCppCompiler;

// hostLibcTop doesn't default to the target's libcTop.
// Only an explicit command-line option will change it.
Expand Down

0 comments on commit cdb1f0f

Please sign in to comment.