Skip to content

When cross compiling Rust to Android on Windows, Rust 1.69.0+ can't find the version script path. #113711

Open
@moe-deer

Description

On Windows, when cross compiling Rust code to generate an Android .so library, using Rust versions 1.69.0 or newer can result in compile errors about the version script.
The error happens because the Rust compiler tries to pass a path to a version script to the linker, but that specified path does not actually exist on Windows.

I tried this code:

cargo build --release --target=aarch64-linux-android

I expected to see this happen:

Finished release [optimized] target(s) in 2.44s

Instead, this happened:

error: linking with `D:/NDK/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android30-clang.cmd` failed: exit code: 255                                                                
  |
  = note: "D:/NDK/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android30-clang.cmd" "-Wl,--version-script=C:\\Users\\Liste\\AppData\\Local\\Temp\\rustcPwRX2e\\list" "-Wl,--no-undefi
ned-version" "C:\\Users\\Liste\\AppData\\Local\\Temp\\rustcPwRX2e\\symbols.o" "E:\\idea_projects\\my_lib\\target\\aarch64-linux-android\\release\\deps\\my_lib.my_lib.d56b3372c49eacad-cgu.0.rcgu.o" "
-Wl,--as-needed" "-L" "E:\\idea_projects\\my_lib\\target\\aarch64-linux-android\\release\\deps" "-L" "E:\\idea_projects\\my_lib\\target\\release\\deps" "-L" "C:\\Users\\Liste\\.rustup\\toolchains\\stable-
x86_64-pc-windows-msvc\\lib\\rustlib\\aarch64-linux-android\\lib" "-Wl,-Bstatic" "C:\\Users\\Liste\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\aarch64-linux-android\\lib\\libcompiler_builtins-0
1f0855226f8e564.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "C:\\Users\\Liste\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\a
arch64-linux-android\\lib" "-o" "E:\\idea_projects\\my_lib\\target\\aarch64-linux-android\\release\\deps\\libmy_lib.so" "-Wl,--gc-sections" "-shared" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs"
  = note: --version-script=C:\Users\Liste\AppData\Local\Temp\rustcPwRX2e\list"" was unexpected at this time.


warning: `my_lib` (lib) generated 2 warnings                                                                                                                                                                     
error: could not compile `my_lib` (lib) due to previous error; 2 warnings emitted

Meta

rustc --version --verbose:

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-pc-windows-msvc
release: 1.71.0
LLVM version: 16.0.5

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-androidOperating system: AndroidO-windows-msvcToolchain: MSVC, Operating system: Windowsregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions