Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #120 from c4dt/fix-build
Browse files Browse the repository at this point in the history
fix: fix build script to take env variables into account
  • Loading branch information
PascalinDe authored Oct 27, 2023
2 parents 7fb5cb6 + 822f2f9 commit ef21bcf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ cargo test

# Notes on building the library for x86_64 devices

To build this library for a x86_64 device, Android NDK version 25.2.9519653 must be installed at the
default installation path (`$HOME/Android/Sdk/ndk`).
To build this library for a x86_64 device, Android NDK version 25.2.9519653 must be installed and
the installation location must be pointed to in the `ANDROID_NDK_HOME` environment variable.

# License

Expand Down
22 changes: 17 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
// inspired by https://github.com/p2panda/meli/pull/21/files
// adapted version of meli's fix https://github.com/p2panda/meli/pull/21/files

use std::env;
use std::path;

fn main() {
// NDK > 25 does not link to `libgcc` anymore
// see https://github.com/p2panda/meli/pull/21/files
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "x86_64"
&& env::var("CARGO_CFG_TARGET_OS").unwrap() == "android"
{
let home: String = env::var("HOME").unwrap();
println!("cargo:rustc-link-search={home}/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/");
const VERSION: &str = "25.2.9519653";
let mut android_ndk_home: String = env::var("ANDROID_NDK_HOME").unwrap();
// check if default version is pinned version
if !android_ndk_home.contains(VERSION) {
let mut splits: Vec<&str> = android_ndk_home.as_str().split('/').collect();
splits.pop(); // remove default version
android_ndk_home = format!("{}/{}", &splits.join("/"), VERSION);
}
if !path::Path::new(&android_ndk_home).exists() {
panic!(
"build cannot succeed: '{}' does not exist",
android_ndk_home
);
}
println!("cargo:rustc-link-search={android_ndk_home}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/");
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
}
}

0 comments on commit ef21bcf

Please sign in to comment.