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 | "io/ioutil" |
| 19 | "os" |
Ivan Lozano | c008361 | 2019-09-03 13:49:39 -0700 | [diff] [blame] | 20 | "runtime" |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 21 | "strings" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 22 | "testing" |
| 23 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 26 | "android/soong/android" |
Colin Cross | f28329d | 2020-02-15 11:00:10 -0800 | [diff] [blame] | 27 | "android/soong/cc" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | var ( |
| 31 | buildDir string |
| 32 | ) |
| 33 | |
| 34 | func setUp() { |
| 35 | var err error |
| 36 | buildDir, err = ioutil.TempDir("", "soong_rust_test") |
| 37 | if err != nil { |
| 38 | panic(err) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func tearDown() { |
| 43 | os.RemoveAll(buildDir) |
| 44 | } |
| 45 | |
| 46 | func TestMain(m *testing.M) { |
| 47 | run := func() int { |
| 48 | setUp() |
| 49 | defer tearDown() |
| 50 | |
| 51 | return m.Run() |
| 52 | } |
| 53 | |
| 54 | os.Exit(run()) |
| 55 | } |
| 56 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 57 | func testConfig(bp string) android.Config { |
| 58 | bp = bp + GatherRequiredDepsForTest() |
| 59 | |
| 60 | fs := map[string][]byte{ |
| 61 | "foo.rs": nil, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 62 | "foo.c": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 63 | "src/bar.rs": nil, |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 64 | "src/any.h": nil, |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame^] | 65 | "buf.proto": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 66 | "liby.so": nil, |
| 67 | "libz.so": nil, |
| 68 | } |
| 69 | |
Colin Cross | f28329d | 2020-02-15 11:00:10 -0800 | [diff] [blame] | 70 | cc.GatherRequiredFilesForTest(fs) |
| 71 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 72 | return android.TestArchConfig(buildDir, nil, bp, fs) |
| 73 | } |
| 74 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 75 | func testRust(t *testing.T, bp string) *android.TestContext { |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 76 | return testRustContext(t, bp, false) |
| 77 | } |
| 78 | |
| 79 | func testRustCov(t *testing.T, bp string) *android.TestContext { |
| 80 | return testRustContext(t, bp, true) |
| 81 | } |
| 82 | |
| 83 | func testRustContext(t *testing.T, bp string, coverage bool) *android.TestContext { |
Ivan Lozano | c008361 | 2019-09-03 13:49:39 -0700 | [diff] [blame] | 84 | // TODO (b/140435149) |
| 85 | if runtime.GOOS != "linux" { |
| 86 | t.Skip("Only the Linux toolchain is supported for Rust") |
| 87 | } |
| 88 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 89 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 90 | config := testConfig(bp) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 91 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 92 | if coverage { |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 93 | config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 94 | config.TestProductVariables.Native_coverage = proptools.BoolPtr(true) |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 95 | config.TestProductVariables.NativeCoveragePaths = []string{"*"} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 98 | ctx := CreateTestContext() |
| 99 | ctx.Register(config) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 100 | |
| 101 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 102 | android.FailIfErrored(t, errs) |
| 103 | _, errs = ctx.PrepareBuildActions(config) |
| 104 | android.FailIfErrored(t, errs) |
| 105 | |
| 106 | return ctx |
| 107 | } |
| 108 | |
| 109 | func testRustError(t *testing.T, pattern string, bp string) { |
Ivan Lozano | c008361 | 2019-09-03 13:49:39 -0700 | [diff] [blame] | 110 | // TODO (b/140435149) |
| 111 | if runtime.GOOS != "linux" { |
| 112 | t.Skip("Only the Linux toolchain is supported for Rust") |
| 113 | } |
| 114 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 115 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 116 | config := testConfig(bp) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 117 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 118 | ctx := CreateTestContext() |
| 119 | ctx.Register(config) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 120 | |
| 121 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 122 | if len(errs) > 0 { |
| 123 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | _, errs = ctx.PrepareBuildActions(config) |
| 128 | if len(errs) > 0 { |
| 129 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 134 | } |
| 135 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 136 | // Test that we can extract the link path from a lib path. |
| 137 | func TestLinkPathFromFilePath(t *testing.T) { |
| 138 | barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so") |
| 139 | libName := linkPathFromFilePath(barPath) |
| 140 | expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/" |
| 141 | |
| 142 | if libName != expectedResult { |
| 143 | t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName) |
| 144 | } |
| 145 | } |
| 146 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 147 | // Test to make sure dependencies are being picked up correctly. |
| 148 | func TestDepsTracking(t *testing.T) { |
| 149 | ctx := testRust(t, ` |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 150 | rust_ffi_host_static { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 151 | name: "libstatic", |
| 152 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 153 | crate_name: "static", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 154 | } |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 155 | rust_ffi_host_shared { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 156 | name: "libshared", |
| 157 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 158 | crate_name: "shared", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 159 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 160 | rust_library_host_dylib { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 161 | name: "libdylib", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 162 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 163 | crate_name: "dylib", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 164 | } |
| 165 | rust_library_host_rlib { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 166 | name: "librlib", |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 167 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 168 | crate_name: "rlib", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 169 | } |
| 170 | rust_proc_macro { |
| 171 | name: "libpm", |
| 172 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 173 | crate_name: "pm", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 174 | } |
| 175 | rust_binary_host { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 176 | name: "fizz-buzz", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 177 | dylibs: ["libdylib"], |
| 178 | rlibs: ["librlib"], |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 179 | proc_macros: ["libpm"], |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 180 | static_libs: ["libstatic"], |
| 181 | shared_libs: ["libshared"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 182 | srcs: ["foo.rs"], |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 183 | } |
| 184 | `) |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 185 | module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 186 | |
| 187 | // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 188 | if !android.InList("libdylib", module.Properties.AndroidMkDylibs) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 189 | t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)") |
| 190 | } |
| 191 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 192 | if !android.InList("librlib", module.Properties.AndroidMkRlibs) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 193 | t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)") |
| 194 | } |
| 195 | |
| 196 | if !android.InList("libpm", module.Properties.AndroidMkProcMacroLibs) { |
| 197 | t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)") |
| 198 | } |
| 199 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 200 | if !android.InList("libshared", module.Properties.AndroidMkSharedLibs) { |
| 201 | t.Errorf("Shared library dependency not detected (dependency missing from AndroidMkSharedLibs)") |
| 202 | } |
| 203 | |
| 204 | if !android.InList("libstatic", module.Properties.AndroidMkStaticLibs) { |
| 205 | t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)") |
| 206 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 207 | } |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 208 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 209 | func TestSourceProviderDeps(t *testing.T) { |
| 210 | ctx := testRust(t, ` |
| 211 | rust_binary { |
| 212 | name: "fizz-buzz-dep", |
| 213 | srcs: [ |
| 214 | "foo.rs", |
| 215 | ":my_generator", |
| 216 | ":libbindings", |
| 217 | ], |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 218 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 219 | } |
| 220 | rust_proc_macro { |
| 221 | name: "libprocmacro", |
| 222 | srcs: [ |
| 223 | "foo.rs", |
| 224 | ":my_generator", |
| 225 | ":libbindings", |
| 226 | ], |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 227 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 228 | crate_name: "procmacro", |
| 229 | } |
| 230 | rust_library { |
| 231 | name: "libfoo", |
| 232 | srcs: [ |
| 233 | "foo.rs", |
| 234 | ":my_generator", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 235 | ":libbindings", |
| 236 | ], |
| 237 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 238 | crate_name: "foo", |
| 239 | } |
| 240 | genrule { |
| 241 | name: "my_generator", |
| 242 | tools: ["any_rust_binary"], |
| 243 | cmd: "$(location) -o $(out) $(in)", |
| 244 | srcs: ["src/any.h"], |
| 245 | out: ["src/any.rs"], |
| 246 | } |
| 247 | rust_bindgen { |
| 248 | name: "libbindings", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 249 | crate_name: "bindings", |
| 250 | source_stem: "bindings", |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 251 | host_supported: true, |
| 252 | wrapper_src: "src/any.h", |
| 253 | } |
| 254 | `) |
| 255 | |
| 256 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib").Rule("rustc") |
| 257 | if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") { |
| 258 | t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) |
| 259 | } |
| 260 | if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") { |
| 261 | t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) |
| 262 | } |
| 263 | |
| 264 | fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc") |
| 265 | if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") { |
| 266 | t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) |
| 267 | } |
| 268 | if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") { |
| 269 | t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) |
| 270 | } |
| 271 | |
| 272 | libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc") |
| 273 | if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") { |
| 274 | t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) |
| 275 | } |
| 276 | if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") { |
| 277 | t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) |
| 278 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 279 | |
| 280 | // Check that our bindings are picked up as crate dependencies as well |
| 281 | libfooMod := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module) |
| 282 | if !android.InList("libbindings", libfooMod.Properties.AndroidMkRlibs) { |
| 283 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 284 | } |
| 285 | fizzBuzzMod := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Module().(*Module) |
| 286 | if !android.InList("libbindings", fizzBuzzMod.Properties.AndroidMkRlibs) { |
| 287 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 288 | } |
| 289 | libprocmacroMod := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Module().(*Module) |
| 290 | if !android.InList("libbindings", libprocmacroMod.Properties.AndroidMkRlibs) { |
| 291 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 292 | } |
| 293 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 296 | func TestSourceProviderTargetMismatch(t *testing.T) { |
| 297 | // This might error while building the dependency tree or when calling depsToPaths() depending on the lunched |
| 298 | // target, which results in two different errors. So don't check the error, just confirm there is one. |
| 299 | testRustError(t, ".*", ` |
| 300 | rust_proc_macro { |
| 301 | name: "libprocmacro", |
| 302 | srcs: [ |
| 303 | "foo.rs", |
| 304 | ":libbindings", |
| 305 | ], |
| 306 | crate_name: "procmacro", |
| 307 | } |
| 308 | rust_bindgen { |
| 309 | name: "libbindings", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 310 | crate_name: "bindings", |
| 311 | source_stem: "bindings", |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 312 | wrapper_src: "src/any.h", |
| 313 | } |
| 314 | `) |
| 315 | } |
| 316 | |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 317 | // Test to make sure proc_macros use host variants when building device modules. |
| 318 | func TestProcMacroDeviceDeps(t *testing.T) { |
| 319 | ctx := testRust(t, ` |
| 320 | rust_library_host_rlib { |
| 321 | name: "libbar", |
| 322 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 323 | crate_name: "bar", |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 324 | } |
| 325 | rust_proc_macro { |
| 326 | name: "libpm", |
| 327 | rlibs: ["libbar"], |
| 328 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 329 | crate_name: "pm", |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 330 | } |
| 331 | rust_binary { |
| 332 | name: "fizz-buzz", |
| 333 | proc_macros: ["libpm"], |
| 334 | srcs: ["foo.rs"], |
| 335 | } |
| 336 | `) |
| 337 | rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc") |
| 338 | |
| 339 | if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") { |
| 340 | t.Errorf("Proc_macro is not using host variant of dependent modules.") |
| 341 | } |
| 342 | } |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 343 | |
| 344 | // Test that no_stdlibs suppresses dependencies on rust standard libraries |
| 345 | func TestNoStdlibs(t *testing.T) { |
| 346 | ctx := testRust(t, ` |
| 347 | rust_binary { |
| 348 | name: "fizz-buzz", |
| 349 | srcs: ["foo.rs"], |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 350 | no_stdlibs: true, |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 351 | }`) |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 352 | module := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module) |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 353 | |
| 354 | if android.InList("libstd", module.Properties.AndroidMkDylibs) { |
| 355 | t.Errorf("no_stdlibs did not suppress dependency on libstd") |
| 356 | } |
| 357 | } |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 358 | |
| 359 | // Test that libraries provide both 32-bit and 64-bit variants. |
| 360 | func TestMultilib(t *testing.T) { |
| 361 | ctx := testRust(t, ` |
| 362 | rust_library_rlib { |
| 363 | name: "libfoo", |
| 364 | srcs: ["foo.rs"], |
| 365 | crate_name: "foo", |
| 366 | }`) |
| 367 | |
| 368 | _ = ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib") |
| 369 | _ = ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_rlib") |
| 370 | } |