]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Restore compatibility with Rust 1.74 (#563)
authorChristian Heimes <christian@python.org>
Tue, 4 Feb 2025 08:25:26 +0000 (09:25 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2025 08:25:26 +0000 (09:25 +0100)
* Restore compatibility with Rust 1.74

PR #544 added support for `no_std` feature. The PR changed
`std::error::Error` to `core::error::Error`. The `core::error` trait was
stabilized in Rust 1.81, so the change bumped MSRV to 1.81. Before the
Python package built with Rust 1.66 and the `safetensors` create with
all features built with 1.74.

This commit restores compatibility with Rust 1.74 for `std` builds:

- `mixed_integer_ops` feature requires 1.66
- `half v2.4.1` requires 1.70
- `clap_lex v0.7.4` requires 1.74

I'm also adding `rust-version` to `Cargo.toml`, so cargo creates a
backwards compatible `Cargo.lock`. By default, Cargo >= 1.83 creates a
`v4` lock file, which is not compatible with Cargo < 1.78.

Signed-off-by: Christian Heimes <christian@python.org>
* Merging the test matrix.

---------

Signed-off-by: Christian Heimes <christian@python.org>
Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
.github/workflows/rust.yml
bindings/python/Cargo.toml
safetensors/Cargo.toml
safetensors/src/tensor.rs

index e7ac0684fca6fd70a7f3497b172b6aad6a576f2d..a1eb3e60347f7ae943c3d0af202afe65ab9b12e5 100644 (file)
@@ -9,6 +9,10 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, windows-latest, macOS-latest]
+        toolchain: [stable]
+        include:
+          - os: ubuntu-latest
+            toolchain: "1.74"
     defaults:
       run:
         working-directory: ./safetensors
index a1dadeede6b574e5b4866ad2f32c39a3986245e1..de7692bca4b516a964f835c21b8b3fa6af5b12c9 100644 (file)
@@ -2,6 +2,7 @@
 name = "safetensors-python"
 version = "0.5.3-dev.0"
 edition = "2021"
+rust-version = "1.74"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 [lib]
index 037104a3868dda8bf4b2ee5511430f3e17ff5205..dd303d65d611f0bf3bd9ac091594e2efd3c3ec74 100644 (file)
@@ -2,6 +2,7 @@
 name = "safetensors"
 version = "0.5.3-dev.0"
 edition = "2021"
+rust-version = "1.74"
 homepage = "https://github.com/huggingface/safetensors"
 repository = "https://github.com/huggingface/safetensors"
 documentation = "https://docs.rs/safetensors/"
index bee7178212350783c34026fe0c88f5dccbb04f57..42d59e040132ef52caedbb1921d0b84f1d3c0b46 100644 (file)
@@ -64,8 +64,12 @@ impl core::fmt::Display for SafeTensorError {
     }
 }
 
+#[cfg(not(feature = "std"))]
 impl core::error::Error for SafeTensorError {}
 
+#[cfg(feature = "std")]
+impl std::error::Error for SafeTensorError {}
+
 struct PreparedData {
     n: u64,
     header_bytes: Vec<u8>,