blob: 80f693eb683b4c142c141ebdb6169312e0e5bd96 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
Ivan Lozanoffee3342019-08-27 12:03:00 -070018 "os"
Ivan Lozanoc0083612019-09-03 13:49:39 -070019 "runtime"
Ivan Lozanob9040d62019-09-24 13:23:50 -070020 "strings"
Ivan Lozanoffee3342019-08-27 12:03:00 -070021 "testing"
22
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040023 "github.com/google/blueprint/proptools"
24
Ivan Lozanoffee3342019-08-27 12:03:00 -070025 "android/soong/android"
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000026 "android/soong/genrule"
Ivan Lozanoffee3342019-08-27 12:03:00 -070027)
28
Ivan Lozanoffee3342019-08-27 12:03:00 -070029func TestMain(m *testing.M) {
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000030 os.Exit(m.Run())
31}
Ivan Lozanoffee3342019-08-27 12:03:00 -070032
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000033var prepareForRustTest = android.GroupFixturePreparers(
34 android.PrepareForTestWithArchMutator,
35 android.PrepareForTestWithDefaults,
36 android.PrepareForTestWithPrebuilts,
Ivan Lozanoffee3342019-08-27 12:03:00 -070037
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000038 genrule.PrepareForTestWithGenRuleBuildComponents,
39
Ivan Lozano1921e802021-05-20 13:39:16 -040040 PrepareForTestWithRustIncludeVndk,
41 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
42 variables.DeviceVndkVersion = StringPtr("current")
43 variables.ProductVndkVersion = StringPtr("current")
44 variables.Platform_vndk_version = StringPtr("29")
45 }),
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000046)
47
48var rustMockedFiles = android.MockFS{
Ivan Lozano1921e802021-05-20 13:39:16 -040049 "foo.rs": nil,
50 "foo.c": nil,
51 "src/bar.rs": nil,
52 "src/any.h": nil,
53 "c_includes/c_header.h": nil,
54 "rust_includes/rust_headers.h": nil,
55 "proto.proto": nil,
56 "proto/buf.proto": nil,
57 "buf.proto": nil,
58 "foo.proto": nil,
59 "liby.so": nil,
60 "libz.so": nil,
61 "data.txt": nil,
Ivan Lozano3149e6e2021-06-01 15:09:53 -040062 "liblog.map.txt": nil,
Ivan Lozanoffee3342019-08-27 12:03:00 -070063}
64
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +020065// testRust returns a TestContext in which a basic environment has been setup.
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000066// This environment contains a few mocked files. See rustMockedFiles for the list of these files.
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +020067func testRust(t *testing.T, bp string) *android.TestContext {
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000068 skipTestIfOsNotSupported(t)
69 result := android.GroupFixturePreparers(
70 prepareForRustTest,
71 rustMockedFiles.AddToFixture(),
72 ).
73 RunTestWithBp(t, bp)
74 return result.TestContext
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +020075}
Colin Cross98be1bb2019-12-13 20:41:13 -080076
Ivan Lozanof76cdf72021-02-12 09:55:06 -050077func testRustVndk(t *testing.T, bp string) *android.TestContext {
Ivan Lozano1921e802021-05-20 13:39:16 -040078 return testRustVndkFs(t, bp, rustMockedFiles)
79}
80
Ivan Lozano3149e6e2021-06-01 15:09:53 -040081const (
82 sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
83 rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
84)
Ivan Lozano1921e802021-05-20 13:39:16 -040085
86func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext {
Ivan Lozano3149e6e2021-06-01 15:09:53 -040087 return testRustVndkFsVersions(t, bp, fs, "current", "current", "29")
88}
89
90func testRustVndkFsVersions(t *testing.T, bp string, fs android.MockFS, device_version, product_version, vndk_version string) *android.TestContext {
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000091 skipTestIfOsNotSupported(t)
92 result := android.GroupFixturePreparers(
93 prepareForRustTest,
Ivan Lozano1921e802021-05-20 13:39:16 -040094 fs.AddToFixture(),
Paul Duffin2c4ca8d2021-03-07 19:18:38 +000095 android.FixtureModifyProductVariables(
96 func(variables android.FixtureProductVariables) {
Ivan Lozano3149e6e2021-06-01 15:09:53 -040097 variables.DeviceVndkVersion = StringPtr(device_version)
98 variables.ProductVndkVersion = StringPtr(product_version)
99 variables.Platform_vndk_version = StringPtr(vndk_version)
Paul Duffin2c4ca8d2021-03-07 19:18:38 +0000100 },
101 ),
102 ).RunTestWithBp(t, bp)
103 return result.TestContext
Ivan Lozano1921e802021-05-20 13:39:16 -0400104
Ivan Lozanof76cdf72021-02-12 09:55:06 -0500105}
106
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +0200107// testRustCov returns a TestContext in which a basic environment has been
108// setup. This environment explicitly enables coverage.
109func testRustCov(t *testing.T, bp string) *android.TestContext {
Paul Duffin2c4ca8d2021-03-07 19:18:38 +0000110 skipTestIfOsNotSupported(t)
111 result := android.GroupFixturePreparers(
112 prepareForRustTest,
113 rustMockedFiles.AddToFixture(),
114 android.FixtureModifyProductVariables(
115 func(variables android.FixtureProductVariables) {
116 variables.ClangCoverage = proptools.BoolPtr(true)
117 variables.Native_coverage = proptools.BoolPtr(true)
118 variables.NativeCoveragePaths = []string{"*"}
119 },
120 ),
121 ).RunTestWithBp(t, bp)
122 return result.TestContext
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +0200123}
124
125// testRustError ensures that at least one error was raised and its value
126// matches the pattern provided. The error can be either in the parsing of the
127// Blueprint or when generating the build actions.
128func testRustError(t *testing.T, pattern string, bp string) {
Paul Duffin2c4ca8d2021-03-07 19:18:38 +0000129 skipTestIfOsNotSupported(t)
130 android.GroupFixturePreparers(
131 prepareForRustTest,
132 rustMockedFiles.AddToFixture(),
133 ).
134 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
135 RunTestWithBp(t, bp)
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +0200136}
137
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400138// testRustVndkError is similar to testRustError, but can be used to test VNDK-related errors.
139func testRustVndkError(t *testing.T, pattern string, bp string) {
Ivan Lozano1921e802021-05-20 13:39:16 -0400140 testRustVndkFsError(t, pattern, bp, rustMockedFiles)
141}
142
143func testRustVndkFsError(t *testing.T, pattern string, bp string, fs android.MockFS) {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400144 skipTestIfOsNotSupported(t)
145 android.GroupFixturePreparers(
146 prepareForRustTest,
Ivan Lozano1921e802021-05-20 13:39:16 -0400147 fs.AddToFixture(),
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400148 android.FixtureModifyProductVariables(
149 func(variables android.FixtureProductVariables) {
150 variables.DeviceVndkVersion = StringPtr("current")
151 variables.ProductVndkVersion = StringPtr("current")
152 variables.Platform_vndk_version = StringPtr("VER")
153 },
154 ),
155 ).
156 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
157 RunTestWithBp(t, bp)
158}
159
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +0200160// testRustCtx is used to build a particular test environment. Unless your
161// tests requires a specific setup, prefer the wrapping functions: testRust,
162// testRustCov or testRustError.
163type testRustCtx struct {
164 bp string
165 fs map[string][]byte
166 env map[string]string
167 config *android.Config
168}
169
Paul Duffin2c4ca8d2021-03-07 19:18:38 +0000170func skipTestIfOsNotSupported(t *testing.T) {
Thiébaud Weksteen0a75e522020-10-07 14:30:03 +0200171 // TODO (b/140435149)
172 if runtime.GOOS != "linux" {
173 t.Skip("Rust Soong tests can only be run on Linux hosts currently")
174 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700175}
176
Ivan Lozanoffee3342019-08-27 12:03:00 -0700177// Test that we can extract the link path from a lib path.
178func TestLinkPathFromFilePath(t *testing.T) {
179 barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so")
180 libName := linkPathFromFilePath(barPath)
181 expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/"
182
183 if libName != expectedResult {
184 t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName)
185 }
186}
187
Ivan Lozanoffee3342019-08-27 12:03:00 -0700188// Test to make sure dependencies are being picked up correctly.
189func TestDepsTracking(t *testing.T) {
190 ctx := testRust(t, `
Matthew Maurer2ae05132020-06-23 14:28:53 -0700191 rust_ffi_host_static {
Ivan Lozano52767be2019-10-18 14:49:46 -0700192 name: "libstatic",
193 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700194 crate_name: "static",
Ivan Lozano52767be2019-10-18 14:49:46 -0700195 }
Ivan Lozano63bb7682021-03-23 15:53:44 -0400196 rust_ffi_host_static {
197 name: "libwholestatic",
198 srcs: ["foo.rs"],
199 crate_name: "wholestatic",
200 }
Matthew Maurer2ae05132020-06-23 14:28:53 -0700201 rust_ffi_host_shared {
Ivan Lozano52767be2019-10-18 14:49:46 -0700202 name: "libshared",
203 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700204 crate_name: "shared",
Ivan Lozano52767be2019-10-18 14:49:46 -0700205 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700206 rust_library_host_dylib {
Ivan Lozano52767be2019-10-18 14:49:46 -0700207 name: "libdylib",
Ivan Lozanoffee3342019-08-27 12:03:00 -0700208 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700209 crate_name: "dylib",
Ivan Lozanoffee3342019-08-27 12:03:00 -0700210 }
211 rust_library_host_rlib {
Ivan Lozano52767be2019-10-18 14:49:46 -0700212 name: "librlib",
Ivan Lozano43845682020-07-09 21:03:28 -0400213 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700214 crate_name: "rlib",
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500215 static_libs: ["libstatic"],
Ivan Lozano63bb7682021-03-23 15:53:44 -0400216 whole_static_libs: ["libwholestatic"],
Ivan Lozanoffee3342019-08-27 12:03:00 -0700217 }
218 rust_proc_macro {
219 name: "libpm",
220 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700221 crate_name: "pm",
Ivan Lozanoffee3342019-08-27 12:03:00 -0700222 }
223 rust_binary_host {
Ivan Lozano43845682020-07-09 21:03:28 -0400224 name: "fizz-buzz",
Ivan Lozano52767be2019-10-18 14:49:46 -0700225 dylibs: ["libdylib"],
226 rlibs: ["librlib"],
Ivan Lozanoffee3342019-08-27 12:03:00 -0700227 proc_macros: ["libpm"],
Ivan Lozano52767be2019-10-18 14:49:46 -0700228 static_libs: ["libstatic"],
229 shared_libs: ["libshared"],
Ivan Lozano43845682020-07-09 21:03:28 -0400230 srcs: ["foo.rs"],
Ivan Lozanoffee3342019-08-27 12:03:00 -0700231 }
232 `)
Ivan Lozano43845682020-07-09 21:03:28 -0400233 module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500234 rustc := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
Ivan Lozanoffee3342019-08-27 12:03:00 -0700235
236 // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
Ivan Lozano52767be2019-10-18 14:49:46 -0700237 if !android.InList("libdylib", module.Properties.AndroidMkDylibs) {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700238 t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)")
239 }
240
Ivan Lozano2b081132020-09-08 12:46:52 -0400241 if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700242 t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)")
243 }
244
245 if !android.InList("libpm", module.Properties.AndroidMkProcMacroLibs) {
246 t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)")
247 }
248
Ivan Lozano52767be2019-10-18 14:49:46 -0700249 if !android.InList("libshared", module.Properties.AndroidMkSharedLibs) {
250 t.Errorf("Shared library dependency not detected (dependency missing from AndroidMkSharedLibs)")
251 }
252
253 if !android.InList("libstatic", module.Properties.AndroidMkStaticLibs) {
254 t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)")
255 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500256
Ivan Lozano63bb7682021-03-23 15:53:44 -0400257 if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=wholestatic") {
258 t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.Args["rustcFlags"])
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500259 }
260
Ivan Lozanoffee3342019-08-27 12:03:00 -0700261}
Ivan Lozanob9040d62019-09-24 13:23:50 -0700262
Ivan Lozano43845682020-07-09 21:03:28 -0400263func TestSourceProviderDeps(t *testing.T) {
264 ctx := testRust(t, `
265 rust_binary {
266 name: "fizz-buzz-dep",
267 srcs: [
268 "foo.rs",
269 ":my_generator",
270 ":libbindings",
271 ],
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400272 rlibs: ["libbindings"],
Ivan Lozano43845682020-07-09 21:03:28 -0400273 }
274 rust_proc_macro {
275 name: "libprocmacro",
276 srcs: [
277 "foo.rs",
278 ":my_generator",
279 ":libbindings",
280 ],
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400281 rlibs: ["libbindings"],
Ivan Lozano43845682020-07-09 21:03:28 -0400282 crate_name: "procmacro",
283 }
284 rust_library {
285 name: "libfoo",
286 srcs: [
287 "foo.rs",
288 ":my_generator",
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400289 ":libbindings",
290 ],
291 rlibs: ["libbindings"],
Ivan Lozano43845682020-07-09 21:03:28 -0400292 crate_name: "foo",
293 }
294 genrule {
295 name: "my_generator",
296 tools: ["any_rust_binary"],
297 cmd: "$(location) -o $(out) $(in)",
298 srcs: ["src/any.h"],
299 out: ["src/any.rs"],
300 }
Colin Crosse9fe2942020-11-10 18:12:15 -0800301 rust_binary_host {
302 name: "any_rust_binary",
303 srcs: [
304 "foo.rs",
305 ],
306 }
Ivan Lozano43845682020-07-09 21:03:28 -0400307 rust_bindgen {
308 name: "libbindings",
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400309 crate_name: "bindings",
310 source_stem: "bindings",
Ivan Lozano43845682020-07-09 21:03:28 -0400311 host_supported: true,
312 wrapper_src: "src/any.h",
313 }
314 `)
315
Ivan Lozano2b081132020-09-08 12:46:52 -0400316 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Rule("rustc")
Ivan Lozano43845682020-07-09 21:03:28 -0400317 if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") {
318 t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
319 }
320 if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") {
321 t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
322 }
323
324 fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc")
325 if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") {
326 t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
327 }
328 if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") {
329 t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
330 }
331
332 libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc")
333 if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") {
334 t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
335 }
336 if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") {
337 t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
338 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400339
340 // Check that our bindings are picked up as crate dependencies as well
341 libfooMod := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module)
Ivan Lozano2b081132020-09-08 12:46:52 -0400342 if !android.InList("libbindings.dylib-std", libfooMod.Properties.AndroidMkRlibs) {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400343 t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
344 }
345 fizzBuzzMod := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Module().(*Module)
Ivan Lozano2b081132020-09-08 12:46:52 -0400346 if !android.InList("libbindings.dylib-std", fizzBuzzMod.Properties.AndroidMkRlibs) {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400347 t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
348 }
349 libprocmacroMod := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Module().(*Module)
Ivan Lozano2b081132020-09-08 12:46:52 -0400350 if !android.InList("libbindings.rlib-std", libprocmacroMod.Properties.AndroidMkRlibs) {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400351 t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
352 }
353
Ivan Lozano43845682020-07-09 21:03:28 -0400354}
355
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400356func TestSourceProviderTargetMismatch(t *testing.T) {
357 // This might error while building the dependency tree or when calling depsToPaths() depending on the lunched
358 // target, which results in two different errors. So don't check the error, just confirm there is one.
359 testRustError(t, ".*", `
360 rust_proc_macro {
361 name: "libprocmacro",
362 srcs: [
363 "foo.rs",
364 ":libbindings",
365 ],
366 crate_name: "procmacro",
367 }
368 rust_bindgen {
369 name: "libbindings",
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400370 crate_name: "bindings",
371 source_stem: "bindings",
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400372 wrapper_src: "src/any.h",
373 }
374 `)
375}
376
Ivan Lozanob9040d62019-09-24 13:23:50 -0700377// Test to make sure proc_macros use host variants when building device modules.
378func TestProcMacroDeviceDeps(t *testing.T) {
379 ctx := testRust(t, `
380 rust_library_host_rlib {
381 name: "libbar",
382 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700383 crate_name: "bar",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700384 }
385 rust_proc_macro {
386 name: "libpm",
387 rlibs: ["libbar"],
388 srcs: ["foo.rs"],
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700389 crate_name: "pm",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700390 }
391 rust_binary {
392 name: "fizz-buzz",
393 proc_macros: ["libpm"],
394 srcs: ["foo.rs"],
395 }
396 `)
397 rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc")
398
399 if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") {
400 t.Errorf("Proc_macro is not using host variant of dependent modules.")
401 }
402}
Matthew Maurer99020b02019-10-31 10:44:40 -0700403
404// Test that no_stdlibs suppresses dependencies on rust standard libraries
405func TestNoStdlibs(t *testing.T) {
406 ctx := testRust(t, `
407 rust_binary {
408 name: "fizz-buzz",
409 srcs: ["foo.rs"],
Ivan Lozano9d1df102020-04-28 10:10:23 -0400410 no_stdlibs: true,
Matthew Maurer99020b02019-10-31 10:44:40 -0700411 }`)
Colin Cross7113d202019-11-20 16:39:12 -0800412 module := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module)
Matthew Maurer99020b02019-10-31 10:44:40 -0700413
414 if android.InList("libstd", module.Properties.AndroidMkDylibs) {
415 t.Errorf("no_stdlibs did not suppress dependency on libstd")
416 }
417}
Ivan Lozano9d1df102020-04-28 10:10:23 -0400418
419// Test that libraries provide both 32-bit and 64-bit variants.
420func TestMultilib(t *testing.T) {
421 ctx := testRust(t, `
422 rust_library_rlib {
423 name: "libfoo",
424 srcs: ["foo.rs"],
425 crate_name: "foo",
426 }`)
427
Ivan Lozano2b081132020-09-08 12:46:52 -0400428 _ = ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std")
429 _ = ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_rlib_dylib-std")
Ivan Lozano9d1df102020-04-28 10:10:23 -0400430}
Thiébaud Weksteene4dd14b2021-04-14 11:18:47 +0200431
432// Test that library size measurements are generated.
433func TestLibrarySizes(t *testing.T) {
434 ctx := testRust(t, `
435 rust_library_dylib {
436 name: "libwaldo",
437 srcs: ["foo.rs"],
438 crate_name: "waldo",
439 }`)
440
441 m := ctx.SingletonForTests("file_metrics")
442 m.Output("libwaldo.dylib.so.bloaty.csv")
443 m.Output("stripped/libwaldo.dylib.so.bloaty.csv")
444}