Commit Graph

152 Commits

Author SHA1 Message Date
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
Treehugger Robot a8bfdbd131 Merge "Update rustc to 1.44.0" 2020-06-26 19:26:09 +00:00
Treehugger Robot b1af227b4a Merge "Add Matt to OWNERS for Rust" 2020-06-26 17:22:09 +00:00
Jeff Vander Stoep 530dccb8c5 Update rustc to 1.44.0
Test: Treehugger
Change-Id: Ib940bc5afbbbec6b16ed7c2879ad31438e58907d
2020-06-26 15:26:49 +02:00
Thiébaud Weksteen 92f703b084 Add clippy-driver build rule
Depending on the location of the repository (e.g. external/, vendor/), a
different set of lints will be enabled. Add the clippy property to the
rust_* modules. This property can be used to overwrite the default
behaviour.

Test: m checkbuild
Bug: 157238651
Change-Id: Ife0f723ef4a74abb102597f8486a7b9f30e7d351
2020-06-26 13:31:21 +02:00
Jingwen Chen d06f11ee71 Merge "Support multiple dists per Android.bp module, and dist output selection." 2020-06-26 08:03:27 +00:00
Jeff Vander Stoep 03186ed247 Add Matt to OWNERS for Rust
Test: n/a
Change-Id: Ibecfd0edd9950a161246d9a13179d88f7e957244
2020-06-26 09:23:47 +02:00
Thiébaud Weksteen 5f2de778f4 Remove duplicate Helper call
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-25 21:25:41 +02:00
Jingwen Chen 40fd90ae52 Support multiple dists per Android.bp module, and dist output selection.
This CL adds "dists" to the base property struct to support multiple
dist file configurations, and generic tag support to dist tagged outputs
of modules.

Fixes: b/152834186
Test: soong tests and `m sdk dist`

Change-Id: I80c86bc9b7b09e671f640a4480c45d438bdd9a2a
Signed-off-by: Jingwen Chen <jingwen@google.com>
2020-06-25 12:42:07 +00:00
Thiébaud Weksteen 1f7f70fe39 Remove moduleContextImpl struct
The moduleContextImpl structure contains duplicate information on the
contexts. BaseModuleContext, ModuleContext and DepsContext can already
surface which Module is being processed via Module(). Because most of
the Rust-specific methods on the *Context structures simply forward to
the Module methods, expose a RustModule() method.

Test: cd external/rust/crates; mma
Change-Id: Ifee90825d54081fc5e9a8df0b7c4580412e9158c
2020-06-24 11:56:33 +02:00
Colin Cross c9ef6ee1b7 Merge "Make native_coverage clause work with ClangCoverage" 2020-06-23 03:06:53 +00:00
Colin Cross 1a6acd4f39 Make native_coverage clause work with ClangCoverage
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-22 11:13:42 -07:00
Treehugger Robot f649c05239 Merge "[Rust] cdylibs can now link against dylibs." 2020-06-19 20:25:47 +00:00
Ivan Lozano 7e741cca30 [Rust] cdylibs can now link against dylibs.
Bug: 144861059
Test: cd external/rust/crates; mma
Test: Manual verification through ldd that libstd is a dependency
Change-Id: I603cf519215317aa8c400cd0f6ebb1b58f5bcf15
2020-06-19 13:54:26 -04:00
Chih-hung Hsieh 80f20d14de Merge "Generate multilib for rust_test" 2020-06-17 23:07:19 +00:00
Chih-Hung Hsieh e728a89807 Generate multilib for rust_test
* Cannot generate multilib for host tests yet.

Bug: 158677299
Test: atest -c -m --include-subdirs external/rust/crates
Change-Id: I7071c1ea30865a8cf268dfe270f2a586eb7710d9
2020-06-17 13:08:00 -07:00
Ivan Lozano a4e8a640bb Merge "[Rust] Correct the gcov path prefix." 2020-06-17 18:58:52 +00:00
Ivan Lozano 796fc4c8be [Rust] Correct the gcov path prefix.
strings.TrimPrefix() args are reversed, leading to an incorrect gcov
path prefix for Rust coverage.

Bug: 156482307
Test: built and ran unicode-xid_device_tests_unicode_xid with coverage
Change-Id: I6476cee14093a7e53738019c84dbcf4333b0b9b2
2020-06-17 11:39:17 -04:00
Ivan Lozano d825990336 Merge "[Rust] Remove unused variables and deduplicate." 2020-06-17 12:28:06 +00:00
Treehugger Robot 6116ffdcf5 Merge "Don't create version variants for SDK variants" 2020-06-17 04:19:04 +00:00
Jiyong Park 2286afd0ef Don't create version variants for SDK variants
When a lib has sdk_version set, an SDK variant and a platform variant
are created by the sdkMutator. Then by the versionMutator, if the
library had 'stubs.versions' property, one or more versioned variants
and one impl variant are created for each of the two (SDK and platform)
variants. As a concrete example,

cc_library {
    name: "foo",
    sdk_version: "current",
    stubs: { versions: ["1", "2"], },
}

would create 6 variants:

1) (sdk: "", version: "")
2) (sdk: "", version: "1")
3) (sdk: "", version: "2")
4) (sdk: "sdk", version: "")
5) (sdk: "sdk", version: "1")
6) (sdk: "sdk", version: "2")

This is somewhat uncessary because the need for the SDK mutator is to
have the platform variant (sdk:"") of a lib where sdk_version is unset,
which actually makes sens for the impl variant (version:""), but not
the versioned variants (version:"1" or version:"2").

This is not only unncessary, but also causes duplicate module
definitions in the Make side when doing an unbundled build. Specifically,
The #1 and #4 above both are emitted to Make and get the same name
"foo".

To fix the problem and not to create unnecessary variants, the versioned
variants are no longer created for the sdk variant. So, foo now has
the following variants only.

1) (sdk: "", version: "") // not emitted to Make (by versionMutator)
2) (sdk: "", version: "1") // not emitted to Make (by versionMutator)
3) (sdk: "", version: "2") // emitted to Make (by versionMutator)
4) (sdk: "sdk", version: "") // not emitted to Make (by versionMutator)

Bug: 159106705
Test: Add sdk_version:"minimum" to libnativehelper in libnativehelper/Android.bp.
m SOONG_ALLOW_MISSING_DEPENDENCIES=true TARGET_BUILD_UNBUNDLED=true libnativehelper

Change-Id: I6f02f4189e5504286174ccff1642166da82d00c9
2020-06-17 04:18:21 +00:00
Ivan Lozano 8a23fa4819 [Rust] Remove unused variables and deduplicate.
Bug: 158731826
Test: cd external/rust/crates; mma
Change-Id: I8c9e5cfeaf941b9676b92451b227c15db9a41bbc
2020-06-16 10:28:25 -04:00
Roland Levillain 2752d926a9 Merge "Rename native code coverage paths product variables in Soong." 2020-06-15 10:12:10 +00:00
Ivan Lozano f094f1c313 Merge "Match Rust gcda output to cc via -Z profile-emit." 2020-06-12 16:12:48 +00:00
Ivan Lozano 1a1d28888c Merge "Make rust_test file output more similar to cc_test." 2020-06-12 16:12:28 +00:00
Colin Cross 440e0d0542 Use inclusive language in build/soong
Test: m checkbuild
Change-Id: Id07890b7cbc2397291a658ca00e86b43c743aafc
2020-06-11 15:33:16 -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
Ivan Lozano f3717eec6c Match Rust gcda output to cc via -Z profile-emit.
Use the -Z profile-emit flag to ensure that rust gcda files have
/proc/self/cwd/ appended to them similar to cc modules. This makes sure
our gcda output is consistent no matter what language the binary is
written in.

Bug: 156482307
Test: gcda outputs to the new path.

Change-Id: Ife4d55f885c7e33dffa66f7436bc2bf8b5916586
2020-06-11 17:16:27 +00:00
Thiébaud Weksteen a2e3a6312b Merge "Add rust-project.json generator" 2020-06-11 16:01:07 +00: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
Colin Cross a6384821f9 Fix using generated test configs for sh_test, python_test and rust_test modules
Annotate the test config properties with android:"path", and always
use LOCAL_FULL_TEST_CONFIG to pass the path to Make.

Bug: 157621988
Test: manual
Change-Id: I1c020e642f83d994d63c9e9cb56e686086d5acaa
2020-06-10 22:48:16 -07:00
Roland Levillain 4f5297b438 Rename native code coverage paths product variables in Soong.
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-06-10 13:00:07 +01:00
Ivan Lozano bec05ea26d Specify SONAME when building Rust shared libs.
Without specifying -soname, cc binaries are unable to locate Rust
provided shared libraries. This adds the -soname linker flag for shared
libraries.

Bug: 158490355
Test: readelf -d <cc_binary> shows the expected SONAME
Change-Id: I66852a7ce24d5ea5e426f11bc1834fb56a150628
2020-06-09 08:40:24 -04:00
Jaewoong Jung 4b79e98a6e Soong package structure refactoring
Give prebuilt_etc and sh_binary their own packages and split the
gigantic main Android.bp up to small, per-package ones.

Test: m nothing, TreeHugger
Bug: 156980228
Change-Id: I7b00cd344b9f16861f1ff39edf0029f016b853d0
2020-06-01 13:44:48 -07:00
Ivan Lozano c0ccb6b443 Fix darwin shared library and proc macro suffixes.
Darwin builds aren't using the correct suffix for shared libraries or
proc macros (.dylib). This fixes that.

Bug: 155302034
Test: "cd external/rust; mma" no longer indicates wrong extension.
Change-Id: I5093e0bcc78dbb2dd9fcf39069f326101bb8f411
2020-05-29 13:08:27 +00:00
Ivan Lozano 6c4e5c05c3 Merge "Add gcov coverage support to Rust modules." 2020-05-07 17:56:43 +00:00
Matthew Maurer e7fe2527f6 Merge "Switch rustc to 1.43.0" 2020-05-05 16:43:47 +00: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
Matthew Maurer f5be9a6ad4 Switch rustc to 1.43.0
Bug: 154947284
Test: cd external/rust/crates; mm
Change-Id: I684e9ee5d44029806d48a271970f8ef28e793195
2020-04-29 13:33:40 -07:00
Ivan Lozano f900f4b848 Test for rust install path regressions.
Bug: 153423714
Test: Soong tests pass.
Change-Id: Ica4d2c7e47f1c325fa387a91f6c476dfa4f93710
2020-04-29 15:31:42 -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