Added --no-std and --alloc flags.

These allow most no_std crates to be supported without extra patches.

Bug: 279614907
Test: Ran on external/rust/crates/half
Change-Id: I1a69ff7950fb63320ef7c87d6cd45b20915df801
This commit is contained in:
Andrew Walbran
2023-05-11 15:57:36 +00:00
parent 9af4718984
commit d579a0fa61

View File

@@ -734,6 +734,15 @@ class Crate(object):
self.write(' "%s",' % apex)
self.write(' ],')
if crate_type != 'test':
if self.runner.variant_args.no_std:
self.write(' prefer_rlib: true,')
self.write(' no_stdlibs: true,')
self.write(' stdlibs: [')
if self.runner.variant_args.alloc:
self.write(' "liballoc.rust_sysroot",')
self.write(' "libcompiler_builtins.rust_sysroot",')
self.write(' "libcore.rust_sysroot",')
self.write(' ],')
if self.runner.variant_args.native_bridge_supported:
self.write(' native_bridge_supported: true,')
if self.runner.variant_args.product_available:
@@ -1852,6 +1861,16 @@ def get_parser():
type=str,
help=('Add the contents of the given file to the main module. '+
'The filename should start with cargo2android to work with the updater.'))
parser.add_argument(
'--no-std',
action='store_true',
default=False,
help='Don\'t link against std.')
parser.add_argument(
'--alloc',
action='store_true',
default=False,
help='Link against alloc. Only valid if --no-std is also passed.')
parser.add_argument(
'--verbose',
action='store_true',