Skip to content

Commit

Permalink
(feat): Update build script to enable cross compiling for Android
Browse files Browse the repository at this point in the history
Based on the cmake manual, cross compiling for Android,
https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android-with-the-ndk

CMAKE_SYSTEM_NAME **must** be set to Android.

Additionally, set CMAKE_ANDROID_NDK if corresponding env var is available.
Android ecosystem uses both ANDROID_NDK_ROOT and ANDROID_NDK_HOME to refer to
NDK's path. For example, github runners has both variables set:
actions/runner-images#2426

These two cmake variables are sufficient to build for Android with cargo-ndk tool.

Signed-off-by: Mariappan Ramasamy <[email protected]>
  • Loading branch information
nappairam committed Aug 6, 2024
1 parent a5eec6e commit e0f59c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions oqs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pkg-config = "0.3"
cmake = "0.1"
bindgen = "0.69"
build-deps = "0.1"
build-target = "0.4.0"

[features]
default = ["openssl", "kems", "sigs"]
Expand Down
12 changes: 12 additions & 0 deletions oqs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ fn build_from_source() -> PathBuf {
config.define(permit_unsupported, str);
}

if build_target::target_os().unwrap() == build_target::Os::Android {
config.define("CMAKE_SYSTEM_NAME", "Android");

if let Ok(ndk) = std::env::var("ANDROID_NDK_HOME") {
config.define("CMAKE_ANDROID_NDK", ndk);
println!("cargo:rerun-if-env-changed=ANDROID_NDK_HOME");
} else if let Ok(ndk) = std::env::var("ANDROID_NDK_ROOT") {
config.define("CMAKE_ANDROID_NDK", ndk);
println!("cargo:rerun-if-env-changed=ANDROID_NDK_ROOT");
}
}

let outdir = config.build_target("oqs").build();

// lib is put into $outdir/build/lib
Expand Down

0 comments on commit e0f59c0

Please sign in to comment.