Description
Building for iOS target (aarch64-apple-ios or aarch64-apple-ios-sim) fails with:
error: Unable to build f16 kernels on given target_arch. Please use x86_64 or aarch64 or remove the fp16kernels feature
This happens even when fp16kernels feature is not enabled.
Root Cause
In rust/lance-linalg/build.rs, there are two bugs:
Bug 1: Feature check uses wrong method
fn build_f16_with_flags(suffix: &str, flags: &[&str]) -> Result<(), cc::Error> {
if cfg!(not(feature = "fp16kernels")) { // ❌ This checks build.rs features, not the crate's
return Ok(());
}
// ...
}
cfg!(feature = "fp16kernels") is a compile-time check on the build script itself, not the library being built. The correct check is:
if env::var("CARGO_FEATURE_FP16KERNELS").is_err() {
return Ok(());
}
Bug 2: Error returned before feature check for unsupported targets
fn main() -> Result<(), String> {
// ... arch/os checks ...
if target_arch == "aarch64" && target_os == "macos" {
build_f16_with_flags(...)?; // Feature check happens inside
} else if target_arch == "aarch64" && target_os == "linux" {
build_f16_with_flags(...)?;
} else if target_arch == "x86_64" {
// ...
} else {
return Err("Unable to build f16 kernels..."); // ❌ Error BEFORE any feature check!
}
}
For iOS (target_os = "ios"), the code falls through to the else branch and returns an error before build_f16_with_flags is ever called.
Proposed Fix
Add the feature check at the top of main(), before any architecture branching:
fn main() -> Result<(), String> {
// ... nightly check, rerun-if-changed ...
// Check if fp16kernels feature is enabled - if not, skip everything
if env::var("CARGO_FEATURE_FP16KERNELS").is_err() {
return Ok(());
}
// ... rest of the code ...
}
This way, when fp16kernels is disabled (which is the default), the build script exits cleanly on all platforms including iOS, Android, and any future targets.
Environment
- lancedb v0.23.1
- lance-linalg v1.0.1
- Target:
aarch64-apple-ios-sim
- Using:
lancedb = { version = "0.23", default-features = false }
Related
Description
Building for iOS target (
aarch64-apple-iosoraarch64-apple-ios-sim) fails with:This happens even when
fp16kernelsfeature is not enabled.Root Cause
In
rust/lance-linalg/build.rs, there are two bugs:Bug 1: Feature check uses wrong method
cfg!(feature = "fp16kernels")is a compile-time check on the build script itself, not the library being built. The correct check is:Bug 2: Error returned before feature check for unsupported targets
For iOS (
target_os = "ios"), the code falls through to theelsebranch and returns an error beforebuild_f16_with_flagsis ever called.Proposed Fix
Add the feature check at the top of main(), before any architecture branching:
This way, when
fp16kernelsis disabled (which is the default), the build script exits cleanly on all platforms including iOS, Android, and any future targets.Environment
aarch64-apple-ios-simlancedb = { version = "0.23", default-features = false }Related
aarch64in Rust #2411 - Similar issue for Android builds