2019-08-27 21:03:00 +02:00
|
|
|
// Copyright 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2020-06-19 18:32:30 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test that variants are being generated correctly, and that crate-types are correct.
|
|
|
|
func TestLibraryVariants(t *testing.T) {
|
|
|
|
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_host {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
2020-06-23 23:28:53 +02:00
|
|
|
}
|
2022-11-18 11:55:27 +01:00
|
|
|
rust_ffi_host {
|
|
|
|
name: "libfoo.ffi",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo"
|
|
|
|
}`)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2019-10-18 23:49:46 +02:00
|
|
|
// Test all variants are being built.
|
2024-05-14 03:03:34 +02:00
|
|
|
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static").Rule("rustc")
|
2021-11-05 21:36:47 +01:00
|
|
|
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
|
|
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
2024-05-14 03:03:34 +02:00
|
|
|
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
2021-11-05 21:36:47 +01:00
|
|
|
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared").Rule("rustc")
|
2019-10-18 23:49:46 +02:00
|
|
|
|
|
|
|
rlibCrateType := "rlib"
|
|
|
|
dylibCrateType := "dylib"
|
|
|
|
sharedCrateType := "cdylib"
|
2022-11-18 11:52:57 +01:00
|
|
|
staticCrateType := "staticlib"
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// Test crate type for rlib is correct.
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
|
|
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooRlib.Args["rustcFlags"])
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test crate type for dylib is correct.
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type="+dylibCrateType) {
|
|
|
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"])
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test crate type for C static libraries is correct.
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooStatic.Args["rustcFlags"], "crate-type="+staticCrateType) {
|
|
|
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.Args["rustcFlags"])
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2019-10-18 23:49:46 +02:00
|
|
|
|
2024-05-14 03:03:34 +02:00
|
|
|
// Test crate type for FFI rlibs is correct
|
|
|
|
if !strings.Contains(libfooFFIRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
|
|
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooFFIRlib.Args["rustcFlags"])
|
|
|
|
}
|
|
|
|
|
2019-10-18 23:49:46 +02:00
|
|
|
// Test crate type for C shared libraries is correct.
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooShared.Args["rustcFlags"], "crate-type="+sharedCrateType) {
|
|
|
|
t.Errorf("missing crate-type for shared variant, expecting %#v, got rustcFlags: %#v", sharedCrateType, libfooShared.Args["rustcFlags"])
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that dylibs are not statically linking the standard library.
|
|
|
|
func TestDylibPreferDynamic(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_host_dylib {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}`)
|
|
|
|
|
2023-09-22 05:58:59 +02:00
|
|
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") {
|
|
|
|
t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
2021-07-08 04:05:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we are passing the android_dylib config flag
|
|
|
|
func TestAndroidDylib(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_host_dylib {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}`)
|
|
|
|
|
2023-09-22 05:58:59 +02:00
|
|
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
2021-07-08 04:05:02 +02:00
|
|
|
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooDylib.Args["rustcFlags"], "--cfg 'android_dylib'") {
|
|
|
|
t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-01 03:38:29 +01:00
|
|
|
|
|
|
|
func TestValidateLibraryStem(t *testing.T) {
|
|
|
|
testRustError(t, "crate_name must be defined.", `
|
|
|
|
rust_library_host {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
}`)
|
|
|
|
|
|
|
|
testRustError(t, "library crate_names must be alphanumeric with underscores allowed", `
|
|
|
|
rust_library_host {
|
|
|
|
name: "libfoo-bar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo-bar"
|
|
|
|
}`)
|
|
|
|
|
|
|
|
testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", `
|
|
|
|
rust_library_host {
|
|
|
|
name: "foobar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo_bar"
|
|
|
|
}`)
|
|
|
|
testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", `
|
|
|
|
rust_library_host {
|
|
|
|
name: "foobar",
|
|
|
|
stem: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo_bar"
|
|
|
|
}`)
|
|
|
|
testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", `
|
|
|
|
rust_library_host {
|
|
|
|
name: "foobar",
|
|
|
|
stem: "foo_bar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo_bar"
|
|
|
|
}`)
|
|
|
|
|
|
|
|
}
|
2020-06-09 14:27:49 +02:00
|
|
|
|
2020-06-19 18:32:30 +02:00
|
|
|
func TestSharedLibrary(t *testing.T) {
|
2020-06-09 14:27:49 +02:00
|
|
|
ctx := testRust(t, `
|
2020-06-23 23:28:53 +02:00
|
|
|
rust_ffi_shared {
|
2020-06-09 14:27:49 +02:00
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}`)
|
|
|
|
|
2020-06-19 18:32:30 +02:00
|
|
|
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared")
|
|
|
|
|
2023-10-02 20:39:17 +02:00
|
|
|
libfooOutput := libfoo.Rule("rustc")
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(libfooOutput.Args["linkFlags"], "-Wl,-soname=libfoo.so") {
|
2020-06-19 18:32:30 +02:00
|
|
|
t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v",
|
2023-09-22 05:58:59 +02:00
|
|
|
libfooOutput.Args["linkFlags"])
|
2020-06-19 18:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkDylibs) {
|
|
|
|
t.Errorf("Non-static libstd dylib expected to be a dependency of Rust shared libraries. Dylib deps are: %#v",
|
|
|
|
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
2020-06-09 14:27:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-29 23:34:06 +02:00
|
|
|
|
2021-11-03 20:30:18 +01:00
|
|
|
func TestSharedLibraryToc(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_ffi_shared {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}
|
|
|
|
cc_binary {
|
|
|
|
name: "fizzbuzz",
|
|
|
|
shared_libs: ["libfoo"],
|
|
|
|
}`)
|
|
|
|
|
|
|
|
fizzbuzz := ctx.ModuleForTests("fizzbuzz", "android_arm64_armv8-a").Rule("ld")
|
|
|
|
|
|
|
|
if !android.SuffixInList(fizzbuzz.Implicits.Strings(), "libfoo.so.toc") {
|
|
|
|
t.Errorf("missing expected libfoo.so.toc implicit dependency, instead found: %#v",
|
|
|
|
fizzbuzz.Implicits.Strings())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:31:23 +02:00
|
|
|
func TestStaticLibraryLinkage(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
2024-05-14 03:03:34 +02:00
|
|
|
rust_ffi {
|
2020-08-18 20:31:23 +02:00
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}`)
|
|
|
|
|
2024-05-14 03:03:34 +02:00
|
|
|
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_rlib-std")
|
|
|
|
libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
|
2020-08-18 20:31:23 +02:00
|
|
|
|
|
|
|
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkRlibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("Static libstd rlib expected to be a dependency of Rust rlib libraries. Rlib deps are: %#v",
|
|
|
|
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
|
|
|
}
|
|
|
|
if !android.InList("libstd", libfooStatic.Module().(*Module).Properties.AndroidMkRlibs) {
|
2020-08-18 20:31:23 +02:00
|
|
|
t.Errorf("Static libstd rlib expected to be a dependency of Rust static libraries. Rlib deps are: %#v",
|
|
|
|
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:46:39 +02:00
|
|
|
func TestNativeDependencyOfRlib(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
2024-05-14 03:03:34 +02:00
|
|
|
rust_ffi_rlib {
|
|
|
|
name: "libffi_rlib",
|
|
|
|
crate_name: "ffi_rlib",
|
|
|
|
rlibs: ["librust_rlib"],
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
}
|
2023-08-17 21:46:39 +02:00
|
|
|
rust_ffi_static {
|
|
|
|
name: "libffi_static",
|
|
|
|
crate_name: "ffi_static",
|
|
|
|
rlibs: ["librust_rlib"],
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
}
|
|
|
|
rust_library_rlib {
|
|
|
|
name: "librust_rlib",
|
|
|
|
crate_name: "rust_rlib",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
shared_libs: ["shared_cc_dep"],
|
|
|
|
static_libs: ["static_cc_dep"],
|
|
|
|
}
|
|
|
|
cc_library_shared {
|
|
|
|
name: "shared_cc_dep",
|
|
|
|
srcs: ["foo.cpp"],
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_cc_dep",
|
|
|
|
srcs: ["foo.cpp"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
rustRlibRlibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
|
|
|
rustRlibDylibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_dylib-std")
|
|
|
|
ffiStatic := ctx.ModuleForTests("libffi_static", "android_arm64_armv8-a_static")
|
2024-05-14 03:03:34 +02:00
|
|
|
ffiRlib := ctx.ModuleForTests("libffi_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
2023-08-17 21:46:39 +02:00
|
|
|
|
|
|
|
modules := []android.TestingModule{
|
|
|
|
rustRlibRlibStd,
|
|
|
|
rustRlibDylibStd,
|
2024-05-14 03:03:34 +02:00
|
|
|
ffiRlib,
|
2023-08-17 21:46:39 +02:00
|
|
|
ffiStatic,
|
|
|
|
}
|
|
|
|
|
|
|
|
// librust_rlib specifies -L flag to cc deps output directory on rustc command
|
|
|
|
// and re-export the cc deps to rdep libffi_static
|
|
|
|
// When building rlib crate, rustc doesn't link the native libraries
|
|
|
|
// The build system assumes the cc deps will be at the final linkage (either a shared library or binary)
|
|
|
|
// Hence, these flags are no-op
|
|
|
|
// TODO: We could consider removing these flags
|
|
|
|
for _, module := range modules {
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
|
|
|
"-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared/") {
|
2023-08-17 21:46:39 +02:00
|
|
|
t.Errorf(
|
2023-09-22 05:58:59 +02:00
|
|
|
"missing -L flag for shared_cc_dep, rustcFlags: %#v",
|
|
|
|
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
2023-08-17 21:46:39 +02:00
|
|
|
)
|
|
|
|
}
|
2023-09-22 05:58:59 +02:00
|
|
|
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
|
|
|
"-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static/") {
|
2023-08-17 21:46:39 +02:00
|
|
|
t.Errorf(
|
2023-09-22 05:58:59 +02:00
|
|
|
"missing -L flag for static_cc_dep, rustcFlags: %#v",
|
|
|
|
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
2023-08-17 21:46:39 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:34:06 +02:00
|
|
|
// Test that variants pull in the right type of rustlib autodep
|
|
|
|
func TestAutoDeps(t *testing.T) {
|
|
|
|
|
|
|
|
ctx := testRust(t, `
|
2022-04-07 18:59:11 +02:00
|
|
|
rust_library_host {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["bar.rs"],
|
|
|
|
crate_name: "bar",
|
|
|
|
}
|
|
|
|
rust_library_host_rlib {
|
|
|
|
name: "librlib_only",
|
|
|
|
srcs: ["bar.rs"],
|
|
|
|
crate_name: "rlib_only",
|
|
|
|
}
|
2020-06-29 23:34:06 +02:00
|
|
|
rust_library_host {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
2022-04-07 18:59:11 +02:00
|
|
|
rustlibs: [
|
|
|
|
"libbar",
|
|
|
|
"librlib_only",
|
|
|
|
],
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
2022-04-07 18:59:11 +02:00
|
|
|
rust_ffi_host {
|
|
|
|
name: "libfoo.ffi",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
rustlibs: [
|
|
|
|
"libbar",
|
|
|
|
"librlib_only",
|
|
|
|
],
|
|
|
|
}`)
|
2020-06-29 23:34:06 +02:00
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std")
|
2020-06-29 23:34:06 +02:00
|
|
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib")
|
2024-05-14 03:03:34 +02:00
|
|
|
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std")
|
2020-06-29 23:34:06 +02:00
|
|
|
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static")
|
|
|
|
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared")
|
|
|
|
|
2024-05-14 03:03:34 +02:00
|
|
|
for _, static := range []android.TestingModule{libfooRlib, libfooStatic, libfooFFIRlib} {
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("libbar.rlib-std", static.Module().(*Module).Properties.AndroidMkRlibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("libbar not present as rlib dependency in static lib: %s", static.Module().Name())
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
|
|
|
if android.InList("libbar", static.Module().(*Module).Properties.AndroidMkDylibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("libbar present as dynamic dependency in static lib: %s", static.Module().Name())
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, dyn := range []android.TestingModule{libfooDylib, libfooShared} {
|
|
|
|
if !android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkDylibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("libbar not present as dynamic dependency in dynamic lib: %s", dyn.Module().Name())
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
2023-06-15 20:21:09 +02:00
|
|
|
if android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkRlibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("libbar present as rlib dependency in dynamic lib: %s", dyn.Module().Name())
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
2023-06-15 20:21:09 +02:00
|
|
|
if !android.InList("librlib_only", dyn.Module().(*Module).Properties.AndroidMkRlibs) {
|
2024-05-14 03:03:34 +02:00
|
|
|
t.Errorf("librlib_only should be selected by rustlibs as an rlib: %s.", dyn.Module().Name())
|
2022-04-07 18:59:11 +02:00
|
|
|
}
|
2020-06-29 23:34:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 13:48:36 +02:00
|
|
|
|
|
|
|
// Test that stripped versions are correctly generated and used.
|
|
|
|
func TestStrippedLibrary(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_dylib {
|
|
|
|
name: "libfoo",
|
|
|
|
crate_name: "foo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
}
|
|
|
|
rust_library_dylib {
|
|
|
|
name: "libbar",
|
|
|
|
crate_name: "bar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
strip: {
|
|
|
|
none: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib")
|
2021-11-05 21:36:47 +01:00
|
|
|
foo.Output("libfoo.dylib.so")
|
|
|
|
foo.Output("unstripped/libfoo.dylib.so")
|
2020-08-27 13:48:36 +02:00
|
|
|
// Check that the `cp` rule is using the stripped version as input.
|
|
|
|
cp := foo.Rule("android.Cp")
|
2021-11-05 21:36:47 +01:00
|
|
|
if strings.HasSuffix(cp.Input.String(), "unstripped/libfoo.dylib.so") {
|
|
|
|
t.Errorf("installed library not based on stripped version: %v", cp.Input)
|
2020-08-27 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2021-11-05 21:36:47 +01:00
|
|
|
fizzBar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeOutput("unstripped/libbar.dylib.so")
|
2020-08-27 13:48:36 +02:00
|
|
|
if fizzBar.Rule != nil {
|
2021-11-05 21:36:47 +01:00
|
|
|
t.Errorf("unstripped library exists, so stripped library has incorrectly been generated")
|
2020-08-27 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-08 18:46:52 +02:00
|
|
|
|
|
|
|
func TestLibstdLinkage(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}
|
|
|
|
rust_ffi {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "bar",
|
|
|
|
rustlibs: ["libfoo"],
|
2020-12-08 20:43:00 +01:00
|
|
|
}
|
|
|
|
rust_ffi {
|
|
|
|
name: "libbar.prefer_rlib",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "bar",
|
|
|
|
rustlibs: ["libfoo"],
|
|
|
|
prefer_rlib: true,
|
2020-09-08 18:46:52 +02:00
|
|
|
}`)
|
|
|
|
|
|
|
|
libfooDylib := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module)
|
|
|
|
libfooRlibStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module)
|
|
|
|
libfooRlibDynamic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module)
|
|
|
|
|
|
|
|
libbarShared := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module().(*Module)
|
|
|
|
libbarStatic := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Module().(*Module)
|
2024-05-14 03:03:34 +02:00
|
|
|
libbarFFIRlib := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module)
|
2020-09-08 18:46:52 +02:00
|
|
|
|
2020-12-08 20:43:00 +01:00
|
|
|
// prefer_rlib works the same for both rust_library and rust_ffi, so a single check is sufficient here.
|
|
|
|
libbarRlibStd := ctx.ModuleForTests("libbar.prefer_rlib", "android_arm64_armv8-a_shared").Module().(*Module)
|
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("libstd", libfooRlibStatic.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("rlib-std variant for device rust_library_rlib does not link libstd as an rlib")
|
|
|
|
}
|
|
|
|
if !android.InList("libstd", libfooRlibDynamic.Properties.AndroidMkDylibs) {
|
|
|
|
t.Errorf("dylib-std variant for device rust_library_rlib does not link libstd as an dylib")
|
|
|
|
}
|
|
|
|
if !android.InList("libstd", libfooDylib.Properties.AndroidMkDylibs) {
|
|
|
|
t.Errorf("Device rust_library_dylib does not link libstd as an dylib")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.InList("libstd", libbarShared.Properties.AndroidMkDylibs) {
|
|
|
|
t.Errorf("Device rust_ffi_shared does not link libstd as an dylib")
|
|
|
|
}
|
|
|
|
if !android.InList("libstd", libbarStatic.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("Device rust_ffi_static does not link libstd as an rlib")
|
|
|
|
}
|
|
|
|
if !android.InList("libfoo.rlib-std", libbarStatic.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("Device rust_ffi_static does not link dependent rustlib rlib-std variant")
|
|
|
|
}
|
2024-05-14 03:03:34 +02:00
|
|
|
if !android.InList("libstd", libbarFFIRlib.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("Device rust_ffi_rlib does not link libstd as an rlib")
|
|
|
|
}
|
|
|
|
if !android.InList("libfoo.rlib-std", libbarFFIRlib.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("Device rust_ffi_rlib does not link dependent rustlib rlib-std variant")
|
|
|
|
}
|
2020-12-08 20:43:00 +01:00
|
|
|
if !android.InList("libstd", libbarRlibStd.Properties.AndroidMkRlibs) {
|
|
|
|
t.Errorf("rust_ffi with prefer_rlib does not link libstd as an rlib")
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
}
|
2024-03-21 18:43:14 +01:00
|
|
|
|
|
|
|
func TestRustFFIExportedIncludes(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_ffi {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "bar",
|
|
|
|
export_include_dirs: ["rust_includes"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.cpp"],
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
host_supported: true,
|
|
|
|
}`)
|
|
|
|
libfooStatic := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_static").Rule("cc")
|
|
|
|
android.AssertStringDoesContain(t, "cFlags for lib module", libfooStatic.Args["cFlags"], " -Irust_includes ")
|
|
|
|
}
|