Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 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 | "strings" |
| 19 | "testing" |
Ivan Lozano | 7e741cc | 2020-06-19 12:32:30 -0400 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | // Test that variants are being generated correctly, and that crate-types are correct. |
| 25 | func TestLibraryVariants(t *testing.T) { |
| 26 | |
| 27 | ctx := testRust(t, ` |
| 28 | rust_library_host { |
| 29 | name: "libfoo", |
| 30 | srcs: ["foo.rs"], |
| 31 | crate_name: "foo", |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 32 | } |
Martin Geisler | bd736da | 2022-11-18 11:55:27 +0100 | [diff] [blame] | 33 | rust_ffi_host { |
| 34 | name: "libfoo.ffi", |
| 35 | srcs: ["foo.rs"], |
| 36 | crate_name: "foo" |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 37 | } |
| 38 | rust_ffi_host_static { |
| 39 | name: "libfoo.ffi_static", |
| 40 | srcs: ["foo.rs"], |
| 41 | crate_name: "foo" |
Martin Geisler | bd736da | 2022-11-18 11:55:27 +0100 | [diff] [blame] | 42 | }`) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 43 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 44 | // Test all variants are being built. |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 45 | libfooRlib := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc") |
| 46 | libfooDylib := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") |
| 47 | libfooFFIRlib := ctx.ModuleForTests(t, "libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc") |
| 48 | libfooShared := ctx.ModuleForTests(t, "libfoo.ffi", "linux_glibc_x86_64_shared").Rule("rustc") |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 49 | |
| 50 | rlibCrateType := "rlib" |
| 51 | dylibCrateType := "dylib" |
| 52 | sharedCrateType := "cdylib" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 53 | |
| 54 | // Test crate type for rlib is correct. |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 55 | if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) { |
| 56 | t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooRlib.Args["rustcFlags"]) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // Test crate type for dylib is correct. |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 60 | if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type="+dylibCrateType) { |
| 61 | t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"]) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 62 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 63 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 64 | // Test crate type for FFI rlibs is correct |
| 65 | if !strings.Contains(libfooFFIRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) { |
| 66 | t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooFFIRlib.Args["rustcFlags"]) |
| 67 | } |
| 68 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 69 | // Test crate type for C shared libraries is correct. |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 70 | if !strings.Contains(libfooShared.Args["rustcFlags"], "crate-type="+sharedCrateType) { |
| 71 | t.Errorf("missing crate-type for shared variant, expecting %#v, got rustcFlags: %#v", sharedCrateType, libfooShared.Args["rustcFlags"]) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // Test that dylibs are not statically linking the standard library. |
| 77 | func TestDylibPreferDynamic(t *testing.T) { |
| 78 | ctx := testRust(t, ` |
| 79 | rust_library_host_dylib { |
| 80 | name: "libfoo", |
| 81 | srcs: ["foo.rs"], |
| 82 | crate_name: "foo", |
| 83 | }`) |
| 84 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 85 | libfooDylib := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 86 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 87 | if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") { |
| 88 | t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 91 | |
| 92 | func TestValidateLibraryStem(t *testing.T) { |
| 93 | testRustError(t, "crate_name must be defined.", ` |
| 94 | rust_library_host { |
| 95 | name: "libfoo", |
| 96 | srcs: ["foo.rs"], |
| 97 | }`) |
| 98 | |
| 99 | testRustError(t, "library crate_names must be alphanumeric with underscores allowed", ` |
| 100 | rust_library_host { |
| 101 | name: "libfoo-bar", |
| 102 | srcs: ["foo.rs"], |
| 103 | crate_name: "foo-bar" |
| 104 | }`) |
| 105 | |
| 106 | testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` |
| 107 | rust_library_host { |
| 108 | name: "foobar", |
| 109 | srcs: ["foo.rs"], |
| 110 | crate_name: "foo_bar" |
| 111 | }`) |
| 112 | testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` |
| 113 | rust_library_host { |
| 114 | name: "foobar", |
| 115 | stem: "libfoo", |
| 116 | srcs: ["foo.rs"], |
| 117 | crate_name: "foo_bar" |
| 118 | }`) |
| 119 | testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` |
| 120 | rust_library_host { |
| 121 | name: "foobar", |
| 122 | stem: "foo_bar", |
| 123 | srcs: ["foo.rs"], |
| 124 | crate_name: "foo_bar" |
| 125 | }`) |
| 126 | |
| 127 | } |
Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 128 | |
Ivan Lozano | 7e741cc | 2020-06-19 12:32:30 -0400 | [diff] [blame] | 129 | func TestSharedLibrary(t *testing.T) { |
Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 130 | ctx := testRust(t, ` |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 131 | rust_ffi_shared { |
Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 132 | name: "libfoo", |
| 133 | srcs: ["foo.rs"], |
| 134 | crate_name: "foo", |
| 135 | }`) |
| 136 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 137 | libfoo := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_shared") |
Ivan Lozano | 7e741cc | 2020-06-19 12:32:30 -0400 | [diff] [blame] | 138 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 139 | libfooOutput := libfoo.Rule("rustc") |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 140 | if !strings.Contains(libfooOutput.Args["linkFlags"], "-Wl,-soname=libfoo.so") { |
Ivan Lozano | 7e741cc | 2020-06-19 12:32:30 -0400 | [diff] [blame] | 141 | t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v", |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 142 | libfooOutput.Args["linkFlags"]) |
Ivan Lozano | 7e741cc | 2020-06-19 12:32:30 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkDylibs) { |
| 146 | t.Errorf("Non-static libstd dylib expected to be a dependency of Rust shared libraries. Dylib deps are: %#v", |
| 147 | libfoo.Module().(*Module).Properties.AndroidMkDylibs) |
Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 148 | } |
| 149 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 150 | |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 151 | func TestSharedLibraryToc(t *testing.T) { |
| 152 | ctx := testRust(t, ` |
| 153 | rust_ffi_shared { |
| 154 | name: "libfoo", |
| 155 | srcs: ["foo.rs"], |
| 156 | crate_name: "foo", |
| 157 | } |
| 158 | cc_binary { |
| 159 | name: "fizzbuzz", |
| 160 | shared_libs: ["libfoo"], |
| 161 | }`) |
| 162 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 163 | fizzbuzz := ctx.ModuleForTests(t, "fizzbuzz", "android_arm64_armv8-a").Rule("ld") |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 164 | |
| 165 | if !android.SuffixInList(fizzbuzz.Implicits.Strings(), "libfoo.so.toc") { |
| 166 | t.Errorf("missing expected libfoo.so.toc implicit dependency, instead found: %#v", |
| 167 | fizzbuzz.Implicits.Strings()) |
| 168 | } |
| 169 | } |
| 170 | |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 171 | func TestStaticLibraryLinkage(t *testing.T) { |
| 172 | ctx := testRust(t, ` |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 173 | rust_ffi_static { |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 174 | name: "libfoo", |
| 175 | srcs: ["foo.rs"], |
| 176 | crate_name: "foo", |
| 177 | }`) |
| 178 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 179 | libfoo := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_rlib_rlib-std") |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 180 | |
| 181 | if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkRlibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 182 | t.Errorf("Static libstd rlib expected to be a dependency of Rust rlib libraries. Rlib deps are: %#v", |
| 183 | libfoo.Module().(*Module).Properties.AndroidMkDylibs) |
| 184 | } |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 187 | func TestNativeDependencyOfRlib(t *testing.T) { |
| 188 | ctx := testRust(t, ` |
Ivan Lozano | 6184842 | 2024-12-13 19:45:00 +0000 | [diff] [blame] | 189 | rust_ffi_static { |
| 190 | name: "libffi_static", |
| 191 | crate_name: "ffi_static", |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 192 | rlibs: ["librust_rlib"], |
| 193 | srcs: ["foo.rs"], |
| 194 | } |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 195 | rust_library_rlib { |
| 196 | name: "librust_rlib", |
| 197 | crate_name: "rust_rlib", |
| 198 | srcs: ["foo.rs"], |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 199 | shared_libs: ["libshared_cc_dep"], |
| 200 | static_libs: ["libstatic_cc_dep"], |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 201 | } |
| 202 | cc_library_shared { |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 203 | name: "libshared_cc_dep", |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 204 | srcs: ["foo.cpp"], |
| 205 | } |
| 206 | cc_library_static { |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 207 | name: "libstatic_cc_dep", |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 208 | srcs: ["foo.cpp"], |
| 209 | } |
| 210 | `) |
| 211 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 212 | rustRlibRlibStd := ctx.ModuleForTests(t, "librust_rlib", "android_arm64_armv8-a_rlib_rlib-std") |
| 213 | rustRlibDylibStd := ctx.ModuleForTests(t, "librust_rlib", "android_arm64_armv8-a_rlib_dylib-std") |
| 214 | ffiRlib := ctx.ModuleForTests(t, "libffi_static", "android_arm64_armv8-a_rlib_rlib-std") |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 215 | |
| 216 | modules := []android.TestingModule{ |
| 217 | rustRlibRlibStd, |
| 218 | rustRlibDylibStd, |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 219 | ffiRlib, |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // librust_rlib specifies -L flag to cc deps output directory on rustc command |
| 223 | // and re-export the cc deps to rdep libffi_static |
| 224 | // When building rlib crate, rustc doesn't link the native libraries |
| 225 | // The build system assumes the cc deps will be at the final linkage (either a shared library or binary) |
| 226 | // Hence, these flags are no-op |
| 227 | // TODO: We could consider removing these flags |
| 228 | for _, module := range modules { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 229 | if !strings.Contains(module.Rule("rustc").Args["libFlags"], |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 230 | "-L out/soong/.intermediates/libshared_cc_dep/android_arm64_armv8-a_shared/") { |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 231 | t.Errorf( |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 232 | "missing -L flag for libshared_cc_dep of %s, rustcFlags: %#v", |
| 233 | module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"], |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 234 | ) |
| 235 | } |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 236 | if !strings.Contains(module.Rule("rustc").Args["libFlags"], |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 237 | "-L out/soong/.intermediates/libstatic_cc_dep/android_arm64_armv8-a_static/") { |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 238 | t.Errorf( |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 239 | "missing -L flag for libstatic_cc_dep of %s, rustcFlags: %#v", |
| 240 | module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"], |
Vinh Tran | 156ea44 | 2023-08-17 15:46:39 -0400 | [diff] [blame] | 241 | ) |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 246 | // Test that variants pull in the right type of rustlib autodep |
| 247 | func TestAutoDeps(t *testing.T) { |
| 248 | |
| 249 | ctx := testRust(t, ` |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 250 | rust_library_host { |
| 251 | name: "libbar", |
| 252 | srcs: ["bar.rs"], |
| 253 | crate_name: "bar", |
| 254 | } |
| 255 | rust_library_host_rlib { |
| 256 | name: "librlib_only", |
| 257 | srcs: ["bar.rs"], |
| 258 | crate_name: "rlib_only", |
| 259 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 260 | rust_library_host { |
| 261 | name: "libfoo", |
| 262 | srcs: ["foo.rs"], |
| 263 | crate_name: "foo", |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 264 | rustlibs: [ |
| 265 | "libbar", |
| 266 | "librlib_only", |
| 267 | ], |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 268 | } |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 269 | rust_ffi_host { |
| 270 | name: "libfoo.ffi", |
| 271 | srcs: ["foo.rs"], |
| 272 | crate_name: "foo", |
| 273 | rustlibs: [ |
| 274 | "libbar", |
| 275 | "librlib_only", |
| 276 | ], |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 277 | } |
| 278 | rust_ffi_host_static { |
| 279 | name: "libfoo.ffi.static", |
| 280 | srcs: ["foo.rs"], |
| 281 | crate_name: "foo", |
| 282 | rustlibs: [ |
| 283 | "libbar", |
| 284 | "librlib_only", |
| 285 | ], |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 286 | }`) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 287 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 288 | libfooRlib := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_rlib_rlib-std") |
| 289 | libfooDylib := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_dylib") |
| 290 | libfooFFIRlib := ctx.ModuleForTests(t, "libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std") |
| 291 | libfooShared := ctx.ModuleForTests(t, "libfoo.ffi", "linux_glibc_x86_64_shared") |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 292 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 293 | for _, static := range []android.TestingModule{libfooRlib, libfooFFIRlib} { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 294 | if !android.InList("libbar.rlib-std", static.Module().(*Module).Properties.AndroidMkRlibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 295 | t.Errorf("libbar not present as rlib dependency in static lib: %s", static.Module().Name()) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 296 | } |
| 297 | if android.InList("libbar", static.Module().(*Module).Properties.AndroidMkDylibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 298 | t.Errorf("libbar present as dynamic dependency in static lib: %s", static.Module().Name()) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | for _, dyn := range []android.TestingModule{libfooDylib, libfooShared} { |
| 303 | if !android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkDylibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 304 | t.Errorf("libbar not present as dynamic dependency in dynamic lib: %s", dyn.Module().Name()) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 305 | } |
Ivan Lozano | 4df0257 | 2023-06-15 14:21:09 -0400 | [diff] [blame] | 306 | if android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkRlibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 307 | t.Errorf("libbar present as rlib dependency in dynamic lib: %s", dyn.Module().Name()) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 308 | } |
Ivan Lozano | 4df0257 | 2023-06-15 14:21:09 -0400 | [diff] [blame] | 309 | if !android.InList("librlib_only", dyn.Module().(*Module).Properties.AndroidMkRlibs) { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 310 | t.Errorf("librlib_only should be selected by rustlibs as an rlib: %s.", dyn.Module().Name()) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 311 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 314 | |
| 315 | // Test that stripped versions are correctly generated and used. |
| 316 | func TestStrippedLibrary(t *testing.T) { |
| 317 | ctx := testRust(t, ` |
| 318 | rust_library_dylib { |
| 319 | name: "libfoo", |
| 320 | crate_name: "foo", |
| 321 | srcs: ["foo.rs"], |
| 322 | } |
| 323 | rust_library_dylib { |
| 324 | name: "libbar", |
| 325 | crate_name: "bar", |
| 326 | srcs: ["foo.rs"], |
| 327 | strip: { |
| 328 | none: true |
| 329 | } |
| 330 | } |
| 331 | `) |
| 332 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 333 | foo := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_dylib") |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 334 | foo.Output("libfoo.dylib.so") |
| 335 | foo.Output("unstripped/libfoo.dylib.so") |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 336 | // Check that the `cp` rule is using the stripped version as input. |
| 337 | cp := foo.Rule("android.Cp") |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 338 | if strings.HasSuffix(cp.Input.String(), "unstripped/libfoo.dylib.so") { |
| 339 | t.Errorf("installed library not based on stripped version: %v", cp.Input) |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 342 | fizzBar := ctx.ModuleForTests(t, "libbar", "android_arm64_armv8-a_dylib").MaybeOutput("unstripped/libbar.dylib.so") |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 343 | if fizzBar.Rule != nil { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 344 | t.Errorf("unstripped library exists, so stripped library has incorrectly been generated") |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 345 | } |
| 346 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 347 | |
| 348 | func TestLibstdLinkage(t *testing.T) { |
| 349 | ctx := testRust(t, ` |
| 350 | rust_library { |
| 351 | name: "libfoo", |
| 352 | srcs: ["foo.rs"], |
| 353 | crate_name: "foo", |
| 354 | } |
| 355 | rust_ffi { |
| 356 | name: "libbar", |
| 357 | srcs: ["foo.rs"], |
| 358 | crate_name: "bar", |
| 359 | rustlibs: ["libfoo"], |
Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 360 | } |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 361 | rust_ffi_static { |
| 362 | name: "libbar_static", |
| 363 | srcs: ["foo.rs"], |
| 364 | crate_name: "bar", |
| 365 | rustlibs: ["libfoo"], |
| 366 | } |
Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 367 | rust_ffi { |
| 368 | name: "libbar.prefer_rlib", |
| 369 | srcs: ["foo.rs"], |
| 370 | crate_name: "bar", |
| 371 | rustlibs: ["libfoo"], |
| 372 | prefer_rlib: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 373 | }`) |
| 374 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 375 | libfooDylib := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_dylib").Module().(*Module) |
| 376 | libfooRlibStatic := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module) |
| 377 | libfooRlibDynamic := ctx.ModuleForTests(t, "libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 378 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 379 | libbarShared := ctx.ModuleForTests(t, "libbar", "android_arm64_armv8-a_shared").Module().(*Module) |
| 380 | libbarFFIRlib := ctx.ModuleForTests(t, "libbar", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 381 | |
Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 382 | // prefer_rlib works the same for both rust_library and rust_ffi, so a single check is sufficient here. |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 383 | libbarRlibStd := ctx.ModuleForTests(t, "libbar.prefer_rlib", "android_arm64_armv8-a_shared").Module().(*Module) |
Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 384 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 385 | if !android.InList("libstd", libfooRlibStatic.Properties.AndroidMkRlibs) { |
| 386 | t.Errorf("rlib-std variant for device rust_library_rlib does not link libstd as an rlib") |
| 387 | } |
| 388 | if !android.InList("libstd", libfooRlibDynamic.Properties.AndroidMkDylibs) { |
| 389 | t.Errorf("dylib-std variant for device rust_library_rlib does not link libstd as an dylib") |
| 390 | } |
| 391 | if !android.InList("libstd", libfooDylib.Properties.AndroidMkDylibs) { |
| 392 | t.Errorf("Device rust_library_dylib does not link libstd as an dylib") |
| 393 | } |
| 394 | |
| 395 | if !android.InList("libstd", libbarShared.Properties.AndroidMkDylibs) { |
| 396 | t.Errorf("Device rust_ffi_shared does not link libstd as an dylib") |
| 397 | } |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 398 | if !android.InList("libstd", libbarFFIRlib.Properties.AndroidMkRlibs) { |
Ivan Lozano | 6184842 | 2024-12-13 19:45:00 +0000 | [diff] [blame] | 399 | t.Errorf("Device rust_ffi_static does not link libstd as an rlib") |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 400 | } |
| 401 | if !android.InList("libfoo.rlib-std", libbarFFIRlib.Properties.AndroidMkRlibs) { |
Ivan Lozano | 6184842 | 2024-12-13 19:45:00 +0000 | [diff] [blame] | 402 | t.Errorf("Device rust_ffi_static does not link dependent rustlib rlib-std variant") |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 403 | } |
Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 404 | if !android.InList("libstd", libbarRlibStd.Properties.AndroidMkRlibs) { |
| 405 | t.Errorf("rust_ffi with prefer_rlib does not link libstd as an rlib") |
| 406 | } |
| 407 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 408 | } |
Ivan Lozano | f033ca6 | 2024-03-21 13:43:14 -0400 | [diff] [blame] | 409 | |
| 410 | func TestRustFFIExportedIncludes(t *testing.T) { |
| 411 | ctx := testRust(t, ` |
| 412 | rust_ffi { |
| 413 | name: "libbar", |
| 414 | srcs: ["foo.rs"], |
| 415 | crate_name: "bar", |
| 416 | export_include_dirs: ["rust_includes"], |
| 417 | host_supported: true, |
| 418 | } |
| 419 | cc_library_static { |
| 420 | name: "libfoo", |
| 421 | srcs: ["foo.cpp"], |
| 422 | shared_libs: ["libbar"], |
| 423 | host_supported: true, |
| 424 | }`) |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 425 | libfooStatic := ctx.ModuleForTests(t, "libfoo", "linux_glibc_x86_64_static").Rule("cc") |
Ivan Lozano | f033ca6 | 2024-03-21 13:43:14 -0400 | [diff] [blame] | 426 | android.AssertStringDoesContain(t, "cFlags for lib module", libfooStatic.Args["cFlags"], " -Irust_includes ") |
| 427 | } |
Ivan Lozano | f458901 | 2024-11-20 22:18:11 +0000 | [diff] [blame] | 428 | |
| 429 | func TestRustVersionScript(t *testing.T) { |
| 430 | ctx := testRust(t, ` |
| 431 | rust_library { |
| 432 | name: "librs", |
| 433 | srcs: ["bar.rs"], |
| 434 | crate_name: "rs", |
| 435 | extra_exported_symbols: "librs.map.txt", |
| 436 | } |
| 437 | rust_ffi { |
| 438 | name: "libffi", |
| 439 | srcs: ["foo.rs"], |
| 440 | crate_name: "ffi", |
| 441 | version_script: "libffi.map.txt", |
| 442 | } |
| 443 | `) |
| 444 | |
| 445 | //linkFlags |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 446 | librs := ctx.ModuleForTests(t, "librs", "android_arm64_armv8-a_dylib").Rule("rustc") |
| 447 | libffi := ctx.ModuleForTests(t, "libffi", "android_arm64_armv8-a_shared").Rule("rustc") |
Ivan Lozano | f458901 | 2024-11-20 22:18:11 +0000 | [diff] [blame] | 448 | |
| 449 | if !strings.Contains(librs.Args["linkFlags"], "-Wl,--version-script=librs.map.txt") { |
| 450 | t.Errorf("missing expected -Wl,--version-script= linker flag for libextended shared lib, linkFlags: %#v", |
| 451 | librs.Args["linkFlags"]) |
| 452 | } |
| 453 | if strings.Contains(librs.Args["linkFlags"], "-Wl,--android-version-script=librs.map.txt") { |
| 454 | t.Errorf("unexpected -Wl,--android-version-script= linker flag for libextended shared lib, linkFlags: %#v", |
| 455 | librs.Args["linkFlags"]) |
| 456 | } |
| 457 | |
| 458 | if !strings.Contains(libffi.Args["linkFlags"], "-Wl,--android-version-script=libffi.map.txt") { |
| 459 | t.Errorf("missing -Wl,--android-version-script= linker flag for libreplaced shared lib, linkFlags: %#v", |
| 460 | libffi.Args["linkFlags"]) |
| 461 | } |
| 462 | if strings.Contains(libffi.Args["linkFlags"], "-Wl,--version-script=libffi.map.txt") { |
| 463 | t.Errorf("unexpected -Wl,--version-script= linker flag for libextended shared lib, linkFlags: %#v", |
| 464 | libffi.Args["linkFlags"]) |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | func TestRustVersionScriptPropertyErrors(t *testing.T) { |
| 469 | testRustError(t, "version_script: can only be set for rust_ffi modules", ` |
| 470 | rust_library { |
| 471 | name: "librs", |
| 472 | srcs: ["bar.rs"], |
| 473 | crate_name: "rs", |
| 474 | version_script: "libbar.map.txt", |
| 475 | }`) |
| 476 | testRustError(t, "version_script and extra_exported_symbols", ` |
| 477 | rust_ffi { |
| 478 | name: "librs", |
| 479 | srcs: ["bar.rs"], |
| 480 | crate_name: "rs", |
| 481 | version_script: "libbar.map.txt", |
| 482 | extra_exported_symbols: "libbar.map.txt", |
| 483 | }`) |
| 484 | } |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 485 | |
| 486 | func TestStubsVersions(t *testing.T) { |
| 487 | t.Parallel() |
| 488 | bp := ` |
| 489 | rust_ffi { |
| 490 | name: "libfoo", |
| 491 | crate_name: "foo", |
| 492 | srcs: ["foo.rs"], |
| 493 | stubs: { |
| 494 | versions: ["29", "R", "current"], |
| 495 | }, |
| 496 | } |
| 497 | ` |
| 498 | ctx := android.GroupFixturePreparers( |
| 499 | prepareForRustTest, |
| 500 | android.PrepareForTestWithVisibility, |
| 501 | rustMockedFiles.AddToFixture(), |
| 502 | android.FixtureModifyConfigAndContext(func(config android.Config, ctx *android.TestContext) { |
| 503 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 504 | })).RunTestWithBp(t, bp) |
| 505 | |
| 506 | variants := ctx.ModuleVariantsForTests("libfoo") |
| 507 | for _, expectedVer := range []string{"29", "R", "current"} { |
| 508 | expectedVariant := "android_arm_armv7-a-neon_shared_" + expectedVer |
| 509 | if !android.InList(expectedVariant, variants) { |
| 510 | t.Errorf("missing expected variant: %q", expectedVariant) |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | func TestStubsVersions_NotSorted(t *testing.T) { |
| 516 | t.Parallel() |
| 517 | bp := ` |
| 518 | rust_ffi_shared { |
| 519 | name: "libfoo", |
| 520 | crate_name: "foo", |
| 521 | srcs: ["foo.rs"], |
| 522 | stubs: { |
| 523 | versions: ["29", "current", "R"], |
| 524 | }, |
| 525 | } |
| 526 | ` |
| 527 | fixture := android.GroupFixturePreparers( |
| 528 | prepareForRustTest, |
| 529 | android.PrepareForTestWithVisibility, |
| 530 | rustMockedFiles.AddToFixture(), |
| 531 | |
| 532 | android.FixtureModifyConfigAndContext(func(config android.Config, ctx *android.TestContext) { |
| 533 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 534 | })) |
| 535 | |
| 536 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(`"libfoo" .*: versions: not sorted`)).RunTestWithBp(t, bp) |
| 537 | } |
| 538 | |
| 539 | func TestStubsVersions_ParseError(t *testing.T) { |
| 540 | t.Parallel() |
| 541 | bp := ` |
| 542 | rust_ffi_shared { |
| 543 | name: "libfoo", |
| 544 | crate_name: "foo", |
| 545 | srcs: ["foo.rs"], |
| 546 | stubs: { |
| 547 | versions: ["29", "current", "X"], |
| 548 | }, |
| 549 | } |
| 550 | ` |
| 551 | fixture := android.GroupFixturePreparers( |
| 552 | prepareForRustTest, |
| 553 | android.PrepareForTestWithVisibility, |
| 554 | rustMockedFiles.AddToFixture(), |
| 555 | |
| 556 | android.FixtureModifyConfigAndContext(func(config android.Config, ctx *android.TestContext) { |
| 557 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 558 | })) |
| 559 | |
| 560 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(`"libfoo" .*: versions: "X" could not be parsed as an integer and is not a recognized codename`)).RunTestWithBp(t, bp) |
| 561 | } |
| 562 | |
| 563 | func TestVersionedStubs(t *testing.T) { |
| 564 | t.Parallel() |
| 565 | bp := ` |
| 566 | rust_ffi_shared { |
| 567 | name: "libFoo", |
| 568 | crate_name: "Foo", |
| 569 | srcs: ["foo.rs"], |
| 570 | stubs: { |
| 571 | symbol_file: "foo.map.txt", |
| 572 | versions: ["1", "2", "3"], |
| 573 | }, |
| 574 | } |
| 575 | |
| 576 | cc_library_shared { |
| 577 | name: "libBar", |
| 578 | srcs: ["bar.c"], |
| 579 | shared_libs: ["libFoo#1"], |
| 580 | } |
| 581 | |
| 582 | rust_library { |
| 583 | name: "libbar_rs", |
| 584 | crate_name: "bar_rs", |
| 585 | srcs: ["bar.rs"], |
| 586 | shared_libs: ["libFoo#1"], |
| 587 | } |
| 588 | rust_ffi { |
| 589 | name: "libbar_ffi_rs", |
| 590 | crate_name: "bar_ffi_rs", |
| 591 | srcs: ["bar.rs"], |
| 592 | shared_libs: ["libFoo#1"], |
| 593 | } |
| 594 | ` |
| 595 | |
| 596 | ctx := android.GroupFixturePreparers( |
| 597 | prepareForRustTest, |
| 598 | android.PrepareForTestWithVisibility, |
| 599 | rustMockedFiles.AddToFixture()).RunTestWithBp(t, bp) |
| 600 | |
| 601 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 602 | expectedVariants := []string{ |
| 603 | "android_arm64_armv8-a_shared", |
| 604 | "android_arm64_armv8-a_shared_1", |
| 605 | "android_arm64_armv8-a_shared_2", |
| 606 | "android_arm64_armv8-a_shared_3", |
| 607 | "android_arm64_armv8-a_shared_current", |
| 608 | "android_arm_armv7-a-neon_shared", |
| 609 | "android_arm_armv7-a-neon_shared_1", |
| 610 | "android_arm_armv7-a-neon_shared_2", |
| 611 | "android_arm_armv7-a-neon_shared_3", |
| 612 | "android_arm_armv7-a-neon_shared_current", |
| 613 | } |
| 614 | variantsMismatch := false |
| 615 | if len(variants) != len(expectedVariants) { |
| 616 | variantsMismatch = true |
| 617 | } else { |
| 618 | for _, v := range expectedVariants { |
| 619 | if !android.InList(v, variants) { |
| 620 | variantsMismatch = false |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | if variantsMismatch { |
| 625 | t.Errorf("variants of libFoo expected:\n") |
| 626 | for _, v := range expectedVariants { |
| 627 | t.Errorf("%q\n", v) |
| 628 | } |
| 629 | t.Errorf(", but got:\n") |
| 630 | for _, v := range variants { |
| 631 | t.Errorf("%q\n", v) |
| 632 | } |
| 633 | } |
| 634 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 635 | libBarLinkRule := ctx.ModuleForTests(t, "libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 636 | libBarFlags := libBarLinkRule.Args["libFlags"] |
| 637 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 638 | libBarRsRustcRule := ctx.ModuleForTests(t, "libbar_rs", "android_arm64_armv8-a_dylib").Rule("rustc") |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 639 | libBarRsFlags := libBarRsRustcRule.Args["linkFlags"] |
| 640 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 641 | libBarFfiRsRustcRule := ctx.ModuleForTests(t, "libbar_ffi_rs", "android_arm64_armv8-a_shared").Rule("rustc") |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 642 | libBarFfiRsFlags := libBarFfiRsRustcRule.Args["linkFlags"] |
| 643 | |
| 644 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/unstripped/libFoo.so" |
| 645 | if !strings.Contains(libBarFlags, libFoo1StubPath) { |
| 646 | t.Errorf("%q is not found in %q", libFoo1StubPath, libBarFlags) |
| 647 | } |
| 648 | if !strings.Contains(libBarRsFlags, libFoo1StubPath) { |
| 649 | t.Errorf("%q is not found in %q", libFoo1StubPath, libBarRsFlags) |
| 650 | } |
| 651 | if !strings.Contains(libBarFfiRsFlags, libFoo1StubPath) { |
| 652 | t.Errorf("%q is not found in %q", libFoo1StubPath, libBarFfiRsFlags) |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | func TestCheckConflictingExplicitVersions(t *testing.T) { |
| 657 | t.Parallel() |
| 658 | bp := ` |
| 659 | cc_library_shared { |
| 660 | name: "libbar", |
| 661 | srcs: ["bar.c"], |
| 662 | shared_libs: ["libfoo", "libfoo#impl"], |
| 663 | } |
| 664 | |
| 665 | rust_ffi_shared { |
| 666 | name: "libfoo", |
| 667 | crate_name: "foo", |
| 668 | srcs: ["foo.rs"], |
| 669 | stubs: { |
| 670 | versions: ["29", "current"], |
| 671 | }, |
| 672 | } |
| 673 | ` |
| 674 | fixture := android.GroupFixturePreparers( |
| 675 | prepareForRustTest, |
| 676 | android.PrepareForTestWithVisibility, |
| 677 | rustMockedFiles.AddToFixture()) |
| 678 | |
| 679 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(`duplicate shared libraries with different explicit versions`)).RunTestWithBp(t, bp) |
| 680 | } |
| 681 | |
| 682 | func TestAddnoOverride64GlobalCflags(t *testing.T) { |
| 683 | t.Parallel() |
| 684 | bp := ` |
| 685 | cc_library_shared { |
| 686 | name: "libclient", |
| 687 | srcs: ["foo.c"], |
| 688 | shared_libs: ["libfoo#1"], |
| 689 | } |
| 690 | |
| 691 | rust_ffi_shared { |
| 692 | name: "libfoo", |
| 693 | crate_name: "foo", |
| 694 | srcs: ["foo.c"], |
| 695 | shared_libs: ["libbar"], |
| 696 | stubs: { |
| 697 | symbol_file: "foo.map.txt", |
| 698 | versions: ["1", "2", "3"], |
| 699 | }, |
| 700 | } |
| 701 | |
| 702 | cc_library_shared { |
| 703 | name: "libbar", |
| 704 | export_include_dirs: ["include/libbar"], |
| 705 | srcs: ["foo.c"], |
| 706 | }` |
| 707 | ctx := android.GroupFixturePreparers( |
| 708 | prepareForRustTest, |
| 709 | android.PrepareForTestWithVisibility, |
| 710 | rustMockedFiles.AddToFixture()).RunTestWithBp(t, bp) |
| 711 | |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame^] | 712 | cFlags := ctx.ModuleForTests(t, "libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 713 | |
| 714 | if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") { |
| 715 | t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags) |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | // Make sure the stubs properties can only be used in modules producing shared libs |
| 720 | func TestRustStubsFFIOnly(t *testing.T) { |
| 721 | testRustError(t, "stubs properties", ` |
| 722 | rust_library { |
| 723 | name: "libfoo", |
| 724 | crate_name: "foo", |
| 725 | srcs: ["foo.c"], |
| 726 | shared_libs: ["libbar"], |
| 727 | stubs: { |
| 728 | symbol_file: "foo.map.txt", |
| 729 | }, |
| 730 | } |
| 731 | `) |
| 732 | |
| 733 | testRustError(t, "stubs properties", ` |
| 734 | rust_library { |
| 735 | name: "libfoo", |
| 736 | crate_name: "foo", |
| 737 | srcs: ["foo.c"], |
| 738 | shared_libs: ["libbar"], |
| 739 | stubs: { |
| 740 | versions: ["1"], |
| 741 | }, |
| 742 | } |
| 743 | `) |
| 744 | |
| 745 | testRustError(t, "stubs properties", ` |
| 746 | rust_ffi_static { |
| 747 | name: "libfoo", |
| 748 | crate_name: "foo", |
| 749 | srcs: ["foo.c"], |
| 750 | shared_libs: ["libbar"], |
| 751 | stubs: { |
| 752 | symbol_file: "foo.map.txt", |
| 753 | }, |
| 754 | } |
| 755 | `) |
| 756 | testRustError(t, "stubs properties", ` |
| 757 | rust_ffi_static { |
| 758 | name: "libfoo", |
| 759 | crate_name: "foo", |
| 760 | srcs: ["foo.c"], |
| 761 | shared_libs: ["libbar"], |
| 762 | stubs: { |
| 763 | versions: ["1"], |
| 764 | }, |
| 765 | } |
| 766 | `) |
| 767 | } |
| 768 | |
| 769 | // TODO: When rust_ffi libraries support export_*_lib_headers, |
| 770 | // add a test similar to cc.TestStubsLibReexportsHeaders |