Skip to content

Commit 80674a7

Browse files
minyungncalexan
authored andcommitted
When targeting Android NDK 23+, use unwind library instead of gcc library. Fixes #75.
This works around an unfortunate issue with the Rust `std` library where-by `-lgcc` is requested but not provided by newer NDKs. There are a multiple ways to address this, but since `rust-android-gradle` already has a linker script it's reasonable to use it for this purpose.
1 parent 2299861 commit 80674a7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ open class CargoBuildTask : DefaultTask() {
167167
if (toolchain.type != ToolchainType.DESKTOP) {
168168
val toolchainDirectory = if (toolchain.type == ToolchainType.ANDROID_PREBUILT) {
169169
val ndkPath = app.ndkDirectory
170+
val ndkVersion = ndkPath.name
171+
val ndkVersionMajor = ndkVersion.split(".").first()
172+
environment("CARGO_NDK_MAJOR_VERSION", ndkVersionMajor)
173+
170174
val hostTag = if (Os.isFamily(Os.FAMILY_WINDOWS)) {
171175
if (Os.isArch("x86_64") || Os.isArch("amd64")) {
172176
"windows-x86_64"

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

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
99

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"
18+
1019
# This only appears when the subprocess call fails, but it's helpful then.
1120
printable_cmd = ' '.join(pipes.quote(arg) for arg in args)
1221
print(printable_cmd)

0 commit comments

Comments
 (0)