forked from Chia-Network/bls-signatures
-
Notifications
You must be signed in to change notification settings - Fork 34
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
fix: support android #88
Merged
ogabrielides
merged 1 commit into
dashpay:develop
from
HashEngineering:feat/support-android
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ fn handle_command_output(output: Output) { | |
#[cfg(not(feature = "apple"))] | ||
fn main() { | ||
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); | ||
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
|
||
// TODO: fix build for wasm32 on MacOS | ||
// errors with `error: linking with `rust-lld` failed: exit status: 1` | ||
|
@@ -63,12 +64,48 @@ fn main() { | |
|
||
fs::create_dir_all(&bls_dash_build_path).expect("can't create build directory"); | ||
|
||
let cmake_output = create_cross_cmake_command() | ||
|
||
let cmake_command_binding = create_cross_cmake_command(); | ||
let mut cmake_command = cmake_command_binding; | ||
|
||
cmake_command | ||
.current_dir(&bls_dash_build_path) | ||
.arg("-DBUILD_BLS_PYTHON_BINDINGS=0") | ||
.arg("-DBUILD_BLS_TESTS=0") | ||
.arg("-DBUILD_BLS_BENCHMARKS=0") | ||
.arg("-DBUILD_BLS_JS_BINDINGS=0") | ||
.arg("-DBUILD_BLS_JS_BINDINGS=0"); | ||
|
||
// configure CMake for Android | ||
if target_os.eq("android") { | ||
let cmake_toolchain_path = env::var("CMAKE_TOOLCHAIN_FILE") | ||
.or_else(|_| env::var("CARGO_NDK_CMAKE_TOOLCHAIN_PATH")) | ||
.expect("Neither CMAKE_TOOLCHAIN_FILE nor CARGO_NDK_CMAKE_TOOLCHAIN_PATH environment variables are set"); | ||
|
||
let ndk_target = match env::var("CARGO_NDK_TARGET_ARCH") { | ||
Ok(value) => value, // If set, use the value directly. | ||
Err(_) => { | ||
match target_arch.as_str() { | ||
"aarch64" => "arm64-v8a".to_string(), | ||
"arm" => "armeabi-v7a".to_string(), | ||
"x86" => "x86".to_string(), | ||
"x86_64" => "x86_64".to_string(), | ||
_ => panic!("Unsupported target architecture for Android: {}", target_arch), | ||
} | ||
} | ||
}; | ||
|
||
// Default to android-24 if ANDROID_PLATFORM is not specified | ||
let android_abi = env::var("ANDROID_PLATFORM") | ||
.or_else(|_| env::var("CARGO_NDK_ANDROID_PLATFORM")) | ||
.unwrap_or_else(|_| "android-24".to_string()); | ||
|
||
cmake_command | ||
.arg(format!("-DANDROID_PLATFORM={}", android_abi)) | ||
.arg(format!("-DANDROID_ABI={}", ndk_target)) | ||
.arg(format!("-DCMAKE_TOOLCHAIN_FILE={}", cmake_toolchain_path)); | ||
} | ||
|
||
let cmake_output = cmake_command | ||
.arg("..") | ||
.output() | ||
.expect("can't run cmake"); | ||
|
@@ -127,7 +164,8 @@ fn main() { | |
cc.files(cpp_files) | ||
.includes(&include_paths) | ||
.cpp(true) | ||
.flag_if_supported("-std=c++14"); | ||
.flag_if_supported("-std=c++14") | ||
.target(&env::var("TARGET").unwrap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
|
||
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support android, we need to specify the platform version (default will be 24, which is Android 7.0) and the ABI which will be one of the 4 specified by the root build process. Lastly, the toolchain is set to the Android toolchain.