Skip to content

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

@moe-deer

Description

@moe-deer

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 15, 2023
added
A-linkageArea: linking into static, shared libraries and binaries
O-androidOperating system: Android
A-crossArea: Cross compilation
O-windows-msvcToolchain: MSVC, Operating system: Windows
on Jul 15, 2023
jyn514

jyn514 commented on Jul 15, 2023

@jyn514
Member

you are using an MSVC host toolchain and the compiler is passing unix-style flags. do you see this same problem on windows-gnu or only on MSVC?

removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 16, 2023
moe-deer

moe-deer commented on Jul 16, 2023

@moe-deer
Author

I encountered this issue on both windows-gnu and MSVC. They work correctly in rust 1.68.2 version, but the problem appears in versions after that.

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jul 16, 2023
added this to the 1.69.0 milestone on Jul 16, 2023
added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on Jul 16, 2023
apiraino

apiraino commented on Aug 1, 2023

@apiraino
Contributor

@moe-deer Does it also happen with a new Rust project? Any chance you can provide a small bare Rust project template to reproduce the issue? Just to be sure I understand: is the correct Windows path to your Android NDK D:\\NDK\\android-ndk-r25c\\?

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @knopp@apiraino@darcycui@jyn514@usernamety

        Issue actions

          When cross compiling Rust to Android on Windows, Rust 1.69.0+ can't find the version script path. · Issue #113711 · rust-lang/rust