summaryrefslogtreecommitdiff
path: root/rust/rust_test.go
AgeCommit message (Collapse)Author
2021-04-15Merge changes I59439b77,I7dbaf8beThiébaud Weksteen
* changes: bloaty: measure stripped Rust binaries rust: do not strip static library
2021-04-15bloaty: measure stripped Rust binariesThiébaud Weksteen
Modify bloaty's MeasureSizeForPath to allow a module to provide multiple paths. This is used to measure both unstripped and stripped libraries/binaries. Add unit test to ensure correct measurements are generated for Rust. Test: m out/soong/binary_sizes.pb.gz Change-Id: I59439b77dbf1cf5ad71e1c02996a6a90938536b4
2021-04-13Add more Rust vendor image support.Ivan Lozano
This adds Rust vendor image support for all module types except Rust prebuilts. Bug: 184042776 Test: New Soong tests. Test: Example cc_library vendor module can depend on rust_ffi_shared. Test: Example rust_library vendor-only module compiles. Change-Id: Iaa30ad51fdaedcbf14687da5472581f6af62ff59
2021-04-05Don't use incorrect version names like VER or BOARD even in testsJiyong Park
All version names will go through ApiLevelFromUser which triggers an error when the name is not a valid one. Bug: 175678607 Test: m Change-Id: Id33bf64085603914d45ad7942cb8908a4734493f
2021-03-25rust: Add whole_static_libs, revert static_libIvan Lozano
Revert the static_lib behavior to the previous behavior (pass static libs to the linker rather than via to rustc using `-lstatic=<lib>`). To bundle static libraries into libraries, provide the whole_static_libs property which retains the current static_libs behavior. Passing all static libraries via -lstatic was resulting in odd bloat where in some cases static symbols were duplicated in binaries and libraries. This split makes it possible to be explicit about when static libraries should be bundled. Bug: 183182230 Test: mma system/bt; mma system/security/keystore2; mma external/rust Change-Id: Ic2dde5d1542dca5ce145aa3a3fbd9ea54440d991
2021-03-23Support test fixtures in rust packagePaul Duffin
Replaces the rust specific rustTestCtx mechanism with the general test fixtures mechanism as converting it to use preparers was not possible. Also, removes usages of the buildDir variable and removes it as it is no longer needed. Bug: 181070625 Test: m nothing Change-Id: I0176a7b6fb2d390ae23693f1e198da5124b4be63
2021-02-12rust: Emit android vndk cfg flag.Ivan Lozano
Pass an "android_vndk" cfg flag that indicates this code targets the vndk. This can be useful in instances where code might need to behave differently. This also includes a fix to make sure our vendor Soong tests are correctly configured. Bug: 179907868 Test: Soong tests pass. Test: Example module emits new cfg flags. Change-Id: I01cdf91f6f9d42cd8a759266d5170479664bf4bc
2021-02-05rust: Only pass "-lstatic" for rlibs.Ivan Lozano
Passing '-lstatic' for dylib static dependencies results in some unexpected bloat as the static libraries are included as whole-archives. For now, limit this to rlibs while we investigate. Bug: 175886967 Bug: 179122837 Test: cd system/bt/; mma Test: Checked size of dylibs. Change-Id: Id8328e95771e2ca8503bc8df35248b1c39cabc8e
2021-02-04rust: Pass cc static libs to rustc.Ivan Lozano
Pass static libraries to rustc via the "-lstatic" flag so that rustc can reason how to handle these libraries. This means that these static libraries get bundled into rlibs, reducing the need to redeclare these dependencies in dependent modules. Additionally, exported depFlags were never used anywhere, so remove this from flagExporter. Bug: 175886967 Bug: 179122837 Test: m Test: Checked that static symbols aren't duplicated in a resulting binary when it appears in a dependency graph more than once. Change-Id: Ifeb3c384e4fad8704206997242a0156ddcb87d2c
2021-01-29rust: Allow rust_tests to include data files.Ivan Lozano
Adds the ability to define data files that should be installed alongside the test. This also fixes a bug wherein rust_test properties were duplicated. Bug: 171710847 Test: rust_test module with "data" property installs files to device. Change-Id: I091489afaf7e76b751a33a28049590d9fb39fe5f
2021-01-15Migrate Rust to LLVM coverage.Joel Galenson
Bug: 177675913 Test: Manually compile, run, and see output with llvm-cov. Change-Id: I66729cff87a848782e9fa1b95cbbc06318c5761a
2020-12-11Merge rust_protobuf and rust_grpcio module types.Ivan Lozano
To allow grpc protobufs to include non-grpc protos in a singular library, we need to allow them to be defined as part of the same module. This CL merges the two previously distinct module types into rust_protobuf, and adds a new property for declaring which protos contain grpc definitions. Bug: 172952239 Test: rust_grpcio modules converted to rust_protobuf modules and build. Test: Example rust_protobuf module with both proto types builds. Change-Id: I0e627fd97bc6f74de89d309e3344694a1e76586d
2020-12-01Merge "rust: Add support for multiple protos per module."Ivan Lozano
2020-11-30rust modules can be included in apexJiyong Park
We will have some APEXes having rust binaries and libraries. So, adding the support for the types of modules. rust.Module now inherits from android.ApexModuleBase and implements the android.ApexModule interface. Bug: 172414324 Test: m Exempt-From-Owner-Approval: rebased after +2 from the owner Change-Id: I356ef4c45f782a6460f001e83af96d1710642d80
2020-11-30rust: Add support for multiple protos per module.Ivan Lozano
This further emulates the rust-protobuf gen_mod_rs flag by providing support for generating a single module containing multiple protobuf definitions. Bug: 171361369 Test: New Soong tests. Test: Example module containing multiple protos works. Change-Id: I815f9628a8289ae512758073dac49bc4535abf01
2020-11-23Annotate dependency tags for dependencies of installed filesColin Cross
Relands Ic22603a5c0718b5a21686672a7471f952b4d1017 with a minor change to track libc++ dependencies for python hosts and after a fix to an internal genrule that depended on transitively installed java libraries (ag/13068670). Soong currently assumes that installed files should depend on installed files of all transitive dependencies, which results in extra installed file dependencies through genrules, static libs, etc. Annotate dependency tags for dependencies for which the installed files are necessary such as shared libraries and JNI libraries. This avoids extra installed files, and is also a first step towards genrules using their own copy of tools instead of the installed copy. Bug: 124313442 Test: m checkbuild Test: java.TestBinary Test: cc.TestInstallSharedLibs Test: deptag_test.go Change-Id: I725871249d561428e6f67bba6a7c65b580012b72
2020-11-17Revert "Annotate dependency tags for dependencies of installed files"Colin Cross
This reverts commit 62a0cfd05460d0e760ce9133690e48861bb57eee. Reason for revert: b/173475545 Change-Id: I4e834200c8e68dfa1b8144dfd1fa95ca68554980
2020-11-14Annotate dependency tags for dependencies of installed filesColin Cross
Soong currently assumes that installed files should depend on installed files of all transitive dependencies, which results in extra installed file dependencies through genrules, static libs, etc. Annotate dependency tags for dependencies for which the installed files are necessary such as shared libraries and JNI libraries. This avoids extra installed files, and is also a first step towards genrules using their own copy of tools instead of the installed copy. Bug: 124313442 Test: m checkbuild Test: java.TestBinary Test: cc.TestInstallSharedLibs Test: deptag_test.go Change-Id: Ic22603a5c0718b5a21686672a7471f952b4d1017
2020-11-12Pass Config to NewTestContext instead of ctx.RegisterColin Cross
Prepare for using Config when adding singletons by passing Config to NewTestContext and NewContext instead of to ctx.Register. This will enable a followup change to store SingletonMakeVarsProviders registered on the Context in the Config, which is necessary to run multiple tests in parallel without data races. Test: all soong tests Change-Id: Id229629a4e42ff4487d317241673837726c075fc
2020-10-09Revert "Make lots of tests run in parallel"Colin Cross
This reverts commit 323dc60712491c71ccdc5363c42df61f0a192487. Reason for revert: Possible cause of test instability Bug: 170513220 Test: soong tests Change-Id: Iee168e9fbb4210569e6cffcc23e60d111403abb8
2020-10-08rust: refactor tests setupThiébaud Weksteen
Move to a builder pattern to increase flexibility when generating the test configuration. The testRust, testRustCov and testRustError are kept as main entry points for standard tests. Add documentation. Test: m nothing Change-Id: I891bec982ff2d65413f150d2395edf0fb0d68a43
2020-10-06Make lots of tests run in parallelColin Cross
Putting t.Parallel() in each test makes them run in parallel. Additional t.Parallel() could be added to each subtest, although that requires making a local copy of the loop variable for table driven tests. Test: m checkbuild Change-Id: I5d9869ead441093f4d7c5757f2447385333a95a4
2020-09-18rust: Add libstd linkage mutator for rlibs.Ivan Lozano
The current state of linkage is that device targets always link libstd dynamically except for rust_ffi_static which requires a static libstd linkage. However this prevents producing rust_ffi_static modules which depend on other Rust libraries as those dependencies will link libstd dynamically and cause a collision. We also want our rust_test modules to statically link in libstd as well. This adds a linkage mutator for rlibs that creates a variant for each libstd linkage. Dependent modules can then select the variant that matches their linkage of libstd. Also fixes an issue where installation paths were being generated for rlibs and static libs even though they weren't being installed. This broke when adding the linkage mutator as Make would complain about multiple targets producing the same output. Bug: 168729404 Test: rust_ffi_static module with other rustlib dependency can be built. Change-Id: I955b484bf5809e8fc5517750c7f8df82d3ca8895
2020-08-31Add rust_protobuf module.Treehugger Robot
This adds a new SourceProvider module type to handle protobuf code generation. See the new test for an example of how to call this. Bug: 143953733 Test: New soong tests pass. Test: Replacing genrules in crosvm with rust_protobuf modules. Change-Id: Ie3117129cde37b8736bc18ee09bf5cde27c01c34
2020-08-26[rust] Pass cc dependencies as linker flags.Ivan Lozano
In order to support cc dependencies which do not start with the 'lib' prefix, we can't pass them through the -l flag. Instead, we can pass them directly to linker flags. Bug: 166151658 Test: cd external/rust/; mma Test: cd external/crosvm/; mma Test: Test linking to a cc dep that does not begin with 'lib' Change-Id: I5acbf3d3405e66446f3eae600b35683c4eb3d8a5
2020-08-04[rust] Add SourceProviders as crates support.Ivan Lozano
This allows SourceProvider modules to create rust_library variants so that generated source can be referenced as an external crate rather than via an include macro. This is done by including rust_bindgen modules like any other library, as a dependency in either rlibs, dylibs, or rustlibs. This renames the stem and flags properties for rust_bindgen modules to source_stem and bindgen_flags, respectively. This deconflicts with the usage in baseCompiler. This also removes 'subName' from the Module struct and moves it over to SourceProvider, which was the only user. This allows us to set it in baseSourceProvider's AndroidMk; setting it in Module's AndroidMk was causing problems finding NOTICE files for bindgen library variants. Bug: 159064919 Test: New Soong tests pass. Test: Local test rust_binary can use rust_bindgen module as a crate. Change-Id: Ieb2cb614c2dd0b5aa7120541d77f6f822a6a1806
2020-07-22Enforce correct variant usage for rust_bindgen.Ivan Lozano
Modules defined in the srcs property are automatically added as dependencies with AddDependency(), which will use any variant available. This can cause incorrect architecture bindings to be silently pulled in, such as when a host module uses a rust_bindgen module that doesn't create a host variant. This moves populating depPaths.SrcDeps over to depsToPaths and adds a check for SourceProviders to make sure the correct OS and architecture is being used. Bug: 161826371 Test: Soong no longer silently pulls in bindings for the wrong target. Test: New Soong test to catch this case passes. Change-Id: I2b3651cf6fc7dabf4081434df1c455e637f5b3a4
2020-07-20Allow rust module dependency on SourceProviders.Ivan Lozano
Allow rust modules to depend on and use generated source code provided by SourceProvider modules and genrule modules without resorting to hardcoded output paths. All generated sources are now copied to a dependent module's intermediates directory, then OUT_DIR is set to point to that path when calling rustc. This matches the common convention used in most rust crates to include generated source code from the path defined in the OUT_DIR environment variable. A couple other small notable changes are included in this CL: * prebuiltLibraries can no longer include generated source files as they should be prebuilt. * srcPathFromModuleSrcs now excludes the main source file from the second return value so its a list of only the generated sources. Bug: 159064919 Test: Local example rust_library compiles with rust_bindgen dependency. Test: Local example rust_library compiles with genrule dependency. Test: Collision detected when multiple providers produce similar output. Test: New Soong tests pass. Change-Id: I59f54a25368c680b9086420c47ec24ab8cd1de6b
2020-07-08Specify module dependency in the srcs listChih-Hung Hsieh
* "srcs" list contains one main Rust source file, followed by optional dependent modules. * A dependent module included in the "srcs" list is the module name prefixed with ":". * Add a simple test. Bug: 160331255 Test: make and manual test build dependencies on genrule modules Change-Id: I4f079138c2599158810b6412fce81b612a3f64a4
2020-07-01rust: Change default variantsMatthew Maurer
rust_library now produces only rlib and dylib variants. rust_library_foreign now produces static and shared variants. This change was made because both are common cases, but all four together essentially never happens. This allows us to have fewer repeat module definitions. Bug: 143217452 Test: cd external/rust; mma Change-Id: Iaf69e8da38f7c12710331c51464699cf7cbbb656
2020-06-25Remove duplicate Helper callThiébaud Weksteen
The testRustContext function is used to prepare the environment for the unit tests. As such, it is marked as a Helper function. Remove a second superfluous call within its definition. Test: m nothing Change-Id: I37ea9a584b33498794c1cac828a7557d4bea8d7c
2020-06-22Make native_coverage clause work with ClangCoverageColin Cross
Make uses NATIVE_COVERAGE to enable gcov coverage and CLANG_COVERAGE to enable clang coverage. NATIVE_COVERAGE is translated to the Soong Native_coverage product variable which triggers the native_coverage clause in Android.bp files. The clause also needs to be triggered for CLANG_COVERAGE. Rename the existing Native_coverage product variable to GcovCoverage, and regenerate Native_coverage when either GcovCoverage or ClangCoverage are set. Also remove NativeLineCoverage, it wasn't doing anything differently than Native_coverage. Bug: 159059537 Test: m checkbuild Change-Id: I215124a9b35a2ad50ad562079d392e3d33da11f4
2020-06-10Rename native code coverage paths product variables in Soong.Roland Levillain
Rename `CoveragePath` and `CoverageExcludePaths` as `NativeCoveragePath` and `NativeCoverageExcludePaths` (resp.). Also rename function `android.CoverageEnabledForPath` as `android.NativeCoverageEnabledForPath`. Test: m nothing Bug: 158212027 Change-Id: Id2c11a638e88088096420b537effa866d7667304
2020-05-05Add gcov coverage support to Rust modules.Ivan Lozano
This adds gcov coverage support for Rust device library and binary modules (including test modules). Support is provided to pass Rust static library gcno files to CC modules and visa versa. Additional changes: * Begin mutator added for Rust modules. * SuffixInList added to android package. * CoverageEnabled added to Coverage interface. * CoverageFiles added to LinkableLibrary interface. * Fix in coverage mutator for non-CC modules which marked the wrong variant as the coverage variant. * Added coverage libraries to the cc.GatherRequiredDepsForTest. Bug: 146448203 Test: NATIVE_COVERAGE=true COVERAGE_PATHS='*' m -j <rust_module> Change-Id: If20728bdde42a1dd544a35a40f0d981b80a5835f
2020-04-29Provide 32-bit and 64-bit Rust libs by default.Ivan Lozano
CC libraries which depend on Rust libraries get missing dependency errors when building 32-bit variants dependent on Rust modules which don't explicitly have "multilib: both" declared. Because CC libraries use MultilibBoth by default, Rust should do the same. This also fixes a bug where the ARM32 toolchain incorrectly embedded toolchain64Bit instead of toolchain32Bit. Bug: 154730212 Test: Rust libraries provide both variants by default. Change-Id: Ia545fe069d3c6b77c3d18f4f10267e2c72ee0bab
2020-04-23Clean up rust tests.Ivan Lozano
The list of required deps for testing is a lot shorter as we no longer include as many prebuilt libraries and our list of stdlibs is much shorter. Remove the libraries we no longer need, and add the non-prebuilt libstd and libtest to the deps generated for every test. Bug: 153463188 Test: Soong tests pass. Change-Id: I94f7b514797ab8d6aedb543ea6afdb07611b7293
2020-02-19Move NDK test modules into cc/testing.goColin Cross
Move the NDK modules defined in app_test.go into cc/testing.go in preparation for using sdk_version: "current" in more tests. Test: all soong tests Change-Id: I80bc31225fb4562fce42781219cefbbd6affae06
2020-02-06Fix lib name resolution if extension is substring.Ivan Lozano
If a library happens to contain the extension as a substring in its name, libNameFromFilePath will return a truncated library name. Change this calculation to remove the last instance of the extension substring instead. Bug: 147140513 Test: Modified rust tests pass. Change-Id: I0ed91e5f571ed5c4040ee15956a1598846aee43a
2019-12-18Move filesystem into ConfigColin Cross
The filesystem object was available through ModuleContext.Fs(), but gives too much access to the filesystem without enforicing correct dependencies. In order to support sandboxing the soong_build process move the filesystem into the Config. The next change will make it private. Bug: 146437378 Test: all Soong tests Change-Id: I5d3ae9108f120fd335b21efd612aefa078378813
2019-12-13Use empty string for core image variantColin Cross
Use the empty string for the core image variant so that modules added to imageMutator do not change their build directory. Bug: 142286466 Test: m checkbuild Change-Id: Ida4534d9a4d6176236aaa480fed359ce27acfaa1 Merged-In: Ida4534d9a4d6176236aaa480fed359ce27acfaa1 (cherry picked from commit 72d685ee7f45e5393be44ae4159edf083ac918de)
2019-11-14Merge changes from topic "rust-sysroot"Jeffrey Vander Stoep
* changes: Enable x86_64 device support Build Rust Device Sysroots in Soong
2019-11-13Build Rust Device Sysroots in SoongMatthew Maurer
In order to ensure we are using current platform Bionic for any platform Rust binaries, we need to build the sysroot in Soong. This will also enable us too hook the "test" crate if necessary. While both a dynamic and static sysroot are available, on device only a dynamic sysroot will be injected. On host, we continue using the sysroot used to build the compiler as before. Bug: 139486496 Change-Id: I127377e5b056610ceb5015a34d266250320fbc31
2019-11-04Enforce correct rust library file names.Ivan Lozano
rustc expects libraries and proc_macro filenames to conform to a particular format, alphanumeric with underscores and lib${crate_name}.*. Enforce this with a check when getStem() is called. This makes the crate_name property required for proc_macros and libraries. This also removes the notion of a default crate name derived from the module name. It's not needed for binaries, so this won't impact them. Bug: 143579265 Test: m -j crosvm.experimental Change-Id: I2770cf7d02dd4291c3d240d58d242b940098dcee
2019-10-28Add support for Rust C libraries.Ivan Lozano
Adds the ability for rust modules to be compiled as C libraries, and allows cc modules to depend on these rust-generated modules. This also means that soong-rust should not have any dependencies on soong-cc aside from what's required for testing. There's a couple small fixes included as well: - A bug in libNameFromFilePath that caused issues when library's had "lib" in their name. - VariantName is removed from rust library MutatedProperties since this was unused. Bug: 140726209 Test: Soong tests pass. Test: Example cc_binary can include a rust shared library as a dep. Test: m crosvm.experimental Change-Id: Ia7deed1345d2423001089014cc65ce7934123da4
2019-09-25Add Soong test for device proc-macro deps.Ivan Lozano
Ensure that devices can include proc_macros, which are host-only and may include host-only dependencies. Bug: 141491501 Test: Soong tests pass. Test: Test fails as expected when removing CL 1126496 Change-Id: I3ae7ab80283cd1fd4b800a533cb3205b3c108d45
2019-09-24Fix proc_macro dependency handling.Ivan Lozano
Currently proc_macros don't pull in the correct arch dependencies when the host arch differs from the target arch. This fixes how proc_macro dependencies are handled by defining them as always being host-only and including them as dependencies for device-modules by using AddFarVariationDependencies. Bug: 141491501 Test: Example device rust module builds with proc_macro dependency. Change-Id: Ic037dc406ce90526f8b68c92fffc0d93a498a4ff
2019-09-03Do not run Soong tests for Rust on non-Linux hosts.Ivan Lozano
The Rust toolchain only supports Linux hosts, so skip Rust tests that depend on host toolchains when building on other platforms. Test: Tests still run on Linux hosts Bug: 140435149 Change-Id: I298b52589ab5c6a7ec3acc4db1111596cd995d76
2019-08-28Add Rust support to Soong.Ivan Lozano
Adds support to Soong for building rust modules. This currently only supports x86_64 device and x86 linux host targets. The functionality is sufficient to build crosvm. Bug: 136189233 Test: Test module builds. Test: crosvm builds. Change-Id: I6ea04615834a6d673578ab10ea1a2eb04259fe09