Skip to content

Commit 025c329

Browse files
committed
Replace -lgcc with -lunwind in linker argument @files. Fixes #89.
This applies the fix of #83 to linker argument @files. Linker argument files are used on (at least) Windows.
1 parent 99c01fd commit 025c329

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

plugin/src/main/resources/com/nishtahir/linker-wrapper.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,35 @@
55
import subprocess
66
import sys
77

8-
args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
8+
args = [
9+
os.environ["RUST_ANDROID_GRADLE_CC"],
10+
os.environ["RUST_ANDROID_GRADLE_CC_LINK_ARG"],
11+
] + sys.argv[1:]
12+
13+
14+
def update_in_place(arglist):
15+
# The `gcc` library is not included starting from NDK version 23.
16+
# Work around by using `unwind` replacement.
17+
ndk_major_version = os.environ["CARGO_NDK_MAJOR_VERSION"]
18+
if ndk_major_version.isdigit():
19+
if 23 <= int(ndk_major_version):
20+
for i, arg in enumerate(arglist):
21+
if arg.startswith("-lgcc"):
22+
# This is one way to preserve line endings.
23+
arglist[i] = "-lunwind" + arg[len("-lgcc") :]
24+
25+
26+
update_in_place(args)
27+
28+
for arg in args:
29+
if arg.startswith("@"):
30+
fileargs = open(arg[1:], "r").read().splitlines(keepends=True)
31+
update_in_place(fileargs)
32+
open(arg[1:], "w").write("".join(fileargs))
933

10-
# The `gcc` library is not included starting from NDK version 23.
11-
# Work around by using `unwind` replacement.
12-
ndk_major_version = os.environ['CARGO_NDK_MAJOR_VERSION']
13-
if ndk_major_version.isdigit():
14-
if 23 <= int(ndk_major_version):
15-
for i, arg in enumerate(args):
16-
if arg == "-lgcc":
17-
args[i] = "-lunwind"
1834

1935
# This only appears when the subprocess call fails, but it's helpful then.
20-
printable_cmd = ' '.join(pipes.quote(arg) for arg in args)
36+
printable_cmd = " ".join(pipes.quote(arg) for arg in args)
2137
print(printable_cmd)
2238

2339
sys.exit(subprocess.call(args))

0 commit comments

Comments
 (0)