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 ( |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame^] | 18 | "strings" |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/cc" |
| 23 | ) |
| 24 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 25 | // 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] | 26 | func TestVendorLinkage(t *testing.T) { |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame^] | 27 | ctx := testRustVndk(t, ` |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 28 | cc_binary { |
| 29 | name: "fizz_vendor", |
| 30 | static_libs: ["libfoo_vendor"], |
| 31 | soc_specific: true, |
| 32 | } |
| 33 | rust_ffi_static { |
| 34 | name: "libfoo_vendor", |
| 35 | crate_name: "foo", |
| 36 | srcs: ["foo.rs"], |
| 37 | vendor_available: true, |
| 38 | } |
| 39 | `) |
| 40 | |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame^] | 41 | vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor.VER_arm64_armv8-a").Module().(*cc.Module) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 42 | |
| 43 | if !android.InList("libfoo_vendor", vendorBinary.Properties.AndroidMkStaticLibs) { |
| 44 | t.Errorf("vendorBinary should have a dependency on libfoo_vendor") |
| 45 | } |
| 46 | } |
| 47 | |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame^] | 48 | // Test that variants which use the vndk emit the appropriate cfg flag. |
| 49 | func TestImageVndkCfgFlag(t *testing.T) { |
| 50 | ctx := testRustVndk(t, ` |
| 51 | rust_ffi_static { |
| 52 | name: "libfoo", |
| 53 | crate_name: "foo", |
| 54 | srcs: ["foo.rs"], |
| 55 | vendor_available: true, |
| 56 | } |
| 57 | `) |
| 58 | |
| 59 | vendor := ctx.ModuleForTests("libfoo", "android_vendor.VER_arm64_armv8-a_static").Rule("rustc") |
| 60 | |
| 61 | if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vndk'") { |
| 62 | t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"]) |
| 63 | } |
| 64 | } |
| 65 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 66 | // Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries. |
| 67 | func TestVendorRamdiskLinkage(t *testing.T) { |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame^] | 68 | ctx := testRustVndk(t, ` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 69 | cc_library_static { |
| 70 | name: "libcc_vendor_ramdisk", |
| 71 | static_libs: ["libfoo_vendor_ramdisk"], |
| 72 | system_shared_libs: [], |
| 73 | vendor_ramdisk_available: true, |
| 74 | } |
| 75 | rust_ffi_static { |
| 76 | name: "libfoo_vendor_ramdisk", |
| 77 | crate_name: "foo", |
| 78 | srcs: ["foo.rs"], |
| 79 | vendor_ramdisk_available: true, |
| 80 | } |
| 81 | `) |
| 82 | |
| 83 | vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_static").Module().(*cc.Module) |
| 84 | |
| 85 | if !android.InList("libfoo_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) { |
| 86 | t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_vendor_ramdisk") |
| 87 | } |
| 88 | } |
| 89 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 90 | // Test that shared libraries cannot be made vendor available until proper support is added. |
| 91 | func TestForbiddenVendorLinkage(t *testing.T) { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 92 | 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] | 93 | rust_ffi_shared { |
| 94 | name: "libfoo_vendor", |
| 95 | crate_name: "foo", |
| 96 | srcs: ["foo.rs"], |
| 97 | vendor_available: true, |
| 98 | } |
| 99 | `) |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 100 | testRustError(t, "cannot be set for rust_ffi or rust_ffi_shared modules.", ` |
| 101 | rust_ffi_shared { |
| 102 | name: "libfoo_vendor", |
| 103 | crate_name: "foo", |
| 104 | srcs: ["foo.rs"], |
| 105 | vendor_ramdisk_available: true, |
| 106 | } |
| 107 | `) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 108 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 109 | rust_ffi { |
| 110 | name: "libfoo_vendor", |
| 111 | crate_name: "foo", |
| 112 | srcs: ["foo.rs"], |
| 113 | vendor: true, |
| 114 | } |
| 115 | `) |
| 116 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 117 | rust_library { |
| 118 | name: "libfoo_vendor", |
| 119 | crate_name: "foo", |
| 120 | srcs: ["foo.rs"], |
| 121 | vendor: true, |
| 122 | } |
| 123 | `) |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 124 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 125 | rust_binary { |
| 126 | name: "foo_vendor", |
| 127 | crate_name: "foo", |
| 128 | srcs: ["foo.rs"], |
| 129 | vendor: true, |
| 130 | } |
| 131 | `) |
| 132 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 133 | } |