Commit Graph

192 Commits

Author SHA1 Message Date
Colin Cross 2eddd06879 Merge "Add libraryDependencyTag to track dependencies on static and shared libraries" 2020-08-06 00:06:28 +00:00
Matthew Maurer 53bba5de8a Merge "Make Rust test harness optional for test binaries" 2020-08-05 21:26:45 +00:00
Ivan Lozano d13b308960 Merge "Make source_stem required for Rust SourceProviders" 2020-08-05 19:38:19 +00:00
Ivan Lozano 80668b07d2 Merge "Add support for custom bindgen binaries." 2020-08-05 19:08:20 +00:00
Thiébaud Weksteen 6090575f63 Merge changes I275f0463,Ie736d7eb
* changes:
  rust: handle modules with same crate_name
  rust: validate existence of library source
2020-08-05 18:50:06 +00:00
Ivan Lozano ff3a5b31c0 Make source_stem required for Rust SourceProviders
This removes ambiguity for developers with the 'stem' property.

Bug: 159064919
Test: New Soong test; error is produced if this property is undefined.
Change-Id: I790fbcfa6cd7dbf6df63b5cf5c22983426ec072e
2020-08-05 13:31:34 -04:00
Ivan Lozano c564d2d5a4 Add support for custom bindgen binaries.
In some cases customized logic is required to generate the expected
bindgen bindings. This adds support for rust_bindgen modules to define a
HostTool module to use instead of bindgen.

Bug: 161816141
Test: New Soong tests pass.
Test: Local test case shows custom_binary module being used for bindgen
      generation.

Change-Id: Id52aec4f25c38206d7e585d8e662be7836aa1d4b
2020-08-05 10:51:43 -04:00
Thiébaud Weksteen ad8ac53581 rust: handle modules with same crate_name
crate_name do not need to be unique. A library may depend on two
different versions of the same crate. Use the module name instead of the
crate name when indexing the modules for rust-project.json.

Test: SOONG_GEN_RUST_PROJECT=1 m nothing
Bug: 162896400
Change-Id: I275f04639ef05f2b649c30168046e13b2efcacb9
2020-08-05 16:34:38 +02:00
Ivan Lozano b14e141519 Merge "[rust] Disable clippy for rust_bindgen modules." 2020-08-05 12:47:14 +00:00
Thiébaud Weksteen 891cd578c7 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: Ie736d7ebb115f2c1f9a90be006c972ce24265c6a
2020-08-05 11:29:33 +02:00
Ivan Lozano 32267c88c4 [rust] Disable clippy for rust_bindgen modules.
bindgen generated code may not pass clippy checks, so preemptively
disable clippy for these.

Bug: 162828070
Test: clippy is not called when compiling rust_bindgen library variants.
Change-Id: I9632c889417bdfd1adf96d9cfbccbe6340824205
2020-08-04 16:27:16 -04:00
Stephen Crane da931d4abd [rust] Disable lints for generated bindings
Bindgen generated bindings will not pass lints, so we need to disable
them when building bindings crates.

Test: m libbinder_ndk_bindgen
Change-Id: I4536f15f8505ff8d5436f1e6cbc2035e6801276d
2020-08-04 13:04:32 -07:00
Stephen Crane 02a623d8d3 Make Rust test harness optional for test binaries
Adds a test_harness field to Rust test blueprint properties. If this
field is explicitly set to false, do not build the test binary with
`--test`. This is necessary for Rust tests which cannot use the standard
test harness.

Test: atest rustBinderTest
Test: atest --host proc-macro2_tests_test
Change-Id: Icbcb54422cc716348feae56b2d71f013516b0ac0
2020-08-04 18:57:10 +00:00
Ivan Lozano 89e4882d37 Merge "[rust] Add SourceProviders as crates support." 2020-08-04 17:46:22 +00:00
Ivan Lozano 26ecd6c597 [rust] Add SourceProviders as crates support.
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-08-04 08:13:24 -04:00
Thiébaud Weksteen 9b7b8f169a Fix dependency merging for rust-project.json
Test: SOONG_GEN_RUST_PROJECT=1 m nothing; inspect rust-project.json
Bug: 159591910
Change-Id: I95beb2e75f2306ae2bf2be02ab5f1a348d134b56
2020-08-04 06:36:20 +00:00
Janis Danisevskis 8b7eb8d86a Rust: allow system/security
Bug: 160623310
Test: None
Change-Id: I00ddb0fb26e7e67f832fb321186f7313209c2669
2020-08-03 21:27:41 +00:00
Thiébaud Weksteen e81c924f0c Move getEdition to a baseCompiler method
Test: cd build/soong; mma
Test: cd external/rust/; mma
Change-Id: Ide63b2e633e7c4345c6338e107f5d66688e4cf58
2020-08-03 11:00:43 +02:00
Ivan Lozano bbec4c4325 Merge "[rust] Clean up unused link variations." 2020-07-31 20:03:40 +00:00
Ivan Lozano 89435d1a50 [rust] Clean up unused link variations.
rust_library modules no longer produce "link" variants alongside
"rust_libraries" variants as the former have been moved to rust_ffi
modules. rust_library modules however still create empty link variants
and code paths still assume that modules can support both rust linkage
and cc linkage. This adds unnecessary complexity that no longer serves a
purpose.

This cleans this up by removing the unused "link" variant for
rust_library modules and simplifies code paths that can now assume
modules are either a rust library or a cc library, but not both.

This also fixes a bug where Shared() was returning the wrong value.

Bug: 159064919
Test: cd external/rust/; mma
Test: cd external/crosvm/; mma

Change-Id: I3b5498c80b315c56b621dcb1388022fecc1bfc1b
2020-07-31 13:53:13 -04: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
Colin Cross 6e511a9a9f Add libraryDependencyTag to track dependencies on static and shared libraries
dependencyTag uses a set of predefined tags to identify different types
of dependencies.  There are already multiple bits of metadata stored
in the dependency tag (Library, Shared, ReexportFlags), and supporting
them all requires a combinatorial explosion of predefined tags and
causes issues when using equality comparisons if a new bit of metadata
is added.

Add a new libraryDependencyTag type that will contain the metadata
bits, and replace the quality comparisons with checks on the metadata
bits.

There are 5 TODOs where modifying the checks identified problems with
the existing checks.  These were left in place to produce identical
build output and will be fixed separately.

Bug: 162437057
Test: no change to build.ninja or {Android,make_vars,late}-${TARGET_PRODUCT}.mk
Change-Id: I72d4207dcf381c07c92e00e5a03968ebb5ed8d30
2020-07-29 13:22:30 -07:00
Ivan Lozano 3feff6c130 Merge changes I4efdf333,I4abaf8e7
* changes:
  Ensure hermetic device rust_bindgen.
  Generate deps file for rust_bindgen modules.
2020-07-29 00:25:42 +00:00
Ivan Lozano 45901edb9a Ensure hermetic device rust_bindgen.
rust_bindgen was not hermetic previously as it would pull in host
headers for device targets. This fixes that by using the same flags we
use when compiling with Clang. This also makes sure our rust_bindgen
headers are built as similar as possible to their respective
cc_libraries.

This also pulls in the bionic dependencies as well, which provide the
headers required for device targets.

Bug: 162007475
Test: device rust_bindgen deps file does not reference host headers.

Change-Id: I4efdf333e011a6c6d73a0345e5485823f166d17a
2020-07-28 14:53:57 -04:00
Ivan Lozano e1e844b83c Generate deps file for rust_bindgen modules.
Bug: 162007475
Test: deps file generated containing the dependent header files.
Change-Id: I4abaf8e76875f7657c1b8386749217adcba1ffa2
2020-07-24 15:39:11 -04:00
Ivan Lozano 41b4d79dab Merge "Add a rust_bindgen_host module type." 2020-07-24 18:53:13 +00:00
Ivan Lozano 264771ce53 Merge "Enforce correct variant usage for rust_bindgen." 2020-07-24 18:41:32 +00:00
Ivan Lozano f90e64a34f Merge "Call rustfmt on rust_bindgen bindings." 2020-07-23 12:41:58 +00:00
Ivan Lozano ec54eec571 Call rustfmt on rust_bindgen bindings.
This makes debugging easier when the bindings contain errors.

Bug: 161730753
Test: Generated bindings are formatted.
Change-Id: Ic46f69d8b6d07b4dc6912b7f02d7427ea6c11cde
2020-07-22 16:51:33 -04:00
Ivan Lozano f6fe9956bf Add a rust_bindgen_host module type.
Bug: 161826371
Test: Local rust_bindgen_host only provides host variants.
Change-Id: I8cc7819a193a6eefe40402e4b6a82f436c5de78a
2020-07-22 20:34:52 +00:00
Ivan Lozano 07cbaf4d89 Enforce correct variant usage for rust_bindgen.
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-22 20:34:22 +00:00
Ivan Lozano 9429c612ff Merge "Add source collision test, rust_bindgen doc." 2020-07-22 17:44:03 +00:00
Ivan Lozano 10735d90d6 Add source collision test, rust_bindgen doc.
Bug: 159064919
Test: Soong tests pass (and fail if error is modified).
Change-Id: Id4f76e53e11e46ae495f9613a2699c598e7daea4
2020-07-22 09:18:13 -04:00
Ivan Lozano bae62bee7d Provide generated sources to clippy.
clippy was not being provided generated sources previously, so it would
error out on being unable to locate the sources.

Test: Clippy no longer errors out on generated sources.
Bug: 161748694
Change-Id: I85907327ca40c82a9520e0c0dbd643bfba6b7315
2020-07-21 14:24:35 -04:00
Ivan Lozano c3b1a61253 Merge changes from topic "rust_bindgen"
* changes:
  Allow rust module dependency on SourceProviders.
  Add SourceProviders and a rust_bindgen module type
2020-07-20 21:18:33 +00:00
Ivan Lozano 43845688bc Allow rust module dependency on SourceProviders.
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-20 13:40:31 -04: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
Jeff Vander Stoep 6e97a7b4a1 rust: Use host linker when building for Mac host.
This behavior is non-hermetic, but matches the behavior of the C++
support. On Linux, using lld works, but on OSX, this fails because lld
does not support Apple's new .tbd files.

Bug: 155302034
Test: On both Linux and Mac hosts:
    cd external/rust; mma

Change-Id: I0ad489113d720bdb9c3b7a67cce9d1e72266f428
2020-07-15 22:02:18 +02:00
Ivan Lozano 33c05281a5 Fix incorrect Rust dylib extension on darwin.
rustc expects Rust dylibs to have a .dylib extension on darwin.

Bug: 155302034
Test: rust_library_host outputs have correct extension on darwin.
Change-Id: I17b0d7eaf0f42f8186185e3f14c3a8e992c74fde
2020-07-15 11:35:30 -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 bb3add1104 rust: Suppress default sysroot unconditionally
With proper prebuilt modules, we can avoid any rustc implicit sysroot
searching.

Asd a bonus, this should make rust-project.json generation correctly
grab otherwise implicit dependencies.

Prebuilt rlibs may include several dependency rlibs. Without a
link_dirs attribute, every dependency (even if unexported) would need a
separate module.

Previously we were casing out on exact structs, which might be OK when
libraryDecorator and procMacroDecorator were the only possibilities, but
repeating the logic for three types is too much. Using an interface
makes this logic scale better.

Bug: 159591910
Test: cd external/rust; mma; m crosvm.experimental
Change-Id: Ia1124e09f48cd05e39f094bbcb988622ebd2272f
2020-07-01 11:27:12 -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 0f003b1851 rust: Add rustlibs auto dependency selection
Adds the rustlibs dependency type which will automatically select
between rlib and dylib based on the type of the library.

Bug: 143217452
Test: cd external/rust; mma
Change-Id: I97faadae98bf957090a32939cfb2d3a10f74a057
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
Matthew Maurer 128f53b3b4 rust: Fix Properties inheritance for prebuilts
Previously, we had just called AddProperties inside the factory on
libraryDecorator's properties directly. This inadvertantly missed their
MutatedProperties. Inheriting properties from libraryDecorator rather
than baseCompiler will avoid that type of error in the future.

Test: cd external/rust; mma; m crosvm.experimental
Change-Id: Ic08c410e69a8e272d63f9ffbdbe16ba9c3cc3de1
2020-07-01 11:27:12 -07:00
Thiébaud Weksteen 6bbe5774a3 Merge "Explicitly define Rust default lints" 2020-07-01 17:38:58 +00:00
Thiébaud Weksteen 8e46efac71 Explicitly define Rust default lints
Add documentation on how lints are defined and used in Android. Merge
the deny_warnings attribute with a new attribute (no_lint) which can be
used to disable the default linting parameters.
Explicitly allow all lints for external/ and prebuilts/, which remove
any warning when building sysroot for the devices.

Test: cd external/rust/crates; mma
Test: add dummy internal Rust module; mma
Change-Id: I62be1c41aeda4068fb9e288038727c1de5ffe547
2020-07-01 17:11:58 +02:00
Chih-Hung Hsieh 5c4e48956c Enable genrule modules for Rust host binaries
* Add HostToolPath to use rust_binary_host modules as host tools.

Bug: 157666974
Test: make with local genrule examples
Change-Id: I9648313c0f0695d2e695f18ded4710350b2d6475
2020-06-30 10:23:49 -07:00
Thiébaud Weksteen 79e546f7df Merge "Remove moduleContextImpl struct" 2020-06-30 16:48:15 +00:00
Matthew Maurer 85a08fc454 Merge "Add clippy-driver build rule" 2020-06-26 20:33:37 +00:00