Skip to content

Commit

Permalink
Restore compatibility with Rust 1.74
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tiran committed Jan 24, 2025
1 parent ea1a2d0 commit dba702d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
27 changes: 26 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:

jobs:
build:
build-stable:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -59,3 +59,28 @@ jobs:
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
# working-directory: ./safetensors
# fail_ci_if_error: true

build-msrv:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./safetensors
env:
MSRV: "1.74"

steps:
- uses: actions/checkout@v3

- name: Install Rust ${{ env.MSRV }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.MSRV }}
override: true

- uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --all-targets --verbose

- name: Run Tests
run: cargo test --verbose
1 change: 1 addition & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions safetensors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
5 changes: 5 additions & 0 deletions safetensors/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ 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>,
Expand Down

0 comments on commit dba702d

Please sign in to comment.