Commit Graph

8 Commits

Author SHA1 Message Date
Chih-Hung Hsieh
e02dce1683 Add EXCLUDED_CRATES and better default names
* protobuf_bin_gen_rust_do_not_use is in EXCLUDED_CRATES
* build_default_name returns a short and readable name
  for a rust_defaults module, from the following choices:
    (1) root_pkg + '_defaults',
    (2) root_pkg + '_defaults_' + crate_name
    (3) root_pkg + '_defaults_' + main_src_basename_path
    (4) root_pkg + '_defaults_' + a_positive_sequence_number

Test: regen external/rust/crates/*/Android.bp
Change-Id: I6aa16a8a6c7ea05744a31a9d4ff0c4524ef91fea
2020-07-14 18:50:15 -07:00
Chih-Hung Hsieh
3725e085ec More options and rename maps; one file per rust_test
* Add a --no-host option.
* Add a --host-first-multilib option.
* Add special renaming for protoc_gen_rust.
* Dump a rust_defaults module to be shared by rust_test modules.
  * Every test source file is in a rust_test module.
  * Add RENAME_DEFAULTS_MAP for altered rust_defaults names.
* Suppress old error message on --extern proc_macro.

Test: regenerate Android.bp files and check differences
Bug: 161090277
Bug: 161089524
Change-Id: I8c70f568facf58d282ea2a2e72b60c8a2972b27d
2020-07-12 23:06:57 -07:00
Chih-Hung Hsieh
35ca4bcf21 Use rustlibs and not deny_warnings.
* The old deny_warnings is replaced with a comment to remind the users.

Test: regenerate Android.bp files and check differences
Bug: 161001041
Bug: 161001220
Change-Id: I96c43cff83edcb7b50e6beee972c9157d20c8dc9
2020-07-10 17:40:36 -07:00
Andrew Walbran
80e90be1b7 Include command-line arguments in comment.
This makes it clear exactly how a build file was generated and how to
reproduce it.

Bug: 158290206
Change-Id: Icf28a66bf0da708a3fcd0fe3d49893191fb1a8f1
2020-06-09 14:33:39 +01:00
Chih-Hung Hsieh
185052a369 Ensure unique name for non-merged modules.
* Do not emit relative_install_path;
  use default unique module name.
* Copy errors in cargo output to Android.bp.
  Some Rust packages are incomplete at crates.io
  and fail to run through cargo test.
* Apply pyformat.

Bug: 156014698
Test: in external/rust/crates/*, cargo2android.py --run --tests
Change-Id: Ide77ca34e47048a8bc03b18eebbe92fb17666784
2020-05-08 12:31:04 -07:00
Chih-Hung Hsieh
8a1a2300ed Accept multiple --crate-type and fix for new cargo.
* Change crate_type string to crate_types list.
  In dump_android_module, iterate over crate_types and
  call dump_one_android_module for each crate type.
* In decide_one_module_type, add mapping of Rust crate types:
        lib => rlib         (no change)
        rlib => rlib        (new)
        dylib => dylib      (new)
        cdylib => shared    (changed)
        staticlib => static (new)
  Maybe we should change and map 'lib' to 'lib',
  but before that, crate_types should not contain
  both 'lib' and 'rlib'.
* Accept new cargo output format, which can
  call rustc with the main source file name after
  other flags, not always after the "--crate-name" flag.
* Work around duplicated test module name problem;
  call self.runner.claim_module_name for every named test module.

Bug: 153118477
Test: fetch quiche-0.3.0, bindgen-0.53.2 and other Rust crates
Test: cargo2android.py --run --vv --device --tests
Change-Id: Id65c3929b5c593df73f26f1510ad7e89194b209e
2020-04-07 10:49:08 -07:00
Chih-Hung Hsieh
6c8d52f6eb Pass --no-default-features to cargo build
* When --features is specified,
  pass --no-default-features to cargo.
* When a dependent Rust package is imported to AOSP,
  if not all "default" features are needed, run
  cargo2android.py with empty or a list of specific features.

Test: cargo2android.py --run # use default features
Test: cargo2android.py --run --features=''  # no default
Test: cargo2android.py --run --features='default,std'
Change-Id: I854f1ecb7d7466490ff34e229ec14a07c1273c6d
2020-03-31 10:08:06 -07:00
Chih-Hung Hsieh
e888737544 A script to run cargo and generate Android.bp.
* Usage note and help for command flags in the script.
  * Run cargo -v multiple times and collect output in cargo.out.
  * Use target.tmp as temporary working directory.
  * Generate multiple Android.bp files into subdirectories.
  * Simplified package names, without version number.
* Merged Android.bp modules.
  * Use --device flag to generate both host and device build targets
    in a combined module.
  * Use --tests flag to generate rust_test modules, with auto_gen_config,
    and multiple unit tests merged in one module.
* Generate cc_library_static modules for rust packages that call
  'cc' and 'ar' to build static C/C++ libraries.
  * Use the --vv flag to call cargo with -vv.
* Limitations:
  * Cargo.toml and its build scripts might need fix for Android first.
  * Depending on user given cargo parameters.
* TODOs:
  * Handle multiple crate types in one rustc command line.
  * Smart merge of host and device rust_test modules,
    to handle device tests that depend on dynamic libraries.
  * Handle special Rust packages that use only build scripts
    and C/C++ compilers to generate included files.

Bug: 142209566
Test: In rust project directories: cargo2android.py --run
Change-Id: Id54652b1e0a6e5fc16619cd05f5b057eee79d610
2019-12-02 15:43:04 -08:00