From a7a6397e9f759f0acb7431940d9eb3ec0ee04cbb Mon Sep 17 00:00:00 2001 From: Drazen Urch Date: Sun, 18 Jan 2026 21:26:54 +0100 Subject: [PATCH 1/2] fix(lance-linalg): Check fp16kernels feature before arch-specific code The build script was checking target architecture BEFORE verifying if the fp16kernels feature was enabled. This caused builds to fail on platforms like iOS/Android when falling through to the error branch, even when the feature was disabled. The fix adds an early exit using CARGO_FEATURE_FP16KERNELS env var check (not cfg!() which checks build script features, not library features). Fixes: https://github.com/lancedb/lance/issues/5746 --- rust/lance-linalg/build.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/lance-linalg/build.rs b/rust/lance-linalg/build.rs index fee023cf742..5fc807625ad 100644 --- a/rust/lance-linalg/build.rs +++ b/rust/lance-linalg/build.rs @@ -21,6 +21,16 @@ fn main() -> Result<(), String> { println!("cargo:rerun-if-changed=src/simd/f16.c"); println!("cargo:rerun-if-changed=src/simd/dist_table.c"); + // Early exit if fp16kernels feature is not enabled. + // This allows the crate to build on any platform (iOS, Android, etc.) + // when the feature is disabled, without requiring platform-specific kernel support. + // + // Note: We use CARGO_FEATURE_* env var instead of cfg!() because cfg!() + // checks the build script's features, not the library's features. + if env::var("CARGO_FEATURE_FP16KERNELS").is_err() { + return Ok(()); + } + // Important: we don't use `cfg!(target_arch)` here because that is the target_arch // for the build script, not the target_arch for the library. Similar story for // target_os. From 8647a7c0a8227fdff1bf3b9a84863bef21fc0716 Mon Sep 17 00:00:00 2001 From: Drazen Urch Date: Sun, 18 Jan 2026 22:28:17 +0100 Subject: [PATCH 2/2] fix: move feature check to else branch per review Address review feedback: instead of early exit which skips build_dist_table_with_flags on x86_64, only error in the else branch when fp16kernels is explicitly requested on unsupported platforms. This preserves dist_table kernel builds on supported platforms while still allowing iOS/Android builds when fp16kernels is disabled. --- rust/lance-linalg/build.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/rust/lance-linalg/build.rs b/rust/lance-linalg/build.rs index 5fc807625ad..10385e35431 100644 --- a/rust/lance-linalg/build.rs +++ b/rust/lance-linalg/build.rs @@ -21,16 +21,6 @@ fn main() -> Result<(), String> { println!("cargo:rerun-if-changed=src/simd/f16.c"); println!("cargo:rerun-if-changed=src/simd/dist_table.c"); - // Early exit if fp16kernels feature is not enabled. - // This allows the crate to build on any platform (iOS, Android, etc.) - // when the feature is disabled, without requiring platform-specific kernel support. - // - // Note: We use CARGO_FEATURE_* env var instead of cfg!() because cfg!() - // checks the build script's features, not the library's features. - if env::var("CARGO_FEATURE_FP16KERNELS").is_err() { - return Ok(()); - } - // Important: we don't use `cfg!(target_arch)` here because that is the target_arch // for the build script, not the target_arch for the library. Similar story for // target_os. @@ -86,7 +76,14 @@ fn main() -> Result<(), String> { build_f16_with_flags("lsx", &["-mlsx"]).unwrap(); build_f16_with_flags("lasx", &["-mlasx"]).unwrap(); } else { - return Err("Unable to build f16 kernels on given target_arch. Please use x86_64 or aarch64 or remove the fp16kernels feature".to_string()); + // Only error if fp16kernels was explicitly requested on unsupported platform. + // This allows builds on iOS, Android, etc. when the feature is disabled. + // + // Note: We use CARGO_FEATURE_* env var instead of cfg!() because cfg!() + // checks the build script's features, not the library's features. + if env::var("CARGO_FEATURE_FP16KERNELS").is_ok() { + return Err("Unable to build f16 kernels on given target_arch. Please use x86_64 or aarch64 or remove the fp16kernels feature".to_string()); + } } Ok(()) }