Commit Graph

111 Commits

Author SHA1 Message Date
Matthew Maurer
4b869316ee cargo2android.py: Default to vendor + product
This is used for managing 3p crates, and the vast majority of them
should be available to both vendor and product. Enable support by
default.

Bug: 270690570
Test: Regenerate external/rust/crates/*
Change-Id: Ie5cb4b8d00de5e6ae37c5a69cb2ee0c0cc6f573a
2023-03-06 22:55:36 +00:00
Treehugger Robot
66f9ab6962 Merge "Extend cargo2android.py version matching to include alpha and beta crates" 2023-02-03 22:01:40 +00:00
Colin Cross
602c2483a5 Extend cargo2android.py version matching to include alpha and beta crates
The ring crate hasn't had a non-alpha release in over two years, and
may need to be updated to an alpha release.  Modify the version regex
in cargo2android.py to recognize the alpha version as part of the
version suffix.

Test: manually run cargo2android.py in redshell
Change-Id: If48d5be339d10bc3e6651485b0038b7219403077
2023-02-03 12:39:51 -08:00
Jeff Vander Stoep
b06dd5c7e2 c2a: make Rust version matchin regex less exact
Allow custom version like 1.65.0.p1 (added in aosp/2404317).

Resolves warning:
WARNING: cannot find RustDefaultVersion in
development/scripts/../../build/soong/rust/config/global.go
Change-Id: I6fced7695473e025b0f739f9986df932d2c3f5fe

Test: cargo2android.py --config cargo2android.py
no warning

Change-Id: I43ff81f061477fc0322f27fef1c950954130dbc6
2023-02-01 14:23:40 +01:00
Chris Wailes
13b1ca483d Add a rename mapping for libatomic to libatomic_rust
Bug: 229895468
Test: cargo2andoid.py --config cargo2android.json
Change-Id: Icf542d1398f9cd378bba845445b2dab34bb0b317
2023-01-24 16:31:14 -08:00
Shuo Wang Hsu
be3f0d9d11 Support building crate variants.
The cargo2android.json config file now supports the key "variants" with
a list of entries containing keys and build name suffix. Each entry
will produce a different library (or binary). Keys supplied for each
variant will overwrite any existing ones specified in the config file.

See an example of the protobuf crate on aosp/2368788.

Test: None
Change-Id: Iaca67c7f22718c27b3cb118d9794f1ff01d31c84
2022-12-28 15:39:42 -08:00
Matthew Maurer
b59698e2e9 c2a: Legacy cleanup
* Removed import of print function - we only support py3 now
* Switched from set() to a set literal

Bug: None
Test: Regenerated argh_derive
Change-Id: I78bc86ad22c747c5f6ad88e2caa5e707e1ffc381
2022-09-12 13:03:32 -07:00
Matthew Maurer
ae5da710b3 c2a: Parse new cargo output
Cargo now outputs
'unittests src/lib.rs'
where before it output
'unittests'.

Bug: 246384761
Test: Add "test": true to argh_derive, regenerate, observe same bp file
Change-Id: Ieeab83761f5fe7cff88af1ce8293818736a6bb9b
2022-09-12 12:55:47 -07:00
Pierre-Clément Tosi
fd12b5feed c2a: Clean-up no-ops with 'pass'
Bug: 243662244
Test: -
Change-Id: Ib62b19c18da7e3a44c74303a72a9c27f9d8b3315
2022-08-24 17:41:08 +01:00
Pierre-Clément Tosi
e5342d134a c2a: Crate: Don't parse -Wclippy, -D, and -W flags
Don't fail the generation of the Android.bp file when those flags are
encountered.

Bug: 243662244
Test: Used on gdbstub, which fixed issues seen in aosp/2191020
Change-Id: I80a6ecd8df7980234552a98ddb1149dc29542ac7
2022-08-24 17:41:08 +01:00
Pierre-Clément Tosi
435dfe58d1 c2a: Crate: Parse unquoted rustc args
Prevent the script from missing flags (minus-prefixed arguments) due to
the CLI argument being quoted (making the "-" its second character).

This removes the need to manually unquote the args in the few cases
where the code already handles them being in quotes.

Bug: 243662244
Test: -
Change-Id: I37b9aa96dcbbeb04616bddfca657d066b998d7c7
2022-08-24 17:40:23 +01:00
Pierre-Clément Tosi
dde806f72d c2a: Extend unquote() to single quotes
Bug: 243662244
Test: -
Change-Id: I4de409b3135369425f8fa934f490e701505cd55d
2022-08-24 16:36:34 +01:00
Frederick Mayle
9f0dd71b8a cargo2android: fix test detection when there is exactly 1 test
Example where it failed:

    tests::sock_send_recv_event: test

    1 test, 0 benchmarks
       Doc-tests vm_control
    0 tests, 0 benchmarks

the "1 test, 0 benchmarks" line wouldn't match the test regex, so it
would mistakenly parse the doc tests line instead and then fail to
generate a rust_test module.

Test: ran on crosvm repo

Change-Id: Id0286165405b58bf84b7261db842e272442c91e8
2022-08-17 20:36:45 +00:00
Matthew Maurer
b1d8a2de5f Merge changes I4c3744e0,I91d8de92
* changes:
  c2a: Our cargo works again, re-enable defaulting.
  c2a: Fix rust_version calculation
2022-08-17 16:08:32 +00:00
Frederick Mayle
71722b10e5 cargo2android: Fix edge case in --add_workspace feature
If the last line of a Cargo.toml was a `[*]`, then appending
`[workspace]` without newlines would result in an invalid toml file.

external/crosvm/tracing/Cargo.toml is an example.

Test: ran on crosvm
Change-Id: Ib949e7f92d0205b1bc6433d1e231924832ddb536
2022-07-27 00:13:52 +00:00
Jeffrey Vander Stoep
3a293c7bba Merge "Revert "c2a: add option to use Cargo.toml.orig"" 2022-07-07 08:24:42 +00:00
Jeffrey Vander Stoep
6529bcaf6a Revert "c2a: add option to use Cargo.toml.orig"
This reverts commit 2adbd7ed89.

Reason for revert: This doesn't work in all cases. For now I'll
instead use local patches for Cargo.toml :(

Change-Id: I0621796e694e2654a01fe9a38a307fd0a4ab8b15
2022-07-06 12:34:37 +00:00
Treehugger Robot
1da99cc99e Merge "c2a: add option to use Cargo.toml.orig" 2022-06-23 15:34:41 +00:00
Jeff Vander Stoep
2adbd7ed89 c2a: add option to use Cargo.toml.orig
`Cargo --publish` strips dev-dependencies from Cargo.toml, an issue
that won't be fixed until [1] is resolved, which doesn't seem
likely as it has been open for ~5 years now.

cargo2android needs dev-dependencies listed in Cargo.toml in order
to generate the rust_test in Android.bp, add an option that tells
cargo2android to use the cargo.toml.orig instead of the cargo.toml.

With this change there are now two options that temporarily
update Cargo.toml, so I've pulled these out into a separate class
to clean up the code a bit.

[1] https://github.com/rust-lang/cargo/issues/4242

Test: run against projects with --add_workspace and
--orig-cargo-toml

Change-Id: I3b8633a807c9734981ebde0bef9b73868acf6774
2022-06-23 16:38:08 +02:00
Matthew Maurer
ce53b80d81 c2a: Our cargo works again, re-enable defaulting.
Bug: 234744235
Test: Run cargo2android.py without --cargo_bin
Test: Run in the sandbox without providing --cargo_bin
Change-Id: I4c3744e0e391ab7e4fb6a857483fde5c0015f0ff
2022-06-16 13:53:26 -07:00
Matthew Maurer
1231af292c c2a: Fix rust_version calculation
string-typed result groups would cause the comparison to fail with a
type error. Explicitly casting results to integer for comparison, then
back to string for concatenation causes things to work again.

Bug: 234744235
Test: Run tool with no --cargo_bin option (and the following patch)
(thus using local cargo version detection) and observe success.

Change-Id: I91d8de925c1b6eca7c9905ea85e1ad90e01fb1f9
2022-06-16 13:53:21 -07:00
Matthew Maurer
a9fb65d155 c2a: Automatically make crates APEX available
The bulk of Rust packages in external/ are OS agnostic and do not care
about individual platform features. This change is intended to reduce
the churn of repeatedly adding new `apex_available` attributes to crates
by defaulting to availability. When landing a new crate which is either
platform revision specific or has an unstable file format, prefer to
set `apex_available: ["//apex_available:platform"]` until you have
thought things through.

Bug: 174862583
Test: Regenerate with no apex_available, see universal availability
Test: Regenerate with apex_available: [], see []
Test: Regenerate with apex_available: [foo], see [foo]
Change-Id: I958597789bfc966caec043d051996284dab7a927
2022-06-16 13:07:12 -07:00
Thiébaud Weksteen
d5d033979f Require cargo_bin option
The prebuilt cargo (or more precisely, its libstd) cannot be used when
running cargo2android.py. Ensure that the upstream cargo binary is used.
This is automatically set when using the sandbox for Googlers. For
external contributors, raise an error if the option is not provided.

Test: As a googler, execute cargo2android.py directly; an error is
    raised.
Test: As a googler, use the sandbox; cargo2android.py is executed
    correctly.
Test: As an external contributor, execute cargo2android.py; an error is
    raised if cargo_bin is not provided.
Bug: 217810523
Change-Id: Id42ba777b3960b13f6ef91d36eaad94df939f48e
2022-02-09 11:25:15 +11:00
Andrew Walbran
ca9f9f2266 Add --no-presubmit option to prevent host tests being run in presubmit.
For some unknown reason the change to merge rust_test and rust_test_host
targets caused some crosvm tests to be run (and fail) in prebsubmit which
were not previously being run, so this is necessary to work around it.

Test: Ran cargo2android.py on various crosvm crates.
Change-Id: I9b94d270148d8ce5fa97f88f460d8c03eac3873c
2022-01-10 16:02:53 +00:00
Andrew Walbran
0e65bba93d Ignore clippy configuration flags.
Test: Ran ./all2android.sh under external/crosvm
Change-Id: I29a50ee242bca5111004b6ba56867b1e68ccd8f3
2022-01-07 15:12:00 +00:00
Andrew Walbran
a32a04851b Don't try to remove Cargo.lock if it doesn't exist.
Change-Id: Ibfad6d97988edb6305d7a237d038412ec5a6100f
2022-01-06 14:03:50 +00:00
Joel Galenson
54d655345d Stop generating separate rust_test_host.
With b/196306316 hopefully fixed, we should be able to use a single
rust_test entry for both device and host tests.  This modifies
cargo2android.py so it generates these shared tests.

Test: Run on crates with simple tests, those with defaults, host-only,
and device-only tests.

Change-Id: Icfe8d1fb26a61bc9ed65b8a7b116a4ebcd782ce4
2021-12-06 16:17:06 -08:00
Joel Galenson
d4b099d3fa Merge changes If5292d1d,Ib1a86d48
* changes:
  Stop cargo2android.py from printing the --cargo_bin argument.
  Revert "Enable LTO in cargo2android.py."
2021-12-02 14:46:56 +00:00
Joel Galenson
56b5f4be29 Comment out errors encountered when running cargo test.
A recent change to remove empty tests runs cargo test --list.  A few
crates produce build errors this way that they did not previously do.
This currently causes cargo2android.py to produce illegal Android.bp
files for these crates even though these should not be fatal errors.
We thus detect these errors and emit them as comments in the
Android.bp file, so developers can see them but the crate can still
compile.

Test: Run on crates with and without such errors.
Change-Id: I8664d3ca9a6b4c513ce0ef35821aa64d22949fc7
2021-11-30 10:34:14 -08:00
Joel Galenson
769c3c373f Stop cargo2android.py from printing the --cargo_bin argument.
cargo2android.py prints out all of its arguments to the top of the
Android.bp file (and into a config file if that option was set) as a
way of persisting them.  However, we do not want to persist the
--cargo_bin directory, as this is a proprety of the local setup and
not the crate itself.  Thus ensure we don't print this.

Test: Run with argument.
Change-Id: If5292d1d740b08755ba6d31654239e93232fdc49
2021-11-24 15:10:02 -08:00
Joel Galenson
903a0f8cb1 Revert "Enable LTO in cargo2android.py."
This reverts commit 4f4ac2f8f3.

This did not work for all crates (specifically, those with build.rs,
as they don't get passed RUSTFLAGS, as well as proc-macros, since they
get the flag but can't use LTO), so we're using a different approach
where this is not desired.

Test: Run script
Change-Id: Ib1a86d4822f51978cd8ec15ad657eb25c84e01a4
2021-11-24 15:09:45 -08:00
Joel Galenson
4f4ac2f8f3 Enable LTO in cargo2android.py.
The latest compiler roll also enabled LTO.  This broke
cargo2android.py, as the test prebuit uses LTO and so cannot be linked
with code built without.  We fix this by enabling it in
cargo2android.py (and ensuring it doesn't add the flag into
Android.bp).

Test: Run
Change-Id: I6c6a813ff58a9e5064752aa59b78247c4af77a26
2021-11-22 15:22:45 -08:00
Joel Galenson
0038349332 Merge "Document the expectations of two arguments." 2021-10-25 16:45:04 +00:00
Joel Galenson
493c26a8d4 Document the expectations of two arguments.
To work with the updater, these files must have a certain prefix.

Test: Run with --help and upgrade a crate.
Change-Id: Icdc492479223865c39d6c6f10b84fe3d762f5d1d
2021-10-18 15:54:41 -07:00
Joel Galenson
7cfc6fe5de Do not generate empty Rust tests.
cargo2android.py currently builds whatever cargo does, which includes
empty tests.  We can filter those out by parsing the output of "cargo
test" and looking for things with no tests.

Fixes: 159039990
Test: Run on a crate with empty integration tests, one with empty unit
tests, and one with no empty tests.

Change-Id: If8b1126d82ce6c2851b90de738ea24b129b81feb
2021-10-15 13:35:41 -07:00
Joel Galenson
f78de4f942 Merge "Do not generate cargo_pkg_version when --no-pkg-vers is passed" 2021-10-08 21:12:41 +00:00
Joel Galenson
308f3521dd Handle versions of the form -a.b.c+foo.
Previously we would keep the +x.y.z part, which caused errors in Soong.

See the diff between the first two patchsets in aosp/1833319 for an
example.

Test: Fix the above CL and run on a crate without a +.
Change-Id: I791c85545e67b54e2c8952428211688e7bbf580d
2021-10-01 15:19:45 -07:00
Joel Galenson
94b8a8d40c Do not generate cargo_pkg_version when --no-pkg-vers is passed
If you passed --no-pkg-vers to cargo2android.py, it would still
generate cargo_pkg_version with an empty string.  Instead, simply
don't generate anything.

Test: Use with and without argument.
Change-Id: I544e4789312ccc3481da73c78f0f2cae2ad6619c
2021-09-28 11:53:51 -07:00
Jason Macnak
7b3f02465b Merge "Suffix libash with _rust to avoid name conflict" 2021-09-08 16:43:34 +00:00
Jason Macnak
051340de9e Suffix libash with _rust to avoid name conflict
Bug: b/189133061
Test: presubmit with attached topic
Change-Id: I6619857a7f632fe7ab0576dd0dd0fe4dacf677b1
2021-09-04 11:04:26 -07:00
Joel Galenson
b06c42a03c Generate cargo_pkg_version and cargo_env_compat for defaults.
The existing code only adds it to things without defaults.  This adds
it to the defaults module itself, which should not overlap the
existing code.

Test: Run and see new entries.
Change-Id: Iaf3d0b47193bb1f54cdc605c88c2cd68034d963a
2021-08-31 14:28:48 -07:00
Joel Galenson
c3bfaf8a1e Fully remove deprecated --no-test-mapping argument.
This argument has already been deprecated, but now there should be no
more uses of it.  Let's remove it and the remaining logic.

Test: Run the updater.
Change-Id: I8ab6f6fadba3b462567237d18ddc02cc4c22e62f
2021-08-18 09:39:36 -07:00
Joel Galenson
a4648dfcba Merge "Do not dump the --config argument." 2021-08-18 15:04:38 +00:00
Joel Galenson
9a82ad9d47 Do not dump the --config argument.
When generating a config file from a commandline, cargo2android.py
should not dump the --config argument, as the point of the dump is to
generate a config file to use.  This would not normally matter, but it
could help in scripts.

Test: Run and do not see --config in the dumped file.
Change-Id: Idc2911ba674e67272c9cf836c89607e10ca0dddd
2021-08-17 17:52:04 -07:00
Matthew Maurer
70182e44f0 cargo2android: Don't emit image support for tests
Image support doesn't make sense for test modules.

Bug: 178565008
Test: Generate rustc-demangle-capi
Change-Id: Ie5a1d85f9828e0c105c3a3e994b22ef7664fe1db
2021-08-17 15:36:38 -07:00
Matthew Maurer
062709c3b3 cargo2android: Support exported C headers
staticlib and cdylib crate types generally want to export header files
for use by C code. Allow the location of these headers to be provided to
c2a for inclusion in blueprint.

Bug: 178565008
Test: Generate rustc-demangle-capi
Change-Id: I0aa9acfb081ea39a7e13315bfc8029d06b8f55d3
2021-08-17 15:06:34 -07:00
Matthew Maurer
9e4b781de9 cargo2android: Emit apex_available + min_sdk_version for native libs
Previously, we only emitted apex_available + min_sdk_version for 'lib'
type crates. That ignored:
* Explicit rlib
* Explicit dylib
* cdylib
* staticlib

Bug: 178565008
Test: Generated Android.bp for rustc-demangle-capi
Change-Id: I19f0abe385b9c13ac731b7f2c978052ffa6b92f7
2021-08-17 15:06:34 -07:00
Matthew Maurer
ac67725422 cargo2android: Add support for various image types
Test: Generated rustc-demangle's Android.bp with it
Bug: 178565008
Change-Id: I0877e2d7d9e309105610b4d87f2a6d45ef67903f
2021-08-17 15:06:34 -07:00
Joel Galenson
833848cea6 Deprecate the --dependencies argument.
We no longer use the --dependencies argument, but it is still used in
a number of places.  Let's remove its functionality but keep the
command-line option as a no-op so we can remove the uses over time.

Test: Run on crate that uses the option.
Change-Id: I954f68faf11d1a926f0ccf070afa8332385e3671
2021-08-17 10:50:42 -07:00
Joel Galenson
69ba807921 Improve package version logic
Only run cargo metadata on the main crate, not all of its dependencies.

Pass it the --format-version argument to avoid a warning and be
future-proof.

Test: Run.
Change-Id: Icdf88bc3b633d18266772ae813fc04b529b95765
2021-08-16 11:31:29 -07:00