Skip to content

Commit efb3f75

Browse files
committed
fix(ci,android): sed-based cdylib exclusion + armv7 NDK path fallback
- Temporarily strip cdylib from Cargo.toml before building non-arm64 android targets (x86_64/i686/arm NDK libc.a has non-PIC objects) - arm NDK path: try armv7a-linux-androideabi then arm-linux-androideabi
1 parent 6500a4d commit efb3f75

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ jobs:
169169
run: |
170170
# Export NDK bin to PATH for ar and other tools
171171
export PATH="${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
172-
# Override crate-type to exclude cdylib: libcronet.a for
172+
# Temporarily drop cdylib from Cargo.toml: libcronet.a for
173173
# x86_64/i686/arm-android was not compiled with -fPIC, so
174-
# producing a cdylib (.so) fails with PIC relocation errors.
174+
# cdylib (.so) linking fails with PIC relocation errors.
175+
# We build only the rlib for these cross-compilation targets.
176+
sed -i 's/crate-type = \["lib", "cdylib"\]/crate-type = ["lib"]/' Cargo.toml
175177
cargo build --target ${{ matrix.rust_target }} \
176-
--features static-link \
177-
--config 'lib.crate-type = ["lib"]'
178+
--features static-link
179+
git checkout -- Cargo.toml
178180
179181
#############################################################################
180182
# macOS (Darwin) — static-link mode (.a downloaded)

build.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ fn main() {
5353
if let Ok(ndk_home) = env::var("ANDROID_NDK_HOME") {
5454
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
5555
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap_or_default();
56-
let ndk_target = match (target_arch.as_str(), target_vendor.as_str()) {
57-
("aarch64", _) => "aarch64-linux-android",
58-
("x86_64", _) => "x86_64-linux-android",
59-
("arm", _) => "armv7a-linux-androideabi",
60-
("x86", _) => "i686-linux-android",
61-
_ => "",
56+
let ndk_candidates: &[&str] = match (target_arch.as_str(), target_vendor.as_str()) {
57+
("aarch64", _) => &["aarch64-linux-android"],
58+
("x86_64", _) => &["x86_64-linux-android"],
59+
("arm", _) => &["armv7a-linux-androideabi", "arm-linux-androideabi"],
60+
("x86", _) => &["i686-linux-android"],
61+
_ => &[],
6262
};
63-
if !ndk_target.is_empty() {
64-
let cxx_path = std::path::Path::new(&ndk_home)
65-
.join("toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib")
66-
.join(ndk_target);
63+
let ndk_base = std::path::Path::new(&ndk_home)
64+
.join("toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib");
65+
for candidate in ndk_candidates {
66+
let cxx_path = ndk_base.join(candidate);
6767
if cxx_path.exists() {
6868
println!("cargo:rustc-link-search=native={}", cxx_path.display());
69+
break;
6970
}
7071
}
7172
}

0 commit comments

Comments
 (0)