Skip to content

Commit

Permalink
Assume toolchain supportsDynamicLinker from presence of "dynamic_link…
Browse files Browse the repository at this point in the history
…ing_mode" feature

Toolchains no longer have to provide linking_mode_flags { mode: DYNAMIC } to
state that they support dynamic linking mode. It is enough to provide a feature.

This is part of ongoing work to get rid of linking_mode_flags from the
CROSSTOOL.

RELNOTES: None.
PiperOrigin-RevId: 189890583
  • Loading branch information
hlopko authored and Copybara-Service committed Mar 21, 2018
1 parent 755d3be commit 3dab964
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ public static CppToolchainInfo create(
this.supportsFission = supportsFission;
this.supportsStartEndLib = supportsStartEndLib;
this.supportsEmbeddedRuntimes = supportsEmbeddedRuntimes;
this.supportsDynamicLinker = supportsDynamicLinker;
this.supportsDynamicLinker =
supportsDynamicLinker
|| toolchainFeatures
.getActivatableNames()
.contains(CppRuleClasses.DYNAMIC_LINKING_MODE);
this.supportsInterfaceSharedObjects = supportsInterfaceSharedObjects;
this.supportsGoldLinker = supportsGoldLinker;
this.toolchainNeedsPic = toolchainNeedsPic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void setup(MockToolsConfig config) throws IOException {
" toolchains = {",
" 'local|compiler': ':cc-compiler-local',",
" 'k8|compiler': ':cc-compiler-k8',",
" 'k8|compiler_no_dyn_linker': ':cc-no-dyn-compiler-k8',",
" 'piii|compiler': ':cc-compiler-piii',",
" 'darwin|compiler': ':cc-compiler-darwin',",
" 'ios_x86_64|compiler': ':cc-compiler-ios_x86_64',",
Expand All @@ -99,6 +100,13 @@ public void setup(MockToolsConfig config) throws IOException {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
"cc_toolchain(name = 'cc-no-dyn-compiler-k8', all_files = ':empty', ",
" compiler_files = ':empty', cpu = 'k8', compiler = 'compiler_no_dyn_linker', ",
" libc = 'local', dwp_files = ':empty', dynamic_runtime_libs = [':empty'], ",
" ar_files = ':empty', as_files = ':empty', linker_files = ':empty',",
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
"cc_toolchain(name = 'cc-compiler-ppc', all_files = ':empty', compiler_files = ':empty',",
" cpu = 'ppc', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
" dynamic_runtime_libs = [':empty'], ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -128,6 +129,9 @@ public boolean apply(Artifact artifact) {
/** This feature will prevent bazel from patching the crosstool. */
public static final String NO_LEGACY_FEATURES_FEATURE = "feature { name: 'no_legacy_features' }";

public static final String DYNAMIC_LINKING_MODE_FEATURE =
"feature { name: '" + CppRuleClasses.DYNAMIC_LINKING_MODE + "'}";

/** Feature expected by the C++ rules when pic build is requested */
public static final String PIC_FEATURE =
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,4 +912,23 @@ public void testInlineCtoolchain_withToolchainResolution() throws Exception {
(CcToolchainProvider) target.get(ToolchainInfo.PROVIDER);
assertThat(toolchainProvider.getAbi()).isEqualTo("banana");
}

@Test
public void testSupportsDynamicLinkerCheckFeatures() throws Exception {
writeDummyCcToolchain();

getAnalysisMock()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.DYNAMIC_LINKING_MODE_FEATURE);

// To make sure the toolchain doesn't define linking_mode_flags { mode: DYNAMIC } as that would
// also result in supportsDynamicLinker returning true
useConfiguration("--compiler=compiler_no_dyn_linker", "--cpu=k8");

ConfiguredTarget target = getConfiguredTarget("//a:b");
CcToolchainProvider toolchainProvider =
(CcToolchainProvider) target.get(ToolchainInfo.PROVIDER);

assertThat(toolchainProvider.supportsDynamicLinker()).isTrue();
}
}

0 comments on commit 3dab964

Please sign in to comment.