nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From 8a6c16fd79e78aaaf1223090e673bdbe11451abc Mon Sep 17 00:00:00 2001
2From: DavHau <hsngrmpf+github@gmail.com>
3Date: Wed, 22 Oct 2025 10:40:03 +0700
4Subject: [PATCH] Fix cross-compilation by checking target arch in build.rs
5
6Previously, build.rs used #[cfg(target_arch)] attributes which check
7the host architecture where the build script runs, not the target
8being compiled for. This caused AVX-512 features to be incorrectly
9enabled when cross-compiling from x86_64 to other architectures like
10riscv64, leading to compilation errors.
11
12Now uses CARGO_CFG_TARGET_ARCH environment variable to correctly
13detect the target architecture during cross-compilation.
14---
15 build.rs | 10 ++++++----
16 1 file changed, 6 insertions(+), 4 deletions(-)
17
18diff --git a/build.rs b/build.rs
19index 42788623..28e006a9 100644
20--- a/build.rs
21+++ b/build.rs
22@@ -38,8 +38,11 @@ fn main() {
23 #[allow(unused_variables)]
24 let is_64_bit_python = matches!(python_config.pointer_width, Some(64));
25
26- #[cfg(all(target_arch = "x86_64", not(target_os = "macos")))]
27- if version_check::is_min_version("1.89.0").unwrap_or(false) && is_64_bit_python {
28+ let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
29+ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
30+
31+ if target_arch == "x86_64" && target_os != "macos"
32+ && version_check::is_min_version("1.89.0").unwrap_or(false) && is_64_bit_python {
33 println!("cargo:rustc-cfg=feature=\"avx512\"");
34 }
35
36@@ -51,8 +54,7 @@ fn main() {
37 println!("cargo:rustc-cfg=feature=\"optimize\"");
38 }
39
40- #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
41- if is_64_bit_python {
42+ if (target_arch == "x86_64" || target_arch == "aarch64") && is_64_bit_python {
43 println!("cargo:rustc-cfg=feature=\"inline_int\"");
44 }