Skip to content

Commit 889bf25

Browse files
committed
Make: Rust 1.65 compatibility
Until then `f32::abs` is missing
1 parent 301d59c commit 889bf25

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ cargo bench
209209
open target/criterion/report/index.html
210210
```
211211
212+
To automatically detect the Minimum Supported Rust Version (MSRV):
213+
214+
```sh
215+
cargo +stable install cargo-msrv
216+
cargo msrv find --ignore-lockfile
217+
```
218+
212219
## JavaScript
213220
214221
### NodeJS

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ categories = [
1616
"wasm",
1717
"external-ffi-bindings",
1818
]
19-
include = ["/rust/**", "/c/**", "/include/**", "/build.rs"]
19+
rust-version = "1.64" # Introduced Core C FFI in stable Rust
20+
include = ["rust/**", "c/**", "include/**", "build.rs"]
2021

2122

2223
[lib]
2324
name = "simsimd"
2425
path = "rust/lib.rs"
2526

2627
[build-dependencies]
27-
cc = "1.0.83"
28+
cc = "1.2.36"
2829

2930

3031
[[bench]]
@@ -48,6 +49,6 @@ default = []
4849
std = []
4950

5051
[dev-dependencies]
51-
criterion = { version = "0.6.0" }
52+
criterion = { version = "0.7.0" }
5253
rand = { version = "0.9.1" }
5354
half = { version = "2.6.0" }

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ fn main() -> Result<(), cc::Error> {
22
let mut build = cc::Build::new();
33

44
build
5+
// Prefer portable flags to support MSVC and older toolchains
6+
.std("c99") // Enforce C99 standard when supported
57
.file("c/lib.c")
68
.include("include")
79
.define("SIMSIMD_NATIVE_F16", "0")
810
.define("SIMSIMD_NATIVE_BF16", "0")
911
.define("SIMSIMD_DYNAMIC_DISPATCH", "1")
1012
.opt_level(3)
11-
// Prefer portable flags to support MSVC and older toolchains
12-
.flag_if_supported("-std=c99") // Enforce C99 standard when supported
1313
.flag_if_supported("-pedantic") // Strict compliance when supported
1414
.warnings(false);
1515

rust/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
pub type Distance = f64;
7878
pub type ComplexProduct = (f64, f64);
7979

80+
/// Compatibility function for pre 1.85 Rust versions lacking `f32::abs`.
81+
#[inline(always)]
82+
fn f32_abs_compat(x: f32) -> f32 {
83+
f32::from_bits(x.to_bits() & 0x7FFF_FFFF)
84+
}
85+
8086
#[link(name = "simsimd")]
8187
extern "C" {
8288

@@ -251,7 +257,7 @@ impl f16 {
251257
/// Returns the absolute value of self.
252258
#[inline(always)]
253259
pub fn abs(self) -> Self {
254-
Self::from_f32(self.to_f32().abs())
260+
Self::from_f32(f32_abs_compat(self.to_f32()))
255261
}
256262

257263
/// Returns the largest integer less than or equal to a number.
@@ -425,7 +431,7 @@ impl bf16 {
425431
/// Returns the absolute value of self.
426432
#[inline(always)]
427433
pub fn abs(self) -> Self {
428-
Self::from_f32(self.to_f32().abs())
434+
Self::from_f32(f32_abs_compat(self.to_f32()))
429435
}
430436

431437
/// Returns the largest integer less than or equal to a number.

0 commit comments

Comments
 (0)