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 ( |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 18 | "os" |
Ivan Lozano | c008361 | 2019-09-03 13:49:39 -0700 | [diff] [blame] | 19 | "runtime" |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 20 | "strings" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 21 | "testing" |
| 22 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
| 24 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 25 | "android/soong/android" |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 26 | "android/soong/genrule" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 29 | func TestMain(m *testing.M) { |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 30 | os.Exit(m.Run()) |
| 31 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 32 | |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 33 | var prepareForRustTest = android.GroupFixturePreparers( |
| 34 | android.PrepareForTestWithArchMutator, |
| 35 | android.PrepareForTestWithDefaults, |
| 36 | android.PrepareForTestWithPrebuilts, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 38 | genrule.PrepareForTestWithGenRuleBuildComponents, |
| 39 | |
| 40 | PrepareForIntegrationTestWithRust, |
| 41 | ) |
| 42 | |
| 43 | var rustMockedFiles = android.MockFS{ |
| 44 | "foo.rs": nil, |
| 45 | "foo.c": nil, |
| 46 | "src/bar.rs": nil, |
| 47 | "src/any.h": nil, |
| 48 | "proto.proto": nil, |
| 49 | "proto/buf.proto": nil, |
| 50 | "buf.proto": nil, |
| 51 | "foo.proto": nil, |
| 52 | "liby.so": nil, |
| 53 | "libz.so": nil, |
| 54 | "data.txt": nil, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 57 | // testRust returns a TestContext in which a basic environment has been setup. |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 58 | // This environment contains a few mocked files. See rustMockedFiles for the list of these files. |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 59 | func testRust(t *testing.T, bp string) *android.TestContext { |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 60 | skipTestIfOsNotSupported(t) |
| 61 | result := android.GroupFixturePreparers( |
| 62 | prepareForRustTest, |
| 63 | rustMockedFiles.AddToFixture(), |
| 64 | ). |
| 65 | RunTestWithBp(t, bp) |
| 66 | return result.TestContext |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 67 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 68 | |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame] | 69 | func testRustVndk(t *testing.T, bp string) *android.TestContext { |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 70 | skipTestIfOsNotSupported(t) |
| 71 | result := android.GroupFixturePreparers( |
| 72 | prepareForRustTest, |
| 73 | rustMockedFiles.AddToFixture(), |
| 74 | android.FixtureModifyProductVariables( |
| 75 | func(variables android.FixtureProductVariables) { |
| 76 | variables.DeviceVndkVersion = StringPtr("current") |
| 77 | variables.ProductVndkVersion = StringPtr("current") |
| 78 | variables.Platform_vndk_version = StringPtr("VER") |
| 79 | }, |
| 80 | ), |
| 81 | ).RunTestWithBp(t, bp) |
| 82 | return result.TestContext |
Ivan Lozano | f76cdf7 | 2021-02-12 09:55:06 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 85 | // testRustCov returns a TestContext in which a basic environment has been |
| 86 | // setup. This environment explicitly enables coverage. |
| 87 | func testRustCov(t *testing.T, bp string) *android.TestContext { |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 88 | skipTestIfOsNotSupported(t) |
| 89 | result := android.GroupFixturePreparers( |
| 90 | prepareForRustTest, |
| 91 | rustMockedFiles.AddToFixture(), |
| 92 | android.FixtureModifyProductVariables( |
| 93 | func(variables android.FixtureProductVariables) { |
| 94 | variables.ClangCoverage = proptools.BoolPtr(true) |
| 95 | variables.Native_coverage = proptools.BoolPtr(true) |
| 96 | variables.NativeCoveragePaths = []string{"*"} |
| 97 | }, |
| 98 | ), |
| 99 | ).RunTestWithBp(t, bp) |
| 100 | return result.TestContext |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // testRustError ensures that at least one error was raised and its value |
| 104 | // matches the pattern provided. The error can be either in the parsing of the |
| 105 | // Blueprint or when generating the build actions. |
| 106 | func testRustError(t *testing.T, pattern string, bp string) { |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 107 | skipTestIfOsNotSupported(t) |
| 108 | android.GroupFixturePreparers( |
| 109 | prepareForRustTest, |
| 110 | rustMockedFiles.AddToFixture(), |
| 111 | ). |
| 112 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 113 | RunTestWithBp(t, bp) |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // testRustCtx is used to build a particular test environment. Unless your |
| 117 | // tests requires a specific setup, prefer the wrapping functions: testRust, |
| 118 | // testRustCov or testRustError. |
| 119 | type testRustCtx struct { |
| 120 | bp string |
| 121 | fs map[string][]byte |
| 122 | env map[string]string |
| 123 | config *android.Config |
| 124 | } |
| 125 | |
Paul Duffin | 2c4ca8d | 2021-03-07 19:18:38 +0000 | [diff] [blame] | 126 | func skipTestIfOsNotSupported(t *testing.T) { |
Thiébaud Weksteen | 0a75e52 | 2020-10-07 14:30:03 +0200 | [diff] [blame] | 127 | // TODO (b/140435149) |
| 128 | if runtime.GOOS != "linux" { |
| 129 | t.Skip("Rust Soong tests can only be run on Linux hosts currently") |
| 130 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 133 | // Test that we can extract the link path from a lib path. |
| 134 | func TestLinkPathFromFilePath(t *testing.T) { |
| 135 | barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so") |
| 136 | libName := linkPathFromFilePath(barPath) |
| 137 | expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/" |
| 138 | |
| 139 | if libName != expectedResult { |
| 140 | t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName) |
| 141 | } |
| 142 | } |
| 143 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 144 | // Test to make sure dependencies are being picked up correctly. |
| 145 | func TestDepsTracking(t *testing.T) { |
| 146 | ctx := testRust(t, ` |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 147 | rust_ffi_host_static { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 148 | name: "libstatic", |
| 149 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 150 | crate_name: "static", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 151 | } |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame^] | 152 | rust_ffi_host_static { |
| 153 | name: "libwholestatic", |
| 154 | srcs: ["foo.rs"], |
| 155 | crate_name: "wholestatic", |
| 156 | } |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 157 | rust_ffi_host_shared { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 158 | name: "libshared", |
| 159 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 160 | crate_name: "shared", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 161 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 162 | rust_library_host_dylib { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 163 | name: "libdylib", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 164 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 165 | crate_name: "dylib", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 166 | } |
| 167 | rust_library_host_rlib { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 168 | name: "librlib", |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 169 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 170 | crate_name: "rlib", |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 171 | static_libs: ["libstatic"], |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame^] | 172 | whole_static_libs: ["libwholestatic"], |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 173 | } |
| 174 | rust_proc_macro { |
| 175 | name: "libpm", |
| 176 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 177 | crate_name: "pm", |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 178 | } |
| 179 | rust_binary_host { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 180 | name: "fizz-buzz", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 181 | dylibs: ["libdylib"], |
| 182 | rlibs: ["librlib"], |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 183 | proc_macros: ["libpm"], |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 184 | static_libs: ["libstatic"], |
| 185 | shared_libs: ["libshared"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 186 | srcs: ["foo.rs"], |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 187 | } |
| 188 | `) |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 189 | module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 190 | rustc := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 191 | |
| 192 | // 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] | 193 | if !android.InList("libdylib", module.Properties.AndroidMkDylibs) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 194 | t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)") |
| 195 | } |
| 196 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 197 | if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 198 | t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)") |
| 199 | } |
| 200 | |
| 201 | if !android.InList("libpm", module.Properties.AndroidMkProcMacroLibs) { |
| 202 | t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)") |
| 203 | } |
| 204 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 205 | if !android.InList("libshared", module.Properties.AndroidMkSharedLibs) { |
| 206 | t.Errorf("Shared library dependency not detected (dependency missing from AndroidMkSharedLibs)") |
| 207 | } |
| 208 | |
| 209 | if !android.InList("libstatic", module.Properties.AndroidMkStaticLibs) { |
| 210 | t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)") |
| 211 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 212 | |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame^] | 213 | if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=wholestatic") { |
| 214 | t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.Args["rustcFlags"]) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 217 | } |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 218 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 219 | func TestSourceProviderDeps(t *testing.T) { |
| 220 | ctx := testRust(t, ` |
| 221 | rust_binary { |
| 222 | name: "fizz-buzz-dep", |
| 223 | srcs: [ |
| 224 | "foo.rs", |
| 225 | ":my_generator", |
| 226 | ":libbindings", |
| 227 | ], |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 228 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 229 | } |
| 230 | rust_proc_macro { |
| 231 | name: "libprocmacro", |
| 232 | srcs: [ |
| 233 | "foo.rs", |
| 234 | ":my_generator", |
| 235 | ":libbindings", |
| 236 | ], |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 237 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 238 | crate_name: "procmacro", |
| 239 | } |
| 240 | rust_library { |
| 241 | name: "libfoo", |
| 242 | srcs: [ |
| 243 | "foo.rs", |
| 244 | ":my_generator", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 245 | ":libbindings", |
| 246 | ], |
| 247 | rlibs: ["libbindings"], |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 248 | crate_name: "foo", |
| 249 | } |
| 250 | genrule { |
| 251 | name: "my_generator", |
| 252 | tools: ["any_rust_binary"], |
| 253 | cmd: "$(location) -o $(out) $(in)", |
| 254 | srcs: ["src/any.h"], |
| 255 | out: ["src/any.rs"], |
| 256 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 257 | rust_binary_host { |
| 258 | name: "any_rust_binary", |
| 259 | srcs: [ |
| 260 | "foo.rs", |
| 261 | ], |
| 262 | } |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 263 | rust_bindgen { |
| 264 | name: "libbindings", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 265 | crate_name: "bindings", |
| 266 | source_stem: "bindings", |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 267 | host_supported: true, |
| 268 | wrapper_src: "src/any.h", |
| 269 | } |
| 270 | `) |
| 271 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 272 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Rule("rustc") |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 273 | if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") { |
| 274 | t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) |
| 275 | } |
| 276 | if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") { |
| 277 | t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings()) |
| 278 | } |
| 279 | |
| 280 | fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc") |
| 281 | if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") { |
| 282 | t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) |
| 283 | } |
| 284 | if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") { |
| 285 | t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings()) |
| 286 | } |
| 287 | |
| 288 | libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc") |
| 289 | if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") { |
| 290 | t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) |
| 291 | } |
| 292 | if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") { |
| 293 | t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings()) |
| 294 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 295 | |
| 296 | // Check that our bindings are picked up as crate dependencies as well |
| 297 | libfooMod := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 298 | if !android.InList("libbindings.dylib-std", libfooMod.Properties.AndroidMkRlibs) { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 299 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 300 | } |
| 301 | fizzBuzzMod := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Module().(*Module) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 302 | if !android.InList("libbindings.dylib-std", fizzBuzzMod.Properties.AndroidMkRlibs) { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 303 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 304 | } |
| 305 | libprocmacroMod := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Module().(*Module) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 306 | if !android.InList("libbindings.rlib-std", libprocmacroMod.Properties.AndroidMkRlibs) { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 307 | t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)") |
| 308 | } |
| 309 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 312 | func TestSourceProviderTargetMismatch(t *testing.T) { |
| 313 | // This might error while building the dependency tree or when calling depsToPaths() depending on the lunched |
| 314 | // target, which results in two different errors. So don't check the error, just confirm there is one. |
| 315 | testRustError(t, ".*", ` |
| 316 | rust_proc_macro { |
| 317 | name: "libprocmacro", |
| 318 | srcs: [ |
| 319 | "foo.rs", |
| 320 | ":libbindings", |
| 321 | ], |
| 322 | crate_name: "procmacro", |
| 323 | } |
| 324 | rust_bindgen { |
| 325 | name: "libbindings", |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 326 | crate_name: "bindings", |
| 327 | source_stem: "bindings", |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 328 | wrapper_src: "src/any.h", |
| 329 | } |
| 330 | `) |
| 331 | } |
| 332 | |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 333 | // Test to make sure proc_macros use host variants when building device modules. |
| 334 | func TestProcMacroDeviceDeps(t *testing.T) { |
| 335 | ctx := testRust(t, ` |
| 336 | rust_library_host_rlib { |
| 337 | name: "libbar", |
| 338 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 339 | crate_name: "bar", |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 340 | } |
| 341 | rust_proc_macro { |
| 342 | name: "libpm", |
| 343 | rlibs: ["libbar"], |
| 344 | srcs: ["foo.rs"], |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 345 | crate_name: "pm", |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 346 | } |
| 347 | rust_binary { |
| 348 | name: "fizz-buzz", |
| 349 | proc_macros: ["libpm"], |
| 350 | srcs: ["foo.rs"], |
| 351 | } |
| 352 | `) |
| 353 | rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc") |
| 354 | |
| 355 | if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") { |
| 356 | t.Errorf("Proc_macro is not using host variant of dependent modules.") |
| 357 | } |
| 358 | } |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 359 | |
| 360 | // Test that no_stdlibs suppresses dependencies on rust standard libraries |
| 361 | func TestNoStdlibs(t *testing.T) { |
| 362 | ctx := testRust(t, ` |
| 363 | rust_binary { |
| 364 | name: "fizz-buzz", |
| 365 | srcs: ["foo.rs"], |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 366 | no_stdlibs: true, |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 367 | }`) |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 368 | module := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module) |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 369 | |
| 370 | if android.InList("libstd", module.Properties.AndroidMkDylibs) { |
| 371 | t.Errorf("no_stdlibs did not suppress dependency on libstd") |
| 372 | } |
| 373 | } |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 374 | |
| 375 | // Test that libraries provide both 32-bit and 64-bit variants. |
| 376 | func TestMultilib(t *testing.T) { |
| 377 | ctx := testRust(t, ` |
| 378 | rust_library_rlib { |
| 379 | name: "libfoo", |
| 380 | srcs: ["foo.rs"], |
| 381 | crate_name: "foo", |
| 382 | }`) |
| 383 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 384 | _ = ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std") |
| 385 | _ = ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_rlib_dylib-std") |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 386 | } |