Skip to content

Commit

Permalink
Add --incompatible_disable_runtimes_filegroups
Browse files Browse the repository at this point in the history
This change adds cc_toolchain.static_runtime_lib and
cc_toolchain.dynamic_runtime_lib attributes and an incompatible flag that
disables deprecated cc_toolchain.static_runtime_libs and
cc_toolchain.dynamic_runtime_libs.

Issue for the incompatible flag: #6942
Tracking issue for legacy crosstool fields removal: #5883

RELNOTES: Added --incompatible_disable_runtimes_filegroups
(#6942).
PiperOrigin-RevId: 226165743
  • Loading branch information
hlopko authored and Copybara-Service committed Dec 19, 2018
1 parent 0a47505 commit 2f229ad
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 174 deletions.
4 changes: 0 additions & 4 deletions site/docs/tutorial/crosstool.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ different order, but the configuration procedure is the same.
compiler_files = ":empty",
cpu = "asmjs",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = ":empty",
objcopy_files = ":empty",
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
)
Expand Down Expand Up @@ -382,10 +380,8 @@ different order, but the configuration procedure is the same.
compiler_files = ":all",
cpu = "asmjs",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = ":all",
objcopy_files = ":empty",
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ cc_toolchain(
compiler_files = ":%toolchainName%-all_files",
cpu = "%cpu%",
dwp_files = ":%toolchainName%-all_files",
dynamic_runtime_libs = [":%dynamicRuntimeLibs%"],
dynamic_runtime_lib = ":%dynamicRuntimeLibs%",
linker_files = ":%toolchainName%-all_files",
objcopy_files = ":%toolchainName%-all_files",
static_runtime_libs = [":%staticRuntimeLibs%"],
static_runtime_lib = ":%staticRuntimeLibs%",
strip_files = ":%toolchainName%-all_files",
supports_param_files = 0,
toolchain_identifier = "%toolchainName%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class CcToolchainAttributesProvider extends ToolchainInfo implements HasC
private final FdoProfileProvider fdoProfileProvider;
private final FdoProfileProvider xfdoProfileProvider;
private final Label ccToolchainLabel;
private final TransitiveInfoCollection staticRuntimeLib;
private final TransitiveInfoCollection dynamicRuntimeLib;

public CcToolchainAttributesProvider(
RuleContext ruleContext,
Expand Down Expand Up @@ -162,10 +164,17 @@ public CcToolchainAttributesProvider(
this.zipper = ruleContext.getPrerequisiteArtifact(":zipper", Mode.HOST);
this.purposePrefix = Actions.escapeLabel(ruleContext.getLabel()) + "_";
this.runtimeSolibDirBase = "_solib_" + "_" + Actions.escapeLabel(ruleContext.getLabel());
this.staticRuntimeLib = ruleContext.getPrerequisite("static_runtime_lib", Mode.TARGET);
this.dynamicRuntimeLib = ruleContext.getPrerequisite("dynamic_runtime_lib", Mode.TARGET);
this.staticRuntimesLibs =
ImmutableList.copyOf(ruleContext.getPrerequisites("static_runtime_libs", Mode.TARGET));
staticRuntimeLib == null
? ImmutableList.copyOf(ruleContext.getPrerequisites("static_runtime_libs", Mode.TARGET))
: null;
this.dynamicRuntimesLibs =
ImmutableList.copyOf(ruleContext.getPrerequisites("dynamic_runtime_libs", Mode.TARGET));
dynamicRuntimeLib == null
? ImmutableList.copyOf(
ruleContext.getPrerequisites("dynamic_runtime_libs", Mode.TARGET))
: null;
this.ccToolchainConfigInfo =
ruleContext.getPrerequisite(
CcToolchainRule.TOOLCHAIN_CONFIG_ATTR, Mode.TARGET, CcToolchainConfigInfo.PROVIDER);
Expand Down Expand Up @@ -247,6 +256,14 @@ public ImmutableList<? extends TransitiveInfoCollection> getDynamicRuntimesLibs(
return dynamicRuntimesLibs;
}

public TransitiveInfoCollection getStaticRuntimeLib() {
return staticRuntimeLib;
}

public TransitiveInfoCollection getDynamicRuntimeLib() {
return dynamicRuntimeLib;
}

public boolean isSupportsHeaderParsing() {
return supportsHeaderParsing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ static CcToolchainProvider getCcToolchainProvider(
return null;
}


if (fdoInputs != null) {
fdoInputFile = fdoInputs.getFirst();
protoProfileArtifact = fdoInputs.getSecond();
Expand Down Expand Up @@ -472,15 +473,25 @@ static CcToolchainProvider getCcToolchainProvider(
configuration.getBinFragment().getRelative(runtimeSolibDirBase);

// Static runtime inputs.
if (cppConfiguration.disableRuntimesFilegroups()
&& !attributes.getStaticRuntimesLibs().isEmpty()) {
ruleContext.ruleError(
"cc_toolchain.static_runtime_libs attribute is removed, please use "
+ "cc_toolchain.static_runtime_lib (singular) instead. See "
+ "https://github.com/bazelbuild/bazel/issues/6942 for details.");
}
TransitiveInfoCollection staticRuntimeLibDep =
selectDep(attributes.getStaticRuntimesLibs(), toolchainInfo.getStaticRuntimeLibsLabel());
attributes.getStaticRuntimeLib() != null
? attributes.getStaticRuntimeLib()
: selectDep(
attributes.getStaticRuntimesLibs(), toolchainInfo.getStaticRuntimeLibsLabel());
final NestedSet<Artifact> staticRuntimeLinkInputs;
final Artifact staticRuntimeLinkMiddleman;
if (toolchainInfo.supportsEmbeddedRuntimes()) {
if (staticRuntimeLibDep == null) {
throw ruleContext.throwWithRuleError(
"Toolchain supports embedded runtimes, but didn't "
+ "provide static_runtime_libs attribute.");
+ "provide static_runtime_lib attribute.");
}
staticRuntimeLinkInputs =
staticRuntimeLibDep.getProvider(FileProvider.class).getFilesToBuild();
Expand All @@ -504,16 +515,26 @@ static CcToolchainProvider getCcToolchainProvider(
(staticRuntimeLinkMiddleman == null) == staticRuntimeLinkInputs.isEmpty());

// Dynamic runtime inputs.
if (cppConfiguration.disableRuntimesFilegroups()
&& !attributes.getDynamicRuntimesLibs().isEmpty()) {
ruleContext.ruleError(
"cc_toolchain.dynamic_runtime_libs attribute is removed, please use "
+ "cc_toolchain.dynamic_runtime_lib (singular) instead. See "
+ "https://github.com/bazelbuild/bazel/issues/6942 for details.");
}
TransitiveInfoCollection dynamicRuntimeLibDep =
selectDep(attributes.getDynamicRuntimesLibs(), toolchainInfo.getDynamicRuntimeLibsLabel());
attributes.getDynamicRuntimeLib() != null
? attributes.getDynamicRuntimeLib()
: selectDep(
attributes.getDynamicRuntimesLibs(), toolchainInfo.getDynamicRuntimeLibsLabel());
NestedSet<Artifact> dynamicRuntimeLinkSymlinks;
List<Artifact> dynamicRuntimeLinkInputs = new ArrayList<>();
Artifact dynamicRuntimeLinkMiddleman;
if (toolchainInfo.supportsEmbeddedRuntimes()) {
if (dynamicRuntimeLibDep == null) {
throw ruleContext.throwWithRuleError(
"Toolchain supports embedded runtimes, but didn't "
+ "provide dynamic_runtime_libs attribute.");
+ "provide dynamic_runtime_lib attribute.");
}
NestedSetBuilder<Artifact> dynamicRuntimeLinkSymlinksBuilder = NestedSetBuilder.stableOrder();
for (Artifact artifact :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,21 @@ Currently unused (<a href="https://github.com/bazelbuild/bazel/issues/6928">#692
all_files are used.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("coverage_files", LABEL).legacyAllowAnyFileType().cfg(HostTransition.INSTANCE))
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(static_runtime_lib) -->
Static library artifact for the C++ runtime library (e.g. libstdc++.a).
<p>When specified, this will take precedence over 'static_runtime_libs'.</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("static_runtime_lib", LABEL).legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(dynamic_runtime_lib) -->
Dynamic library artifact for the C++ runtime library (e.g. libstdc++.so).
<p>When specified, this will take precedence over 'dynamic_runtime_libs'.</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("dynamic_runtime_lib", LABEL).legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(static_runtime_libs) -->
Deprecated, use 'static_runtime_lib'
(see <a href="https://github.com/bazelbuild/bazel/issues/6942">#6942</a>).
A collection of artifacts for static libraries for the C++ runtime library
(e.g. libstdc++.a).
Expand All @@ -223,6 +237,8 @@ Currently unused (<a href="https://github.com/bazelbuild/bazel/issues/6928">#692
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("static_runtime_libs", LABEL_LIST).legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(dynamic_runtime_libs) -->
Deprecated, use 'dynamic_runtime_lib'
(see <a href="https://github.com/bazelbuild/bazel/issues/6942">#6942</a>).
A collection of artifacts for dynamic libraries for the C++ runtime library
(e.g. libstdc++.so).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ boolean enableCcToolchainConfigInfoFromSkylark() {
return cppOptions.enableCcToolchainConfigInfoFromSkylark;
}

boolean disableRuntimesFilegroups() {
return cppOptions.disableRuntimesFilegroups;
}

/**
* Returns the value of the libc top-level directory (--grte_top) as specified on the command line
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,21 @@ public Label getFdoPrefetchHintsLabel() {
+ "the responsibility of the C++ toolchain to append this flag.")
public boolean disableEmittingStaticLibgcc;

@Option(
name = "incompatible_disable_runtimes_filegroups",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If true, cc_toolchain.static_runtime_libs and cc_toolchain.dynamic_runtime_libs are "
+ "replaced by cc_toolchain.static_runtime_lib and cc_toolchain.dynamic_runtime_lib "
+ "(see https://github.com/bazelbuild/bazel/issues/6942)")
public boolean disableRuntimesFilegroups;

@Option(
name = "experimental_enable_cc_toolchain_config_info",
defaultValue = "false",
Expand Down
2 changes: 2 additions & 0 deletions src/main/protobuf/crosstool_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ message CToolchain {
// If specified, Blaze finds statically linked / dynamically linked runtime
// libraries in the declared crosstool filegroup. Otherwise, Blaze
// looks in "[static|dynamic]-runtime-libs-$TARGET_CPU".
// Deprecated, see https://github.com/bazelbuild/bazel/issues/6942
optional string static_runtimes_filegroup = 45;
// Deprecated, see https://github.com/bazelbuild/bazel/issues/6942
optional string dynamic_runtimes_filegroup = 46;
optional bool supports_incremental_linker = 41 [default = false];
// This should be true, if the toolchain supports the D flag to ar, which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ public void testCcToolchainLicenseOverride() throws Exception {
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-cherry',",
" all_files = ':every-file',",
" dynamic_runtime_libs = ['dynamic-runtime-libs-cherry'],",
" static_runtime_libs = ['static-runtime-libs-cherry'])");
" dynamic_runtime_lib = 'dynamic-runtime-libs-cherry',",
" static_runtime_lib = 'static-runtime-libs-cherry')");
scratch.file("c/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());

ConfiguredTarget target = getConfiguredTarget("//c:c");
Expand Down
Loading

0 comments on commit 2f229ad

Please sign in to comment.