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:
parent
128f53b3b4
commit
2ae0513a8e
|
@ -32,14 +32,14 @@ func TestClippy(t *testing.T) {
|
|||
clippy: false,
|
||||
}`)
|
||||
|
||||
ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Output("libfoo.so")
|
||||
fooClippy := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").MaybeRule("clippy")
|
||||
ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Output("libfoo.dylib.so")
|
||||
fooClippy := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||
if fooClippy.Rule.String() != "android/soong/rust.clippy" {
|
||||
t.Errorf("Clippy output (default) for libfoo was not generated: %+v", fooClippy)
|
||||
}
|
||||
|
||||
ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_shared").Output("libfoobar.so")
|
||||
foobarClippy := ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_shared").MaybeRule("clippy")
|
||||
ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").Output("libfoobar.dylib.so")
|
||||
foobarClippy := ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||
if foobarClippy.Rule != nil {
|
||||
t.Errorf("Clippy output for libfoobar is not empty")
|
||||
}
|
||||
|
|
|
@ -15,13 +15,15 @@ var (
|
|||
"rust_library",
|
||||
"rust_library_dylib",
|
||||
"rust_library_rlib",
|
||||
"rust_library_shared",
|
||||
"rust_library_static",
|
||||
"rust_ffi",
|
||||
"rust_ffi_shared",
|
||||
"rust_ffi_static",
|
||||
"rust_library_host",
|
||||
"rust_library_host_dylib",
|
||||
"rust_library_host_rlib",
|
||||
"rust_library_host_shared",
|
||||
"rust_library_host_static",
|
||||
"rust_ffi_host",
|
||||
"rust_ffi_host_shared",
|
||||
"rust_ffi_host_static",
|
||||
"rust_proc_macro",
|
||||
"rust_test",
|
||||
"rust_test_host",
|
||||
|
|
|
@ -105,6 +105,12 @@ func TestCoverageZip(t *testing.T) {
|
|||
rlibs: ["librlib"],
|
||||
crate_name: "foo",
|
||||
}
|
||||
rust_ffi_static {
|
||||
name: "libbaz",
|
||||
srcs: ["foo.rs"],
|
||||
rlibs: ["librlib"],
|
||||
crate_name: "baz",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "librlib",
|
||||
srcs: ["foo.rs"],
|
||||
|
@ -113,17 +119,17 @@ func TestCoverageZip(t *testing.T) {
|
|||
rust_binary {
|
||||
name: "fizz",
|
||||
rlibs: ["librlib"],
|
||||
static_libs: ["libfoo"],
|
||||
static_libs: ["libbaz"],
|
||||
srcs: ["foo.rs"],
|
||||
}
|
||||
cc_binary {
|
||||
name: "buzz",
|
||||
static_libs: ["libfoo"],
|
||||
static_libs: ["libbaz"],
|
||||
srcs: ["foo.c"],
|
||||
}
|
||||
cc_library {
|
||||
name: "libbar",
|
||||
static_libs: ["libfoo"],
|
||||
static_libs: ["libbaz"],
|
||||
compile_multilib: "64",
|
||||
srcs: ["foo.c"],
|
||||
}`)
|
||||
|
@ -149,7 +155,7 @@ func TestCoverageZip(t *testing.T) {
|
|||
|
||||
// Make sure the expected inputs are provided to the zip rule.
|
||||
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") {
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,12 @@ func init() {
|
|||
android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
|
||||
android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
|
||||
android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
|
||||
android.RegisterModuleType("rust_library_shared", RustLibrarySharedFactory)
|
||||
android.RegisterModuleType("rust_library_static", RustLibraryStaticFactory)
|
||||
android.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory)
|
||||
android.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory)
|
||||
android.RegisterModuleType("rust_ffi", RustFFIFactory)
|
||||
android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
|
||||
android.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
|
||||
android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
|
||||
android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
||||
android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
|
||||
}
|
||||
|
||||
type VariantLibraryProperties struct {
|
||||
|
@ -96,6 +98,8 @@ type libraryInterface interface {
|
|||
setStatic()
|
||||
|
||||
// Build a specific library variant
|
||||
BuildOnlyFFI()
|
||||
BuildOnlyRust()
|
||||
BuildOnlyRlib()
|
||||
BuildOnlyDylib()
|
||||
BuildOnlyStatic()
|
||||
|
@ -185,9 +189,17 @@ func (library *libraryDecorator) setStatic() {
|
|||
var _ compiler = (*libraryDecorator)(nil)
|
||||
var _ libraryInterface = (*libraryDecorator)(nil)
|
||||
|
||||
// rust_library produces all variants.
|
||||
// rust_library produces all rust variants.
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -205,23 +217,31 @@ func RustLibraryRlibFactory() android.Module {
|
|||
return module.Init()
|
||||
}
|
||||
|
||||
// rust_library_shared produces a shared library.
|
||||
func RustLibrarySharedFactory() android.Module {
|
||||
// rust_ffi_shared produces a shared library.
|
||||
func RustFFISharedFactory() android.Module {
|
||||
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyShared()
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
// rust_library_static produces a static library.
|
||||
func RustLibraryStaticFactory() android.Module {
|
||||
// rust_ffi_static produces a static library.
|
||||
func RustFFIStaticFactory() android.Module {
|
||||
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyStatic()
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
// rust_library_host produces all variants.
|
||||
// rust_library_host produces all rust variants.
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -239,44 +259,60 @@ func RustLibraryRlibHostFactory() android.Module {
|
|||
return module.Init()
|
||||
}
|
||||
|
||||
// rust_library_static_host produces a static library.
|
||||
func RustLibraryStaticHostFactory() android.Module {
|
||||
// rust_ffi_static_host produces a static library.
|
||||
func RustFFIStaticHostFactory() android.Module {
|
||||
module, library := NewRustLibrary(android.HostSupported)
|
||||
library.BuildOnlyStatic()
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
// rust_library_shared_host produces an shared library.
|
||||
func RustLibrarySharedHostFactory() android.Module {
|
||||
// rust_ffi_shared_host produces an shared library.
|
||||
func RustFFISharedHostFactory() android.Module {
|
||||
module, library := NewRustLibrary(android.HostSupported)
|
||||
library.BuildOnlyShared()
|
||||
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() {
|
||||
library.MutatedProperties.BuildDylib = true
|
||||
library.MutatedProperties.BuildRlib = false
|
||||
library.MutatedProperties.BuildShared = false
|
||||
library.MutatedProperties.BuildStatic = false
|
||||
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) BuildOnlyRlib() {
|
||||
library.MutatedProperties.BuildDylib = false
|
||||
library.MutatedProperties.BuildRlib = true
|
||||
library.MutatedProperties.BuildShared = false
|
||||
library.MutatedProperties.BuildStatic = false
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) BuildOnlyStatic() {
|
||||
library.MutatedProperties.BuildShared = false
|
||||
library.MutatedProperties.BuildRlib = false
|
||||
library.MutatedProperties.BuildDylib = false
|
||||
|
||||
library.MutatedProperties.BuildShared = false
|
||||
library.MutatedProperties.BuildStatic = true
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) BuildOnlyShared() {
|
||||
library.MutatedProperties.BuildStatic = false
|
||||
library.MutatedProperties.BuildRlib = false
|
||||
library.MutatedProperties.BuildDylib = false
|
||||
library.MutatedProperties.BuildStatic = false
|
||||
library.MutatedProperties.BuildShared = true
|
||||
}
|
||||
|
||||
func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
||||
|
@ -284,10 +320,10 @@ func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorat
|
|||
|
||||
library := &libraryDecorator{
|
||||
MutatedProperties: LibraryMutatedProperties{
|
||||
BuildDylib: true,
|
||||
BuildRlib: true,
|
||||
BuildShared: true,
|
||||
BuildStatic: true,
|
||||
BuildDylib: false,
|
||||
BuildRlib: false,
|
||||
BuildShared: false,
|
||||
BuildStatic: false,
|
||||
},
|
||||
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
||||
}
|
||||
|
|
|
@ -29,13 +29,18 @@ func TestLibraryVariants(t *testing.T) {
|
|||
name: "libfoo",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo",
|
||||
}`)
|
||||
}
|
||||
rust_ffi_host {
|
||||
name: "libfoo.ffi",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo"
|
||||
}`)
|
||||
|
||||
// Test all variants are being built.
|
||||
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")
|
||||
libfooStatic := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_static").Output("libfoo.a")
|
||||
libfooShared := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Output("libfoo.so")
|
||||
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static").Output("libfoo.ffi.a")
|
||||
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared").Output("libfoo.ffi.so")
|
||||
|
||||
rlibCrateType := "rlib"
|
||||
dylibCrateType := "dylib"
|
||||
|
@ -119,7 +124,7 @@ func TestValidateLibraryStem(t *testing.T) {
|
|||
|
||||
func TestSharedLibrary(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
rust_library {
|
||||
rust_ffi_shared {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo",
|
||||
|
|
|
@ -164,12 +164,12 @@ func TestLinkPathFromFilePath(t *testing.T) {
|
|||
// Test to make sure dependencies are being picked up correctly.
|
||||
func TestDepsTracking(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
rust_library_host_static {
|
||||
rust_ffi_host_static {
|
||||
name: "libstatic",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "static",
|
||||
}
|
||||
rust_library_host_shared {
|
||||
rust_ffi_host_shared {
|
||||
name: "libshared",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "shared",
|
||||
|
|
|
@ -83,15 +83,17 @@ func CreateTestContext() *android.TestContext {
|
|||
ctx.RegisterModuleType("rust_test", RustTestFactory)
|
||||
ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
|
||||
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_shared", RustLibrarySharedFactory)
|
||||
ctx.RegisterModuleType("rust_library_static", RustLibraryStaticFactory)
|
||||
ctx.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory)
|
||||
ctx.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory)
|
||||
ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
|
||||
ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
|
||||
ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
|
||||
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_prebuilt_dylib", PrebuiltDylibFactory)
|
||||
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
|
|
Loading…
Reference in New Issue