Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 1 | // Copyright 2020 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | ) |
| 23 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 24 | // Test that cc modules can link against vendor_available rust_ffi_static libraries. |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 25 | func TestVendorLinkage(t *testing.T) { |
| 26 | ctx := testRust(t, ` |
| 27 | cc_binary { |
| 28 | name: "fizz_vendor", |
| 29 | static_libs: ["libfoo_vendor"], |
| 30 | soc_specific: true, |
| 31 | } |
| 32 | rust_ffi_static { |
| 33 | name: "libfoo_vendor", |
| 34 | crate_name: "foo", |
| 35 | srcs: ["foo.rs"], |
| 36 | vendor_available: true, |
| 37 | } |
| 38 | `) |
| 39 | |
| 40 | vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_arm64_armv8-a").Module().(*cc.Module) |
| 41 | |
| 42 | if !android.InList("libfoo_vendor", vendorBinary.Properties.AndroidMkStaticLibs) { |
| 43 | t.Errorf("vendorBinary should have a dependency on libfoo_vendor") |
| 44 | } |
| 45 | } |
| 46 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 47 | // Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries. |
| 48 | func TestVendorRamdiskLinkage(t *testing.T) { |
| 49 | ctx := testRust(t, ` |
| 50 | cc_library_static { |
| 51 | name: "libcc_vendor_ramdisk", |
| 52 | static_libs: ["libfoo_vendor_ramdisk"], |
| 53 | system_shared_libs: [], |
| 54 | vendor_ramdisk_available: true, |
| 55 | } |
| 56 | rust_ffi_static { |
| 57 | name: "libfoo_vendor_ramdisk", |
| 58 | crate_name: "foo", |
| 59 | srcs: ["foo.rs"], |
| 60 | vendor_ramdisk_available: true, |
| 61 | } |
| 62 | `) |
| 63 | |
| 64 | vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_static").Module().(*cc.Module) |
| 65 | |
| 66 | if !android.InList("libfoo_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) { |
| 67 | t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_vendor_ramdisk") |
| 68 | } |
| 69 | } |
| 70 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 71 | // Test that shared libraries cannot be made vendor available until proper support is added. |
| 72 | func TestForbiddenVendorLinkage(t *testing.T) { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 73 | testRustError(t, "cannot be set for rust_ffi or rust_ffi_shared modules.", ` |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 74 | rust_ffi_shared { |
| 75 | name: "libfoo_vendor", |
| 76 | crate_name: "foo", |
| 77 | srcs: ["foo.rs"], |
| 78 | vendor_available: true, |
| 79 | } |
| 80 | `) |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 81 | testRustError(t, "cannot be set for rust_ffi or rust_ffi_shared modules.", ` |
| 82 | rust_ffi_shared { |
| 83 | name: "libfoo_vendor", |
| 84 | crate_name: "foo", |
| 85 | srcs: ["foo.rs"], |
| 86 | vendor_ramdisk_available: true, |
| 87 | } |
| 88 | `) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 89 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 90 | rust_ffi { |
| 91 | name: "libfoo_vendor", |
| 92 | crate_name: "foo", |
| 93 | srcs: ["foo.rs"], |
| 94 | vendor: true, |
| 95 | } |
| 96 | `) |
| 97 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 98 | rust_library { |
| 99 | name: "libfoo_vendor", |
| 100 | crate_name: "foo", |
| 101 | srcs: ["foo.rs"], |
| 102 | vendor: true, |
| 103 | } |
| 104 | `) |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 105 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 106 | rust_binary { |
| 107 | name: "foo_vendor", |
| 108 | crate_name: "foo", |
| 109 | srcs: ["foo.rs"], |
| 110 | vendor: true, |
| 111 | } |
| 112 | `) |
| 113 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 114 | } |