fix(node): enforce x86-64-v2 artifact baseline

This commit is contained in:
Gatefixer
2026-08-06 04:48:31 +00:00
parent cf9a8bf91d
commit c858e25494
2 changed files with 34 additions and 2 deletions
+5 -2
View File
@@ -1,11 +1,14 @@
# Keep Node's Linux x64 addons compatible with pre-Haswell CPUs.
# lance-linalg dispatches hot vector kernels to newer SIMD tiers at runtime.
[env]
LANCEDB_NODE_ENFORCE_X86_64_V2 = "1"
[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C",
"target-cpu=x86-64-v2",
"-C",
"target-feature=-avx2,-fma,-f16c",
"target-feature=-avx,-avx2,-fma,-f16c",
]
# Preserve the workspace's dynamic C runtime configuration for musl.
@@ -14,5 +17,5 @@ rustflags = [
"-C",
"target-cpu=x86-64-v2",
"-C",
"target-feature=-crt-static,-avx2,-fma,-f16c",
"target-feature=-crt-static,-avx,-avx2,-fma,-f16c",
]
+29
View File
@@ -3,6 +3,35 @@
extern crate napi_build;
use std::env;
const ENFORCE_BASELINE: &str = "LANCEDB_NODE_ENFORCE_X86_64_V2";
const UNSUPPORTED_FEATURES: [&str; 4] = ["avx", "avx2", "fma", "f16c"];
fn main() {
napi_build::setup();
println!("cargo:rerun-if-env-changed={ENFORCE_BASELINE}");
let is_linux_x64 = env::var("CARGO_CFG_TARGET_ARCH").as_deref() == Ok("x86_64")
&& env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux");
let is_release = env::var("PROFILE").as_deref() == Ok("release");
let is_node_build = env::var(ENFORCE_BASELINE).as_deref() == Ok("1");
if !is_linux_x64 || (!is_release && !is_node_build) {
return;
}
let target_features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default();
let enabled_features = target_features.split(',').collect::<Vec<_>>();
let leaked_features = UNSUPPORTED_FEATURES
.iter()
.filter(|feature| enabled_features.contains(feature))
.copied()
.collect::<Vec<_>>();
assert!(
leaked_features.is_empty(),
"Linux x64 Node addons must use the x86-64-v2 baseline; unsupported target features: {}",
leaked_features.join(", ")
);
}