diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/binary_test.go | 27 | ||||
| -rw-r--r-- | rust/bindgen.go | 2 | ||||
| -rw-r--r-- | rust/builder.go | 20 | ||||
| -rw-r--r-- | rust/compiler.go | 7 | ||||
| -rw-r--r-- | rust/config/global.go | 1 | ||||
| -rw-r--r-- | rust/protobuf.go | 2 | ||||
| -rw-r--r-- | rust/rust_test.go | 10 |
7 files changed, 46 insertions, 23 deletions
diff --git a/rust/binary_test.go b/rust/binary_test.go index dd4f99314..fc4c56037 100644 --- a/rust/binary_test.go +++ b/rust/binary_test.go @@ -21,6 +21,27 @@ import ( "android/soong/android" ) +// Test that rustlibs default linkage is always rlib for host binaries. +func TestBinaryHostLinkage(t *testing.T) { + ctx := testRust(t, ` + rust_binary_host { + name: "fizz-buzz", + srcs: ["foo.rs"], + rustlibs: ["libfoo"], + } + rust_library { + name: "libfoo", + srcs: ["foo.rs"], + crate_name: "foo", + host_supported: true, + } + `) + fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) + if !android.InList("libfoo.rlib-std", fizzBuzz.Properties.AndroidMkRlibs) { + t.Errorf("rustlibs dependency libfoo should be an rlib dep for host binaries") + } +} + // Test that rustlibs default linkage is correct for binaries. func TestBinaryLinkage(t *testing.T) { ctx := testRust(t, ` @@ -54,6 +75,12 @@ func TestBinaryLinkage(t *testing.T) { if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) { t.Errorf("rustlibs dependency libfoo should be an dylib dep for device modules") } + + rlibLinkDevice := ctx.ModuleForTests("rlib_linked", "android_arm64_armv8-a").Module().(*Module) + + if !android.InList("libfoo.rlib-std", rlibLinkDevice.Properties.AndroidMkRlibs) { + t.Errorf("rustlibs dependency libfoo should be an rlib dep for device modules when prefer_rlib is set") + } } // Test that prefer_rlib links in libstd statically as well as rustlibs. diff --git a/rust/bindgen.go b/rust/bindgen.go index c2bf6af4c..407f2754f 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -294,7 +294,7 @@ func (b *bindgenDecorator) SourceProviderProps() []interface{} { // rust_bindgen generates Rust FFI bindings to C libraries using bindgen given a wrapper header as the primary input. // Bindgen has a number of flags to control the generated source, and additional flags can be passed to clang to ensure // the header and generated source is appropriately handled. It is recommended to add it as a dependency in the -// rlibs, dylibs or rustlibs property. It may also be added in the srcs property for external crates, using the ":" +// rlibs or rustlibs property. It may also be added in the srcs property for external crates, using the ":" // prefix. func RustBindgenFactory() android.Module { module, _ := NewRustBindgen(android.HostAndDeviceSupported) diff --git a/rust/builder.go b/rust/builder.go index fbceecc80..b1f049d15 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -45,9 +45,9 @@ var ( "rustcFlags", "libFlags", "envVars") rustLink = pctx.AndroidStaticRule("rustLink", blueprint.RuleParams{ - Command: "${config.RustLinker} -o $out ${crtBegin} ${config.RustLinkerArgs} @$in ${linkFlags} ${crtEnd}", + Command: "${config.RustLinker} -o $out ${crtBegin} ${earlyLinkFlags} @$in ${linkFlags} ${crtEnd}", }, - "linkFlags", "crtBegin", "crtEnd") + "earlyLinkFlags", "linkFlags", "crtBegin", "crtEnd") _ = pctx.SourcePathVariable("rustdocCmd", "${config.RustBin}/rustdoc") rustdoc = pctx.AndroidStaticRule("rustdoc", @@ -244,6 +244,10 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps) []string { envVars = append(envVars, "AR=${cc_config.ClangBin}/llvm-ar") + if ctx.Darwin() { + envVars = append(envVars, "ANDROID_RUST_DARWIN=true") + } + return envVars } @@ -254,6 +258,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl var implicits, linkImplicits, linkOrderOnly android.Paths var output buildOutput var rustcFlags, linkFlags []string + var earlyLinkFlags string output.outputFile = outputFile crateName := ctx.RustModule().CrateName() @@ -292,6 +297,10 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl } // Collect linker flags + if !ctx.Darwin() { + earlyLinkFlags = "-Wl,--as-needed" + } + linkFlags = append(linkFlags, flags.GlobalLinkFlags...) linkFlags = append(linkFlags, flags.LinkFlags...) @@ -391,9 +400,10 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl Implicits: linkImplicits, OrderOnly: linkOrderOnly, Args: map[string]string{ - "linkFlags": strings.Join(linkFlags, " "), - "crtBegin": strings.Join(deps.CrtBegin.Strings(), " "), - "crtEnd": strings.Join(deps.CrtEnd.Strings(), " "), + "earlyLinkFlags": earlyLinkFlags, + "linkFlags": strings.Join(linkFlags, " "), + "crtBegin": strings.Join(deps.CrtBegin.Strings(), " "), + "crtEnd": strings.Join(deps.CrtEnd.Strings(), " "), }, }) } diff --git a/rust/compiler.go b/rust/compiler.go index 06ae12f79..84c1fce9b 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -91,10 +91,8 @@ type BaseCompilerProperties struct { // list of rust rlib crate dependencies Rlibs []string `android:"arch_variant"` - // list of rust dylib crate dependencies - Dylibs []string `android:"arch_variant"` - - // list of rust automatic crate dependencies + // list of rust automatic crate dependencies. + // Rustlibs linkage is rlib for host targets and dylib for device targets. Rustlibs []string `android:"arch_variant"` // list of rust proc_macro crate dependencies @@ -359,7 +357,6 @@ func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath { func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...) - deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...) deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...) deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...) deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...) diff --git a/rust/config/global.go b/rust/config/global.go index c39341e4c..86eb2d1cb 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -102,7 +102,6 @@ func init() { pctx.ImportAs("cc_config", "android/soong/cc/config") pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++") - pctx.StaticVariable("RustLinkerArgs", "-Wl,--as-needed") pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " ")) diff --git a/rust/protobuf.go b/rust/protobuf.go index 0cf6e8c97..a14ebeaab 100644 --- a/rust/protobuf.go +++ b/rust/protobuf.go @@ -243,7 +243,7 @@ func (proto *protobufDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) D // rust_protobuf generates protobuf rust code from the provided proto file. This uses the protoc-gen-rust plugin for // protoc. Additional flags to the protoc command can be passed via the proto_flags property. This module type will -// create library variants that can be used as a crate dependency by adding it to the rlibs, dylibs, and rustlibs +// create library variants that can be used as a crate dependency by adding it to the rlibs and rustlibs // properties of other modules. func RustProtobufFactory() android.Module { module, _ := NewRustProtobuf(android.HostAndDeviceSupported) diff --git a/rust/rust_test.go b/rust/rust_test.go index 3f4e29676..704bfe785 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -232,11 +232,6 @@ func TestDepsTracking(t *testing.T) { srcs: ["foo.rs"], crate_name: "shared", } - rust_library_host_dylib { - name: "libdylib", - srcs: ["foo.rs"], - crate_name: "dylib", - } rust_library_host_rlib { name: "librlib", srcs: ["foo.rs"], @@ -252,7 +247,6 @@ func TestDepsTracking(t *testing.T) { } rust_binary_host { name: "fizz-buzz", - dylibs: ["libdylib"], rlibs: ["librlib"], proc_macros: ["libpm"], static_libs: ["libstatic"], @@ -265,10 +259,6 @@ func TestDepsTracking(t *testing.T) { rustLink := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustLink") // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up. - if !android.InList("libdylib", module.Properties.AndroidMkDylibs) { - t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)") - } - if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) { t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)") } |