rust: Change default variants

rust_library now produces only rlib and dylib variants.
rust_library_foreign now produces static and shared variants.

This change was made because both are common cases, but all four
together essentially never happens. This allows us to have fewer repeat
module definitions.

Bug: 143217452
Test: cd external/rust; mma
Change-Id: Iaf69e8da38f7c12710331c51464699cf7cbbb656
This commit is contained in:
Matthew Maurer 2020-06-23 14:28:53 -07:00
parent 128f53b3b4
commit 2ae0513a8e
7 changed files with 103 additions and 52 deletions

View File

@ -32,14 +32,14 @@ func TestClippy(t *testing.T) {
clippy: false, clippy: false,
}`) }`)
ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Output("libfoo.so") ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Output("libfoo.dylib.so")
fooClippy := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").MaybeRule("clippy") fooClippy := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
if fooClippy.Rule.String() != "android/soong/rust.clippy" { if fooClippy.Rule.String() != "android/soong/rust.clippy" {
t.Errorf("Clippy output (default) for libfoo was not generated: %+v", fooClippy) t.Errorf("Clippy output (default) for libfoo was not generated: %+v", fooClippy)
} }
ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_shared").Output("libfoobar.so") ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").Output("libfoobar.dylib.so")
foobarClippy := ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_shared").MaybeRule("clippy") foobarClippy := ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
if foobarClippy.Rule != nil { if foobarClippy.Rule != nil {
t.Errorf("Clippy output for libfoobar is not empty") t.Errorf("Clippy output for libfoobar is not empty")
} }

View File

@ -15,13 +15,15 @@ var (
"rust_library", "rust_library",
"rust_library_dylib", "rust_library_dylib",
"rust_library_rlib", "rust_library_rlib",
"rust_library_shared", "rust_ffi",
"rust_library_static", "rust_ffi_shared",
"rust_ffi_static",
"rust_library_host", "rust_library_host",
"rust_library_host_dylib", "rust_library_host_dylib",
"rust_library_host_rlib", "rust_library_host_rlib",
"rust_library_host_shared", "rust_ffi_host",
"rust_library_host_static", "rust_ffi_host_shared",
"rust_ffi_host_static",
"rust_proc_macro", "rust_proc_macro",
"rust_test", "rust_test",
"rust_test_host", "rust_test_host",

View File

@ -105,6 +105,12 @@ func TestCoverageZip(t *testing.T) {
rlibs: ["librlib"], rlibs: ["librlib"],
crate_name: "foo", crate_name: "foo",
} }
rust_ffi_static {
name: "libbaz",
srcs: ["foo.rs"],
rlibs: ["librlib"],
crate_name: "baz",
}
rust_library_rlib { rust_library_rlib {
name: "librlib", name: "librlib",
srcs: ["foo.rs"], srcs: ["foo.rs"],
@ -113,17 +119,17 @@ func TestCoverageZip(t *testing.T) {
rust_binary { rust_binary {
name: "fizz", name: "fizz",
rlibs: ["librlib"], rlibs: ["librlib"],
static_libs: ["libfoo"], static_libs: ["libbaz"],
srcs: ["foo.rs"], srcs: ["foo.rs"],
} }
cc_binary { cc_binary {
name: "buzz", name: "buzz",
static_libs: ["libfoo"], static_libs: ["libbaz"],
srcs: ["foo.c"], srcs: ["foo.c"],
} }
cc_library { cc_library {
name: "libbar", name: "libbar",
static_libs: ["libfoo"], static_libs: ["libbaz"],
compile_multilib: "64", compile_multilib: "64",
srcs: ["foo.c"], srcs: ["foo.c"],
}`) }`)
@ -149,7 +155,7 @@ func TestCoverageZip(t *testing.T) {
// Make sure the expected inputs are provided to the zip rule. // Make sure the expected inputs are provided to the zip rule.
if !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") || if !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") ||
!android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") || !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_static_cov/libbaz.gcno") ||
!android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_cov/fizz.gcno") { !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_cov/fizz.gcno") {
t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", fizzZipInputs) t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", fizzZipInputs)
} }
@ -158,11 +164,11 @@ func TestCoverageZip(t *testing.T) {
t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", libfooZipInputs) t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", libfooZipInputs)
} }
if !android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_cov/obj/foo.gcno") || if !android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_cov/obj/foo.gcno") ||
!android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") { !android.SuffixInList(buzzZipInputs, "android_arm64_armv8-a_static_cov/libbaz.gcno") {
t.Fatalf("missing expected coverage files for cc 'buzz' binary: %#v", buzzZipInputs) t.Fatalf("missing expected coverage files for cc 'buzz' binary: %#v", buzzZipInputs)
} }
if !android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/obj/foo.gcno") || if !android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/obj/foo.gcno") ||
!android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/libfoo.gcno") { !android.SuffixInList(libbarZipInputs, "android_arm64_armv8-a_static_cov/libbaz.gcno") {
t.Fatalf("missing expected coverage files for cc 'libbar' library: %#v", libbarZipInputs) t.Fatalf("missing expected coverage files for cc 'libbar' library: %#v", libbarZipInputs)
} }
} }

View File

@ -29,10 +29,12 @@ func init() {
android.RegisterModuleType("rust_library_host", RustLibraryHostFactory) android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
android.RegisterModuleType("rust_library_shared", RustLibrarySharedFactory) android.RegisterModuleType("rust_ffi", RustFFIFactory)
android.RegisterModuleType("rust_library_static", RustLibraryStaticFactory) android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
android.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory) android.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
android.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory) android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
} }
type VariantLibraryProperties struct { type VariantLibraryProperties struct {
@ -96,6 +98,8 @@ type libraryInterface interface {
setStatic() setStatic()
// Build a specific library variant // Build a specific library variant
BuildOnlyFFI()
BuildOnlyRust()
BuildOnlyRlib() BuildOnlyRlib()
BuildOnlyDylib() BuildOnlyDylib()
BuildOnlyStatic() BuildOnlyStatic()
@ -185,9 +189,17 @@ func (library *libraryDecorator) setStatic() {
var _ compiler = (*libraryDecorator)(nil) var _ compiler = (*libraryDecorator)(nil)
var _ libraryInterface = (*libraryDecorator)(nil) var _ libraryInterface = (*libraryDecorator)(nil)
// rust_library produces all variants. // rust_library produces all rust variants.
func RustLibraryFactory() android.Module { func RustLibraryFactory() android.Module {
module, _ := NewRustLibrary(android.HostAndDeviceSupported) module, library := NewRustLibrary(android.HostAndDeviceSupported)
library.BuildOnlyRust()
return module.Init()
}
// rust_ffi produces all ffi variants.
func RustFFIFactory() android.Module {
module, library := NewRustLibrary(android.HostAndDeviceSupported)
library.BuildOnlyFFI()
return module.Init() return module.Init()
} }
@ -205,23 +217,31 @@ func RustLibraryRlibFactory() android.Module {
return module.Init() return module.Init()
} }
// rust_library_shared produces a shared library. // rust_ffi_shared produces a shared library.
func RustLibrarySharedFactory() android.Module { func RustFFISharedFactory() android.Module {
module, library := NewRustLibrary(android.HostAndDeviceSupported) module, library := NewRustLibrary(android.HostAndDeviceSupported)
library.BuildOnlyShared() library.BuildOnlyShared()
return module.Init() return module.Init()
} }
// rust_library_static produces a static library. // rust_ffi_static produces a static library.
func RustLibraryStaticFactory() android.Module { func RustFFIStaticFactory() android.Module {
module, library := NewRustLibrary(android.HostAndDeviceSupported) module, library := NewRustLibrary(android.HostAndDeviceSupported)
library.BuildOnlyStatic() library.BuildOnlyStatic()
return module.Init() return module.Init()
} }
// rust_library_host produces all variants. // rust_library_host produces all rust variants.
func RustLibraryHostFactory() android.Module { func RustLibraryHostFactory() android.Module {
module, _ := NewRustLibrary(android.HostSupported) module, library := NewRustLibrary(android.HostSupported)
library.BuildOnlyRust()
return module.Init()
}
// rust_ffi_host produces all FFI variants.
func RustFFIHostFactory() android.Module {
module, library := NewRustLibrary(android.HostSupported)
library.BuildOnlyFFI()
return module.Init() return module.Init()
} }
@ -239,44 +259,60 @@ func RustLibraryRlibHostFactory() android.Module {
return module.Init() return module.Init()
} }
// rust_library_static_host produces a static library. // rust_ffi_static_host produces a static library.
func RustLibraryStaticHostFactory() android.Module { func RustFFIStaticHostFactory() android.Module {
module, library := NewRustLibrary(android.HostSupported) module, library := NewRustLibrary(android.HostSupported)
library.BuildOnlyStatic() library.BuildOnlyStatic()
return module.Init() return module.Init()
} }
// rust_library_shared_host produces an shared library. // rust_ffi_shared_host produces an shared library.
func RustLibrarySharedHostFactory() android.Module { func RustFFISharedHostFactory() android.Module {
module, library := NewRustLibrary(android.HostSupported) module, library := NewRustLibrary(android.HostSupported)
library.BuildOnlyShared() library.BuildOnlyShared()
return module.Init() return module.Init()
} }
func (library *libraryDecorator) BuildOnlyFFI() {
library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildRlib = false
library.MutatedProperties.BuildShared = true
library.MutatedProperties.BuildStatic = true
}
func (library *libraryDecorator) BuildOnlyRust() {
library.MutatedProperties.BuildDylib = true
library.MutatedProperties.BuildRlib = true
library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildStatic = false
}
func (library *libraryDecorator) BuildOnlyDylib() { func (library *libraryDecorator) BuildOnlyDylib() {
library.MutatedProperties.BuildDylib = true
library.MutatedProperties.BuildRlib = false library.MutatedProperties.BuildRlib = false
library.MutatedProperties.BuildShared = false library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildStatic = false library.MutatedProperties.BuildStatic = false
} }
func (library *libraryDecorator) BuildOnlyRlib() { func (library *libraryDecorator) BuildOnlyRlib() {
library.MutatedProperties.BuildDylib = false library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildRlib = true
library.MutatedProperties.BuildShared = false library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildStatic = false library.MutatedProperties.BuildStatic = false
} }
func (library *libraryDecorator) BuildOnlyStatic() { func (library *libraryDecorator) BuildOnlyStatic() {
library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildRlib = false library.MutatedProperties.BuildRlib = false
library.MutatedProperties.BuildDylib = false library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildStatic = true
} }
func (library *libraryDecorator) BuildOnlyShared() { func (library *libraryDecorator) BuildOnlyShared() {
library.MutatedProperties.BuildStatic = false
library.MutatedProperties.BuildRlib = false library.MutatedProperties.BuildRlib = false
library.MutatedProperties.BuildDylib = false library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildStatic = false
library.MutatedProperties.BuildShared = true
} }
func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
@ -284,10 +320,10 @@ func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorat
library := &libraryDecorator{ library := &libraryDecorator{
MutatedProperties: LibraryMutatedProperties{ MutatedProperties: LibraryMutatedProperties{
BuildDylib: true, BuildDylib: false,
BuildRlib: true, BuildRlib: false,
BuildShared: true, BuildShared: false,
BuildStatic: true, BuildStatic: false,
}, },
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem), baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
} }

View File

@ -29,13 +29,18 @@ func TestLibraryVariants(t *testing.T) {
name: "libfoo", name: "libfoo",
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "foo", crate_name: "foo",
}`) }
rust_ffi_host {
name: "libfoo.ffi",
srcs: ["foo.rs"],
crate_name: "foo"
}`)
// Test all variants are being built. // Test all variants are being built.
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib").Output("libfoo.rlib") libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib").Output("libfoo.rlib")
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so") libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so")
libfooStatic := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_static").Output("libfoo.a") libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static").Output("libfoo.ffi.a")
libfooShared := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Output("libfoo.so") libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared").Output("libfoo.ffi.so")
rlibCrateType := "rlib" rlibCrateType := "rlib"
dylibCrateType := "dylib" dylibCrateType := "dylib"
@ -119,7 +124,7 @@ func TestValidateLibraryStem(t *testing.T) {
func TestSharedLibrary(t *testing.T) { func TestSharedLibrary(t *testing.T) {
ctx := testRust(t, ` ctx := testRust(t, `
rust_library { rust_ffi_shared {
name: "libfoo", name: "libfoo",
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "foo", crate_name: "foo",

View File

@ -164,12 +164,12 @@ func TestLinkPathFromFilePath(t *testing.T) {
// Test to make sure dependencies are being picked up correctly. // Test to make sure dependencies are being picked up correctly.
func TestDepsTracking(t *testing.T) { func TestDepsTracking(t *testing.T) {
ctx := testRust(t, ` ctx := testRust(t, `
rust_library_host_static { rust_ffi_host_static {
name: "libstatic", name: "libstatic",
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "static", crate_name: "static",
} }
rust_library_host_shared { rust_ffi_host_shared {
name: "libshared", name: "libshared",
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "shared", crate_name: "shared",

View File

@ -83,15 +83,17 @@ func CreateTestContext() *android.TestContext {
ctx.RegisterModuleType("rust_test", RustTestFactory) ctx.RegisterModuleType("rust_test", RustTestFactory)
ctx.RegisterModuleType("rust_test_host", RustTestHostFactory) ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
ctx.RegisterModuleType("rust_library", RustLibraryFactory) ctx.RegisterModuleType("rust_library", RustLibraryFactory)
ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
ctx.RegisterModuleType("rust_library_shared", RustLibrarySharedFactory) ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
ctx.RegisterModuleType("rust_library_static", RustLibraryStaticFactory) ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
ctx.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory) ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
ctx.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory) ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {