Skip to content

iOS build fails: fp16kernels feature check in build.rs doesn't work for unsupported targets #5746

@durch

Description

@durch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions