Skip to content

Commit

Permalink
Add support for versioned shared libraries in CcImport
Browse files Browse the repository at this point in the history
Permit ".so" files with "version extension" strings in CcImport rules using
existing shared version matcher.

Allows use of files like "foo.so.1a2"

PiperOrigin-RevId: 284166839
  • Loading branch information
Googler authored and Copybara-Service committed Dec 6, 2019
1 parent e810227 commit 5efc8c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
or <code>.dylib</code>
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("shared_library", LABEL).allowedFileTypes(CppFileTypes.SHARED_LIBRARY))
.add(
attr("shared_library", LABEL)
.allowedFileTypes(
CppFileTypes.SHARED_LIBRARY, CppFileTypes.VERSIONED_SHARED_LIBRARY))
/*<!-- #BLAZE_RULE($cc_import).ATTRIBUTE(interface_library) -->
A single interface library for linking the shared library.
<p> Permitted file types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@ public void testCcImportWithSharedLibrary() throws Exception {
.containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so");
}

@Test
public void testCcImportWithVersionedSharedLibrary() throws Exception {
useConfiguration("--cpu=k8");
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
"foo",
skylarkImplementationLoadStatement,
"cc_import(name = 'foo', shared_library = 'libfoo.so.1ab2.1_a2')");
Artifact dynamicLibrary =
Iterables.getOnlyElement(target.get(CcInfo.PROVIDER).getCcLinkingContext().getLibraries())
.getResolvedSymlinkDynamicLibrary();
Iterable<Artifact> dynamicLibrariesForRuntime =
target
.get(CcInfo.PROVIDER)
.getCcLinkingContext()
.getDynamicLibrariesForRuntime(/* linkingStatically= */ false);
assertThat(artifactsToStrings(ImmutableList.of(dynamicLibrary)))
.containsExactly("src a/libfoo.so.1ab2.1_a2");
assertThat(artifactsToStrings(dynamicLibrariesForRuntime))
.containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so.1ab2.1_a2");
}

@Test
public void testCcImportWithInvalidVersionedSharedLibrary() throws Exception {
checkError(
"a",
"foo",
"does not produce any cc_import shared_library files " + "(expected .so, .dylib or .dll)",
skylarkImplementationLoadStatement,
"cc_import(",
" name = 'foo',",
" shared_library = 'libfoo.so.1ab2.ab',",
")");
}

@Test
public void testCcImportWithInterfaceSharedLibrary() throws Exception {
useConfiguration("--cpu=k8");
Expand Down

0 comments on commit 5efc8c4

Please sign in to comment.