Commit graph

23 commits

Author SHA1 Message Date
Treehugger Robot
588aae727b Add rust_protobuf module.
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-31 14:05:39 -04:00
Dan Albert
92fe740677 Stop using prebuilt NDK CRT objects.
We don't need the prebuilt versions. The NDK CRT objects are (now)
built from the platform sources and the only difference is that the
NDK CRT objects also include an ELF note that identifies the NDK
version, which isn't helpful for anything built by the platform.

Add a `crt` property to cc_object that allows CRT objects to identify
themselves. CRT objects, unlike other modules, will have a variant
built per-API level they support, rather than just an SDK variant and
a platform variant. This is needed because new CRT objects will rely
on APIs not available in old libcs and old CRT objects will not
support all the features of a modern one.

Test: treehugger
Bug: http://b/159925977
Change-Id: I6595485fa1bfe0ad4945193d344b863f64eec654
2020-08-11 15:06:55 -07:00
Thiébaud Weksteen
83ee52f4cd rust: validate existence of library source
While rust_bindgen modules may be interpreted as libraries, they do not
have a reference to the generated source until bindgen has been
executed. For now, ignore these modules.

Update the unit tests to cover the rust_bindgen case.

Test: SOONG_GEN_RUST_PROJECT=1 m nothing
Bug: 162881856
Change-Id: I329d0fe3d94b77d395c3684f55ab01544ff7c18f
2020-08-06 15:17:46 +02:00
Paul Duffin
021f4e525f Fix prebuilt mutator ordering in tests
Previously, the prebuilt mutators were added by the
cc.RegisterRequiredBuildComponentsForTest() function as a convenience
but unfortunately it lead to some of the mutators being in a different
order in the tests than in the normal build.

This change:
* Extracts the RegisterPrebuiltMutators() call from
  cc.RegisterRequiredBuildComponentsForTest()
* Makes sure that the prebuilt mutators are registered before the
  visibility gatherer and enforcer mutators.

Bug: 162505935
Test: m nothing
Change-Id: I7d959b558200b502f0a5e4653c41ea01414e142a
2020-07-31 16:12:01 +01:00
Ivan Lozano
4fef93c53f Add SourceProviders and a rust_bindgen module type
Add SourceProvider modules which provides a base interface for more
complex code generation usecases such as bindgen. Also adds the
rust_bindgen module type which calls bindgen to generate Rust FFI
bindings to C.

Bug: 159064919
Test: Local test module generates bindings.
Test: New Soong tests pass.

Change-Id: Ie31467bbbe423497666ad837cf5fe1acd1e76bd8
2020-07-20 13:40:14 -04:00
Chih-Hung Hsieh
bbd25aeb42 Specify module dependency in the srcs list
* "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-08 23:50:00 -07:00
Matthew Maurer
c761eeca48 rust: Mutate prebuilt modules dylib/rlib
This change makes it possible to use a single module to provide both
dylib and rlib varieties of a library. This allows the use of libstd and
libtest from a rustlibs property, allowing linkage type to change
for different variants.

Bug: 159718669
Test: cd external crates; mma; m crosvm.experimental
Change-Id: I477c4d2faec63703fdc6dd42ba020747d6a50714
2020-07-01 11:27:12 -07:00
Matthew Maurer
2ae0513a8e rust: Change default variants
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-07-01 11:27:12 -07:00
Ivan Lozano
fc80fe7f2f Make rust_test file output more similar to cc_test.
This changes the way the output filename is calculated for rust_test
binaries to be more similar to cc_test.

This also removes the option to define multiple test binaries in a
single rust_test module via the TestPerSrc mutator. Now each rust_test
module corresponds to a single test binary.

Bug: 158500462
Test: m -j pin-utils_tests_pin_utils
Test: m -j unicode-xid_device_tests_unicode_xid
Change-Id: I6e0f79dcb4e49fa49d6ebb36abeef67a9eb180a0
2020-06-11 17:12:19 -04:00
Thiébaud Weksteen
e4d12a0468 Add rust-project.json generator
Because we are not relying on Cargo.toml for our crate dependencies,
we need to provide a structured file to rust-analyzer which describes
the locations of the crates. Add a generator for that purpose, similarly
to cc/compdb and cc/ccdeps.

Bug: 156395307
Test: SOONG_GEN_RUST_PROJECT=1 m nothing && \
      cat ${ANDROID_BUILD_TOP}/out/soong/rust-project.json
Change-Id: I46efe0adeddae281eaf86707504c3aa15b5e80b8
2020-06-11 11:22:31 +02:00
Ivan Lozano
a0cd8f9acb Add gcov coverage support to Rust modules.
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-05-05 10:30:15 -04:00
Ivan Lozano
9d1df10e2a Provide 32-bit and 64-bit Rust libs by default.
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-29 15:31:34 -04:00
Ivan Lozano
2f15bae336 Clean up rust tests.
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-04-23 09:39:34 -04:00
Paul Duffin
77980a8bb9 Dedup registration for cc default test config
The cc.GatherRequiredDepsForTest() method returns some default module
definitions that are required when using cc module types like
cc_library. Previously, the registration of the module types and
mutators needed to process those default definitions was duplicated
in the test config initialization.

This change removes that duplicated code and replaces it with calls
to cc.RegisterRequiredBuildComponentsForTest(ctx) which registers all
the required build components.

Test: m checkbuild
Bug: 146540677
Change-Id: I80b6913c5691ff164ce9d308b9e1da24940f2d42
2019-12-19 19:19:40 +00:00
Colin Cross
98be1bb00f Move filesystem into Config
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-18 08:19:10 -08:00
Colin Cross
ae6c5207cc Move ImageMutator after archMutator
Move the ImageMutator to be registered just after the archMutator
in preparation for moving it between osMutator and archMutator.
Requries updating variants in a few tests that now run the
ImageMutator.

Bug: 142286466
Test: no change to build.ninja
Test: all soong tests
Change-Id: Ia9d2a7bc0e225bedec3c9a83ea04f471a931bf47
2019-12-06 12:37:14 -08:00
Colin Cross
09ef474b6f Merge changes I0dcc9c7b,I9bc40642
* changes:
  Move cc.imageMutator into the android package
  Make CreateVariations return []android.Module
2019-11-25 22:30:17 +00:00
Colin Cross
4b49b768a2 Make TestContext.RegisterModuleType take an android.ModuleFactory
Avoid having to pass ModuleFactoryAdaptor to every call to
RegisterModuleType in a test by wrapping RegisterModuleType.

Test: all soong tests
Change-Id: If8847d16487de0479cc3020b728256922b3cadba
2019-11-25 10:59:44 -08:00
Colin Cross
7228ecd5e3 Move cc.imageMutator into the android package
Prepare for making the image mutator available to all modules and
moving it between the os and arch mutators by moving it into the
android package and using an interface implemented by the module
types to control it.

Bug: 142286466
Test: No unexpected changes to out/soong/build.ninja
Change-Id: I0dcc9c7b5ec80edffade340c367f6ae4da34151b
2019-11-20 15:21:32 -08:00
Chih-Hung Hsieh
a5f22ed6b0 Add rust_test and rust_test_host.
* Rust tests are like binary files compiled with --test.
  New test.go follows binary.go code patterns and reuses
  some code in binary.go.
* Generate one test per source file as testPerSrc in cc/test.go.
  The "all tests" variation feature of cc/test.go is not copied yet.
  Fix some Stem and SubName settings to make testPerSrc work.
* Move cc.CheckDuplicate to android.CheckDuplicate,
  which is now shared by cc and rust.
* Refactor tests in binary_test.go and add new test_test.go.

Bug: 140938178
Test: mm in rust projects, added rust_test and rust_test_host
Change-Id: Ia6fec8b4cf2572fd352ab1938a1f3c7b5cca2212
2019-10-29 17:19:03 -07:00
Ivan Lozano
52767be335 Add support for Rust C libraries.
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-10-28 22:09:01 -07:00
Ivan Lozano
b9040d6b76 Add Soong test for device proc-macro deps.
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-25 00:23:54 +00:00
Ivan Lozano
ffee334706 Add Rust support to Soong.
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
2019-08-28 14:11:07 -07:00