Skip to content

Commit

Permalink
Merge pull request #495 from CCnut/main
Browse files Browse the repository at this point in the history
Fix: Android build problem
Relates to #278
  • Loading branch information
ashvardanian authored Sep 28, 2024
2 parents b9a9758 + d1a936f commit 3165189
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Spatial • Binary • Probabilistic • User-Defined Metrics
<a href="https://unum-cloud.github.io/usearch/golang">GoLang</a> •
<a href="https://unum-cloud.github.io/usearch/wolfram">Wolfram</a>
<br/>
Linux • MacOS • Windows • iOS • WebAssembly •
Linux • MacOS • Windows • iOS • Android • WebAssembly •
<a href="https://unum-cloud.github.io/usearch/sqlite">SQLite3</a>
</p>

Expand Down
17 changes: 9 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,37 @@ fn main() {
};

if cfg!(feature = "simsimd") {
build.define("USEARCH_USE_SIMSIMD", "1")
.define("SIMSIMD_DYNAMIC_DISPATCH", "1")
.define("SIMSIMD_NATIVE_BF16", "0")
.define("SIMSIMD_NATIVE_F16", "0");
build
.define("USEARCH_USE_SIMSIMD", "1")
.define("SIMSIMD_DYNAMIC_DISPATCH", "1")
.define("SIMSIMD_NATIVE_BF16", "0")
.define("SIMSIMD_NATIVE_F16", "0");

for flag in &flags_to_try {
build.define(flag, "1");
}
} else {
build.define("USEARCH_USE_SIMSIMD", "0");
}


let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
// Conditional compilation depending on the target operating system.
if cfg!(target_os = "linux") {
if target_os == "linux" || target_os == "android" {
build
.flag_if_supported("-std=c++17")
.flag_if_supported("-O3")
.flag_if_supported("-ffast-math")
.flag_if_supported("-fdiagnostics-color=always")
.flag_if_supported("-g1"); // Simplify debugging
} else if cfg!(target_os = "macos") {
} else if target_os == "macos" {
build
.flag_if_supported("-mmacosx-version-min=10.15")
.flag_if_supported("-std=c++17")
.flag_if_supported("-O3")
.flag_if_supported("-ffast-math")
.flag_if_supported("-fcolor-diagnostics")
.flag_if_supported("-g1"); // Simplify debugging
} else if cfg!(target_os = "windows") {
} else if target_os == "windows" {
build
.flag_if_supported("/std:c++17")
.flag_if_supported("/O2")
Expand Down
3 changes: 3 additions & 0 deletions include/usearch/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#define USEARCH_DEFINED_APPLE
#elif defined(__linux__)
#define USEARCH_DEFINED_LINUX
#if defined(__ANDROID_API__)
#define USEARCH_DEFINED_ANDROID
#endif
#endif

// Inferring the compiler: Clang vs GCC
Expand Down
4 changes: 2 additions & 2 deletions include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ class aligned_allocator_gt {
std::size_t alignment = alignment_ak;
#if defined(USEARCH_DEFINED_WINDOWS)
return (pointer)_aligned_malloc(length_bytes, alignment);
#elif defined(USEARCH_DEFINED_APPLE)
#elif defined(USEARCH_DEFINED_APPLE) || defined(USEARCH_DEFINED_ANDROID)
// Apple Clang keeps complaining that `aligned_alloc` is only available
// with macOS 10.15 and newer, so let's use `posix_memalign` there.
// with macOS 10.15 and newer or Android API >= 28, so let's use `posix_memalign` there.
void* result = nullptr;
int status = posix_memalign(&result, alignment, length_bytes);
return status == 0 ? (pointer)result : nullptr;
Expand Down

0 comments on commit 3165189

Please sign in to comment.