Skip to content

Commit 99aca88

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 d5f693d commit 99aca88

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,40 @@
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+
arg[: len("-lgcc")] = "-lunwind"
24+
arglist[i] = arg
25+
26+
27+
update_in_place(args)
28+
29+
for arg in args:
30+
if arg.startswith("@"):
31+
fileargs = open(arg[1:], "r").read().splitlines(keepends=True)
32+
update_in_place(fileargs)
33+
open(arg[1:], "w").write("".join(args))
34+
35+
print(">>>")
36+
print(open(arg[1:], "r").read())
37+
print("<<<")
938

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"
1839

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

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

0 commit comments

Comments
 (0)