Skip to content

Commit ef5904f

Browse files
yutannihilationCopilotnyurik
authored
fix(rust): fix SIMDe configuration on aarch64 platforms when not installed yet (#63)
(In order to fix build on aarch64 platfroms, #62 is still needed in addition to this change) I was wondering why [the FastPFOR-rs repository](https://github.com/fast-pack/FastPFOR) tests macOS runner without installing SIMDe; FastPFOR fetches and build SIMDe automatically. However, it seems the include path and define are not configured correctly when with `cxx_build::bridge()`. So, this pull request attempts to fix it by manually doing the equivalent to this part of `cmake_modules/simde.cmake`. ```cmake target_include_directories(simde INTERFACE "${simde_SOURCE_DIR}") # Enables native aliases. Not ideal but makes it easier to convert old code. target_compile_definitions(simde INTERFACE SIMDE_ENABLE_NATIVE_ALIASES) ``` --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Yuri Astrakhan <yuriastrakhan@gmail.com>
1 parent c80e497 commit ef5904f

4 files changed

Lines changed: 49 additions & 17 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
*.pdb
33
.idea/
44
.vscode/
5+
Cargo.lock
56
codecov*
67
debug/
78
target/
89
temp/
910
tmp/
1011
venv/
1112

12-
# This is a library, no lock
13-
Cargo.lock
13+
!codecov.yml

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,24 @@ For local development, you may need to install the following packages:
8888

8989
```bash
9090
# This list may be incomplete
91-
sudo apt-get install build-essential libsimde-dev
91+
sudo apt-get install build-essential
9292
```
9393

94+
`libsimde-dev` is optional. On ARM/aarch64, the C++ build fetches `SIMDe` via `CMake`,
95+
and the Rust CXX bridge now reuses that fetched include path automatically.
96+
Install `libsimde-dev` only if you prefer a system package fallback.
97+
9498
### macOS
95-
To build `FastPFor` on macOS, you'll need to install `SIMDe`.
96-
Since Homebrew installs packages in `/opt/homebrew` (for Apple Silicon), you'll also need to explicitly set the include paths.
99+
On Apple Silicon, manual `SIMDe` installation is usually not required.
100+
The C++ build fetches `SIMDe` via `CMake`, and the Rust CXX bridge reuses that path.
101+
102+
If you prefer a system package fallback, install `SIMDe` with Homebrew and set include flags.
97103

98104
```bash
99-
# install SIMDe via Homebrew
105+
# optional: install SIMDe via Homebrew
100106
brew install simde
101-
```
102107

103-
```bash
104-
# Ensure the compiler can find the required headers before building
108+
# optional fallback: ensure the compiler can find Homebrew headers
105109
export CXXFLAGS="-I/opt/homebrew/include"
106110
export CFLAGS="-I/opt/homebrew/include"
107111
```

build.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// Builds the C++ `FastPFOR` library and bridge when the `cpp` feature is enabled.
44
#[cfg(feature = "cpp")]
55
fn build_fastpfor() {
6-
use std::path::Path;
6+
use std::{env, path::Path};
77

88
assert!(
99
Path::new("cpp/CMakeLists.txt").exists(),
@@ -12,20 +12,42 @@ fn build_fastpfor() {
1212

1313
// Compile FastPFOR using CMake
1414
println!("cargo:rerun-if-changed=cpp");
15-
let lib_path = cmake::Config::new("cpp")
16-
.define("WITH_TEST", "OFF")
17-
.build()
18-
.join("lib");
15+
let cmake_out = cmake::Config::new("cpp").define("WITH_TEST", "OFF").build();
16+
let lib_path = cmake_out.join("lib");
1917
let lib_path = lib_path.to_str().unwrap();
2018

2119
// Compile the bridge
2220
println!("cargo:rerun-if-changed=src/cpp/fastpfor_bridge.h");
2321
println!("cargo:rerun-if-changed=src/cpp/mod.rs");
24-
cxx_build::bridge("src/cpp/mod.rs")
22+
let mut bridge = cxx_build::bridge("src/cpp/mod.rs");
23+
bridge
2524
.include("cpp/headers")
2625
.include("src/cpp")
27-
.std("c++14")
28-
.compile("fastpfor_bridge");
26+
.std("c++14");
27+
28+
// On ARM/aarch64, FastPFOR headers include SIMDe shims for SSE intrinsics.
29+
// CMake fetches SIMDe to build FastPFOR itself, but the Rust/CXX bridge is a
30+
// separate compilation unit and needs the same compile definition, plus an
31+
// include path if CMake fetched SIMDe into the build tree.
32+
if env::var("CARGO_CFG_TARGET_ARCH").is_ok_and(|arch| arch == "aarch64") {
33+
// Mirror `cpp/cmake_modules/simde.cmake` for the bridge TU:
34+
// FastPFOR headers use SSE names directly (e.g. __m128i, _mm_*),
35+
// so we need SIMDe's native aliases enabled here as well, regardless of
36+
// where the SIMDe headers are provided from.
37+
bridge.define("SIMDE_ENABLE_NATIVE_ALIASES", None);
38+
39+
let simde_include = cmake_out.join("build").join("_deps").join("simde-src");
40+
if simde_include.exists() {
41+
bridge.include(simde_include);
42+
} else {
43+
println!(
44+
"cargo:warning=SIMDe headers were not found in CMake build output; \
45+
ensure SIMDe is available on the include path if bridge compilation fails."
46+
);
47+
}
48+
}
49+
50+
bridge.compile("fastpfor_bridge");
2951

3052
// Link the FastPFOR library - must be done after the bridge is compiled
3153
println!("cargo:rustc-link-search=native={lib_path}");

codecov.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
codecov:
2+
require_ci_to_pass: false
3+
4+
coverage:
5+
status:
6+
patch: off

0 commit comments

Comments
 (0)