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
This commit is contained in:
@@ -352,12 +352,14 @@ 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)
|
||||
|
||||
@@ -1342,6 +1344,9 @@ 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:
|
||||
@@ -1367,7 +1372,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="' + self.args.rustflags + '" ' + cmd
|
||||
cmd = 'RUSTFLAGS="' + os.environ['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
|
||||
@@ -1378,6 +1383,7 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user