Commit Graph

103 Commits

Author SHA1 Message Date
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