From 6c8d52f6ebdd68a856f241c2effcb878d6b9198c Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Mon, 30 Mar 2020 18:28:52 -0700 Subject: [PATCH] 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 --- scripts/cargo2android.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index c88536e5f..9f3dd575a 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -876,8 +876,11 @@ class Runner(object): cmd_tail = ' --target-dir ' + TARGET_TMP + ' >> cargo.out 2>&1' for c in self.cargo: features = '' - if self.args.features and c != 'clean': - features = ' --features ' + self.args.features + if c != 'clean': + if self.args.features is not None: + features = ' --no-default-features' + if self.args.features: + features += ' --features ' + self.args.features cmd = 'cargo -vv ' if self.args.vv else 'cargo -v ' cmd += c + features + cmd_tail if self.args.rustflags and c != 'clean': @@ -1076,7 +1079,9 @@ def parse_args(): default=False, help='run cargo also for a default device target') parser.add_argument( - '--features', type=str, help='passing features to cargo build') + '--features', type=str, + help=('pass features to cargo build, ' + + 'empty string means no default features')) parser.add_argument( '--onefile', action='store_true',