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 | |
| 24 | // Test that cc_binaries can link against rust_ffi_static libraries. |
| 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 | |
| 47 | // Test that shared libraries cannot be made vendor available until proper support is added. |
| 48 | func TestForbiddenVendorLinkage(t *testing.T) { |
| 49 | testRustError(t, "vendor_available can only be set for rust_ffi_static modules", ` |
| 50 | rust_ffi_shared { |
| 51 | name: "libfoo_vendor", |
| 52 | crate_name: "foo", |
| 53 | srcs: ["foo.rs"], |
| 54 | vendor_available: true, |
| 55 | } |
| 56 | `) |
| 57 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 58 | rust_ffi { |
| 59 | name: "libfoo_vendor", |
| 60 | crate_name: "foo", |
| 61 | srcs: ["foo.rs"], |
| 62 | vendor: true, |
| 63 | } |
| 64 | `) |
| 65 | testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", ` |
| 66 | rust_library { |
| 67 | name: "libfoo_vendor", |
| 68 | crate_name: "foo", |
| 69 | srcs: ["foo.rs"], |
| 70 | vendor: true, |
| 71 | } |
| 72 | `) |
| 73 | } |