From 903a0f8cb12a21ebcac491066f3bd40d893b6998 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Wed, 24 Nov 2021 11:09:36 -0800 Subject: [PATCH 1/2] Revert "Enable LTO in cargo2android.py." This reverts commit 4f4ac2f8f309db10c7ccc4c8e4e8979fc803b249. 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 --- scripts/cargo2android.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index ebee1e906..7b7a9a587 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -352,14 +352,12 @@ class Crate(object): # 'prefer-dynamic' does not work with common flag -C lto # 'embed-bitcode' is ignored; we might control LTO with other .bp flag # 'codegen-units' is set in Android global config or by default - # 'lto' is used in Android, but it's set by the build system if not (flag.startswith('codegen-units=') or flag.startswith('debuginfo=') or flag.startswith('embed-bitcode=') or flag.startswith('extra-filename=') or flag.startswith('incremental=') or flag.startswith('metadata=') or - flag.startswith('lto=') or flag == 'prefer-dynamic'): self.codegens.append(flag) @@ -1344,9 +1342,6 @@ class Runner(object): # set up search PATH for cargo to find the correct rustc saved_path = os.environ['PATH'] os.environ['PATH'] = os.path.dirname(self.cargo_path) + ':' + saved_path - # We need to enable lto since our test prebuilts use it - saved_rustflags = os.environ.get('RUSTFLAGS', '') - os.environ['RUSTFLAGS'] = '-C lto=thin -C embed-bitcode=yes ' + saved_rustflags # Add [workspace] to Cargo.toml if it is not there. added_workspace = False if self.args.add_workspace: @@ -1372,7 +1367,7 @@ class Runner(object): cmd = self.cargo_path + cmd_v_flag cmd += c + features + cmd_tail_target + cmd_tail_redir if self.args.rustflags and c != 'clean': - cmd = 'RUSTFLAGS="' + os.environ['RUSTFLAGS'] + ' ' + self.args.rustflags + '" ' + cmd + cmd = 'RUSTFLAGS="' + self.args.rustflags + '" ' + cmd self.run_cmd(cmd, cargo_out) if self.args.tests: cmd = self.cargo_path + ' test' + features + cmd_tail_target + ' -- --list' + cmd_tail_redir @@ -1383,7 +1378,6 @@ class Runner(object): if self.args.verbose: print('### INFO: restored original Cargo.toml') os.environ['PATH'] = saved_path - os.environ['RUSTFLAGS'] = saved_rustflags if not self.dry_run: if not had_cargo_lock: # restore to no Cargo.lock state os.remove(cargo_lock) From 769c3c373f6326508dc5b4c8372159cc16fe0e63 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Wed, 24 Nov 2021 15:04:29 -0800 Subject: [PATCH 2/2] 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 --- scripts/cargo2android.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index 7b7a9a587..f363b1ed7 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -1278,7 +1278,11 @@ class Runner(object): self.bp_files.add(name) license_section = self.read_license(name) with open(name, 'w') as outf: - outf.write(ANDROID_BP_HEADER.format(args=' '.join(sys.argv[1:]))) + print_args = sys.argv[1:].copy() + if '--cargo_bin' in print_args: + index = print_args.index('--cargo_bin') + del print_args[index:index+2] + outf.write(ANDROID_BP_HEADER.format(args=' '.join(print_args))) outf.write('\n') outf.write(license_section) outf.write('\n') @@ -1842,7 +1846,7 @@ def dump_config(parser, args): non_default_args = {} for arg in args_dict: if (args_dict[arg] != parser.get_default(arg) and arg != 'dump_config_and_exit' - and arg != 'config'): + and arg != 'config' and arg != 'cargo_bin'): non_default_args[arg.replace('_', '-')] = args_dict[arg] # Write to the specified file. with open(args.dump_config_and_exit, 'w') as f: