Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Update build script to enable cross compiling for Android #264

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
Expand Down Expand Up @@ -45,7 +46,7 @@ jobs:

- name: Set OPENSSL_ROOT_DIR
if: startsWith(matrix.os, 'macos')
run: echo "OPENSSL_ROOT_DIR=/usr/local/opt/[email protected]" >> $GITHUB_ENV
run: echo "OPENSSL_ROOT_DIR=/opt/homebrew/Cellar/[email protected]/1.1.1w" >> $GITHUB_ENV

- name: Install Rust
run: |
Expand Down Expand Up @@ -83,4 +84,14 @@ jobs:
- name: Cargo clippy
run: cargo clippy

- name: Install cargo ndk and rust compiler for android targets
run: |
cargo install --locked cargo-ndk
rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android

- name: Cargo build android
if: ${{ ! startsWith(matrix.os, 'windows') }}
run: |
cargo ndk --bindgen -t x86_64 -t x86 -t armeabi-v7a -t arm64-v8a -o ./jniLibs rustc --crate-type cdylib -p oqs --no-default-features --features kems,sigs,std

# vim: set ft=yaml ts=2 sw=2 tw=0 et :
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