Specify SONAME when building Rust shared libs.
Without specifying -soname, cc binaries are unable to locate Rust provided shared libraries. This adds the -soname linker flag for shared libraries. Bug: 158490355 Test: readelf -d <cc_binary> shows the expected SONAME Change-Id: I66852a7ce24d5ea5e426f11bc1834fb56a150628
This commit is contained in:
parent
3ef493ff91
commit
bec05ea26d
|
@ -329,12 +329,21 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|||
|
||||
return deps
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
|
||||
return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.baseModuleName())
|
||||
flags = library.baseCompiler.compilerFlags(ctx, flags)
|
||||
if library.shared() || library.static() {
|
||||
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
|
||||
}
|
||||
if library.shared() {
|
||||
flags.LinkFlags = append(flags.LinkFlags, "-Wl,-soname="+library.sharedLibFilename(ctx))
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
|
@ -371,7 +380,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||
outputs := TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
||||
library.coverageFile = outputs.coverageFile
|
||||
} else if library.shared() {
|
||||
fileName := library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
|
||||
fileName := library.sharedLibFilename(ctx)
|
||||
outputFile = android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
outputs := TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
||||
|
|
|
@ -114,3 +114,17 @@ func TestValidateLibraryStem(t *testing.T) {
|
|||
}`)
|
||||
|
||||
}
|
||||
|
||||
func TestSharedLibraryFlags(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
rust_library_host {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo",
|
||||
}`)
|
||||
|
||||
libfooShared := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Output("libfoo.so")
|
||||
if !strings.Contains(libfooShared.Args["linkFlags"], "-Wl,-soname=libfoo.so") {
|
||||
t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v", libfooShared.Args["linkFlags"])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue