Commit Graph

124 Commits

Author SHA1 Message Date
Jeongik Cha
a18bd3c1ca Set <partition>_available only if it is for device
it is meaningful only if it is installed in the device

Bug: 277909042
Test: cargo2android.py with/without device, and then check
product/vendor_available

Change-Id: I9ca7328ac953849db224949089412e181b659945
2023-09-27 02:28:55 +09:00
Jeongik Cha
3151ae84ef Fix the order of suffix in Android.bp
rust_library + host_suffix + rlib_suffix is the right order
For example, rust_library_host_dylib, rust_library_host_rlib

Bug: 277909042
Test: cargo2android --run --force-rlib
Change-Id: Ib156b96853eb51bae1f68229ebe76b87b0f8b363
2023-09-18 20:00:58 +09:00
James Farrell
56475b17c5 Support adding suffixes to module names and deps.
This is helpful for crates like protobuf and syn for which we have
multiple versions, and will let us eliminate several patch files

Test: Ran it on everything in external/rust/crates.
Change-Id: I29ac1ee69be99b7164e1458e0d8fc1cb028b15a0
2023-09-13 18:00:42 +00:00
James Farrell
a5c22d559c Add some type annotations, mainly to help the IDE.
No functional changes.

Test: Ran it.
Change-Id: Ifedf1c42628dae03968eeefd5101ae75456acd32
2023-09-12 21:14:33 +00:00
Martin Geisler
6f634869e6 Merge "Revert "Rename libsyn to libsyn2"" into main 2023-09-07 14:01:47 +00:00
Martin Geisler
a6fe26c146 Revert "Rename libsyn to libsyn2"
This reverts commit 7705ea6d36.

Reason for revert: I believe this is stale since `libsyn` is version 2 now:

https://cs.android.com/android/platform/superproject/+/main:external/rust/crates/syn/Android.bp;l=41;drc=fcd71dcc29ef325341ea7c1a145591b349018eb3

Change-Id: I31892447cf95d094e4bb201c4d86a28c70085467
2023-09-01 14:08:46 +00:00
Treehugger Robot
8449944a50 Merge "Rename libsyn to libsyn2" into main 2023-08-16 17:10:05 +00:00
Sim Sun
ecff5ddc84 c2a: Support customizing rustc
The current cargo2android.py doesn't work well w/ `--cargo_bin`. It would use the full path rustc(/<HOME>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc) instead of basename(`rustc`). The `RUSTC_PAT` and `RUSTC_VV_CMD_ARGS` regex doesn't match the full path.

This CL uses `(.*\/)?` to match the path if it exists.

Change-Id: If5e4060410c1cd45ad6c9612ebe856552aa14d08
2023-06-21 14:08:38 -07:00
Andrew Walbran
90bfd75d6b Support Python 3.8.10.
Redshell unfortunately uses this old version, while the union operator
for dictionaries was only added in Python 3.9.

Test: Ran cargo2android.py on a crate with variants
Change-Id: I7a875acde11c23a3b789ef384f3ab32100d7c6d5
2023-06-13 13:06:26 +00:00
Matthew Maurer
7705ea6d36 Rename libsyn to libsyn2
A downstream project has an invalid branching structure, so we can't
actually rename `libsyn` to `libsyn-legacy` like we normally would.
Instead, we must allow the legacy package to squat on the `libsyn` name
until the branching structure is fixed to unblock the upgrade to
syn-2.x.

Test: TreeHugger
Bug: 276463929
Bug: 278978404
Change-Id: If72d389dd5238299cc1b35818e0b5596b0469cb1
2023-05-22 21:21:02 +00:00
Andrew Walbran
59f441224e Add --dependency-suffix flag.
This adds a suffix to all dependencies, which may be useful for no_std
crates.

Bug: 279614907
Test: Ran on external/rust/crates/ciborium
Change-Id: I4d504fbfdcd079a946814dcf953b42baa0ca3563
2023-05-12 16:47:19 +00:00
Andrew Walbran
aff9481608 Fix handling of tests for variants.
Variant test and cargo flags were being ignored.

Bug: 279614907
Test: Ran on external/rust/crates/serde
Change-Id: I9c6cf71c8d04944cc7c532cfb53b50c2efc3e375
2023-05-12 13:24:37 +00:00
Andrew Walbran
d579a0fa61 Added --no-std and --alloc flags.
These allow most no_std crates to be supported without extra patches.

Bug: 279614907
Test: Ran on external/rust/crates/half
Change-Id: I1a69ff7950fb63320ef7c87d6cd45b20915df801
2023-05-12 13:22:55 +00:00
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