From: Christian Heimes Date: Tue, 4 Feb 2025 08:25:26 +0000 (+0100) Subject: Restore compatibility with Rust 1.74 (#563) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=581f43bf212a32aaf00021efbea7fca49620811b;p=safetensors.git Restore compatibility with Rust 1.74 (#563) * 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 * Merging the test matrix. --------- Signed-off-by: Christian Heimes Co-authored-by: Nicolas Patry --- diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e7ac068..a1eb3e6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index a1dadee..de7692b 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -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] diff --git a/safetensors/Cargo.toml b/safetensors/Cargo.toml index 037104a..dd303d6 100644 --- a/safetensors/Cargo.toml +++ b/safetensors/Cargo.toml @@ -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/" diff --git a/safetensors/src/tensor.rs b/safetensors/src/tensor.rs index bee7178..42d59e0 100644 --- a/safetensors/src/tensor.rs +++ b/safetensors/src/tensor.rs @@ -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,