From f29ca58e88c5846bbe8955e5192135e5ab4f14a1 Mon Sep 17 00:00:00 2001 From: "A. Cody Schuffelen" Date: Thu, 13 Jul 2023 19:03:39 -0700 Subject: Darwin/Mac OS host rust compilation fixes - Don't pass `--as-needed` to the linker on Mac OS which is unsupported there - Use `--force_load` rather than `--Wl,--whole-archive` on Mac OS - Scan `rustc`'s linker arguments for `-dylib` and `-dynamiclib`, which it can use instead of `-shared` on Mac OS: https://github.com/rust-lang/rust/blob/7bd81ee1902c049691d0a1f03be5558bee51d100/compiler/rustc_codegen_ssa/src/back/linker.rs#L319 Test: m libhalf serde_derive Bug: 291164566 Change-Id: Iecd6c2532fa31c9476834f49b109de98cbd2dccf --- scripts/mkcratersp.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'scripts/mkcratersp.py') diff --git a/scripts/mkcratersp.py b/scripts/mkcratersp.py index 86b4aa3fb..6ef01ebcc 100755 --- a/scripts/mkcratersp.py +++ b/scripts/mkcratersp.py @@ -48,6 +48,8 @@ for i, arg in enumerate(sys.argv): linkdirs.append(sys.argv[i+1]) if arg.startswith('-l') or arg == '-shared': libs.append(arg) + if os.getenv('ANDROID_RUST_DARWIN') and (arg == '-dylib' or arg == '-dynamiclib'): + libs.append(arg) if arg.startswith('-Wl,--version-script='): version_script = arg[21:] if arg[0] == '-': @@ -64,9 +66,13 @@ create_archive(f'{out}.whole.a', objects, []) create_archive(f'{out}.a', [], temp_archives) with open(out, 'w') as f: - print(f'-Wl,--whole-archive', file=f) - print(f'{out}.whole.a', file=f) - print(f'-Wl,--no-whole-archive', file=f) + if os.getenv("ANDROID_RUST_DARWIN"): + print(f'-force_load', file=f) + print(f'{out}.whole.a', file=f) + else: + print(f'-Wl,--whole-archive', file=f) + print(f'{out}.whole.a', file=f) + print(f'-Wl,--no-whole-archive', file=f) print(f'{out}.a', file=f) for a in archives: print(a, file=f) -- cgit v1.2.3-59-g8ed1b