diff --git a/.github/workflows/maturin_upload_pypi.yml b/.github/workflows/maturin_upload_pypi.yml index 934c2ee..b322394 100644 --- a/.github/workflows/maturin_upload_pypi.yml +++ b/.github/workflows/maturin_upload_pypi.yml @@ -1,4 +1,4 @@ -# This file is autogenerated by maturin v1.2.3 +# This file is autogenerated by maturin v1.9.6 # To update, run # # maturin generate-ci github @@ -15,96 +15,167 @@ permissions: jobs: linux: - runs-on: ubuntu-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] - fail-fast: false + platform: + - runner: ubuntu-22.04 + target: x86_64 + - runner: ubuntu-22.04 + target: x86 + - runner: ubuntu-22.04 + target: aarch64 + - runner: ubuntu-22.04 + target: armv7 + - runner: ubuntu-22.04 + target: s390x + - runner: ubuntu-22.04 + target: ppc64le steps: - - uses: actions/checkout@v5 - - uses: actions/setup-python@v5 + - uses: actions/checkout@main + - uses: actions/setup-python@v6 with: - python-version: '3.9 - 3.13' + python-version: | + 3.8 - 3.14 + 3.x + pypy3.8 + pypy3.9 + pypy3.10 + pypy3.11 - name: Build wheels uses: PyO3/maturin-action@v1 env: PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out ../dist --find-interpreter - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: auto working-directory: lib/ - name: Upload wheels - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@main with: - name: wheels-linux-${{ matrix.target }} + name: wheels-linux-${{ matrix.platform.target }} + path: dist + if-no-files-found: error + + musllinux: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + - runner: ubuntu-22.04 + target: x86 + - runner: ubuntu-22.04 + target: aarch64 + - runner: ubuntu-22.04 + target: armv7 + steps: + - uses: actions/checkout@main + - uses: actions/setup-python@v6 + with: + python-version: | + 3.8 - 3.14 + 3.x + pypy3.8 + pypy3.9 + pypy3.10 + pypy3.11 + - name: Build wheels + uses: PyO3/maturin-action@v1 + env: + PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1 + with: + target: ${{ matrix.platform.target }} + args: --release --out ../dist --find-interpreter + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} + manylinux: musllinux_1_2 + working-directory: lib/ + - name: Upload wheels + uses: actions/upload-artifact@main + with: + name: wheels-musllinux-${{ matrix.platform.target }} path: dist if-no-files-found: error windows: - runs-on: windows-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x64, x86] - fail-fast: false + platform: + - runner: windows-latest + target: x64 + - runner: windows-latest + target: x86 steps: - - uses: actions/checkout@v5 - - uses: actions/setup-python@v5 + - uses: actions/checkout@main + - uses: actions/setup-python@v6 with: - python-version: '3.13' - architecture: ${{ matrix.target }} + # We can't use pypy3.8 nor pypy3.11 in CI + python-version: | + 3.8 - 3.14 + 3.x + pypy3.9 + pypy3.10 + architecture: ${{ matrix.platform.target }} - name: Build wheels uses: PyO3/maturin-action@v1 env: PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out ../dist --find-interpreter - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} working-directory: lib/ - name: Upload wheels - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@main with: - name: wheels-windows-${{ matrix.target }} + name: wheels-windows-${{ matrix.platform.target }} path: dist if-no-files-found: error macos: - runs-on: macos-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x86_64, aarch64] - fail-fast: false + platform: + - runner: macos-13 + target: x86_64 + - runner: macos-14 + target: aarch64 steps: - - uses: actions/checkout@v5 - - uses: actions/setup-python@v5 + - uses: actions/checkout@main + - uses: actions/setup-python@v6 with: - python-version: '3.13' + # We can't use pypy3.8 in CI + python-version: | + 3.8 - 3.14 + 3.x + pypy3.9 + pypy3.10 + pypy3.11 - name: Build wheels uses: PyO3/maturin-action@v1 env: PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out ../dist --find-interpreter - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} working-directory: lib/ - name: Upload wheels - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@main with: - name: wheels-macos-${{ matrix.target }} + name: wheels-macos-${{ matrix.platform.target }} path: dist if-no-files-found: error sdist: runs-on: ubuntu-latest - strategy: - fail-fast: false steps: - - name: Checkout repo - uses: actions/checkout@v5 - + - uses: actions/checkout@main - name: Build sdist uses: PyO3/maturin-action@v1 env: @@ -113,11 +184,10 @@ jobs: command: sdist args: --out ../dist working-directory: lib/ - - name: Upload sdist - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@main with: - name: sdist + name: wheels-sdist path: dist if-no-files-found: error @@ -127,7 +197,7 @@ jobs: steps: - name: Checkout reposistory - uses: actions/checkout@v5 + uses: actions/checkout@main - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@stable @@ -143,24 +213,27 @@ jobs: release: name: Release runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') - needs: [linux, windows, macos, sdist] - strategy: - fail-fast: false + if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} + needs: [linux, musllinux, windows, macos, sdist, check_clippy_python_bindings] + permissions: + # Use to sign the release artifacts + id-token: write + # Used to upload release artifacts + contents: write + # Used to generate artifact attestation + attestations: write steps: - uses: actions/download-artifact@v4 + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v2 with: - pattern: wheels-* - merge-multiple: true - - uses: actions/download-artifact@v4 - with: - name: sdist - merge-multiple: true + subject-path: 'wheels-*/*' - name: Publish to PyPI + if: ${{ startsWith(github.ref, 'refs/tags/') }} uses: PyO3/maturin-action@v1 env: PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1 MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_PASSWORD }} with: command: upload - args: --non-interactive --skip-existing * + args: --non-interactive --skip-existing wheels-*/* diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 305e42f..b0efdf6 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -5,15 +5,28 @@ on: [push, pull_request] jobs: checks: + name: mypy Python ${{ matrix.py_version }} runs-on: ubuntu-latest - name: mypy + strategy: + fail-fast: false + matrix: + py_version: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + - '3.13' + - '3.14' + - '3.x' # Explicit latest + steps: - uses: actions/checkout@v5 - - name: Set up Python 3.9 - uses: actions/setup-python@v5 + - name: Set up Python ${{ matrix.py_version }} + uses: actions/setup-python@v6 with: - python-version: 3.9 + python-version: ${{ matrix.py_version }} - name: Install Dependencies run: | diff --git a/.github/workflows/python_bindings.yml b/.github/workflows/python_bindings.yml index 73a451b..46473e2 100644 --- a/.github/workflows/python_bindings.yml +++ b/.github/workflows/python_bindings.yml @@ -5,21 +5,37 @@ on: [push, pull_request] jobs: tests_cases: - name: Tests cases + name: Test for Python ${{ matrix.py_version }} runs-on: ubuntu-latest strategy: fail-fast: false + matrix: + py_version: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + - '3.13' + - '3.14' + - '3.x' # Explicit latest steps: - - name: Checkout repo - uses: actions/checkout@v5 + - name: Checkout repo + uses: actions/checkout@v5 - - name: Setup requirements - run: | - python3 -m pip install -U maturin + - name: Setup Python ${{ matrix.py_version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.py_version }} - - name: Install local crunch64 - run: python3 -m pip install ./lib + - name: Setup requirements + run: | + python3 --version + python3 -m pip install -U maturin - - name: Run tests - run: python3 ./python_bindings/tests.py + - name: Install local crunch64 + run: python3 -m pip install ./lib + + - name: Run tests + run: python3 ./python_bindings/tests.py diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 881ab9b..fdbd987 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -62,3 +62,17 @@ jobs: # To find current MSRV use `cargo msrv find`. Install it with `cargo install cargo-msrv --locked` - name: Run MSRV checker run: cargo hack check --rust-version --workspace --all-targets --ignore-private + + msrv_no_default: + name: Check MSRV + runs-on: ubuntu-latest + steps: + - name: Checkout reposistory + uses: actions/checkout@v5 + + - name: Setup MSRV checker + uses: taiki-e/install-action@cargo-hack + + # To find current MSRV use `cargo msrv find`. Install it with `cargo install cargo-msrv --locked` + - name: Run MSRV checker + run: cargo hack check --rust-version --workspace --all-targets --ignore-private --no-default-features diff --git a/CHANGELOG.md b/CHANGELOG.md index 684d57f..db45233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.6.0] - 2025-10-11 + +### Added + +- `no_std` support. + - `alloc` is still required. +- Prebuilt binaries for Python 3.14. +- Prebuilt binaries for Python 3.8. + +### Changed + +- Python 3.8 is supported again. + - CI allows us to build for 3.8 again. +- Change the hard requirement of Python 3.9 to just Python 3 in the package metadata. + - Note there's no official support for Python versions older than 3.8. + ## [0.5.4] - 2024-12-15 ### Fixed @@ -101,7 +117,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Python bindings. - C bindings. -[unreleased]: https://github.com/decompals/crunch64/compare/0.5.1...HEAD +[unreleased]: https://github.com/decompals/crunch64/compare/0.6.0...HEAD +[0.6.0]: https://github.com/decompals/crunch64/compare/0.5.3...0.6.0 [0.5.3]: https://github.com/decompals/crunch64/compare/0.5.2...0.5.3 [0.5.2]: https://github.com/decompals/crunch64/compare/0.5.1...0.5.2 [0.5.1]: https://github.com/decompals/crunch64/compare/0.5.0...0.5.1 diff --git a/Cargo.lock b/Cargo.lock index 450a9e2..b8cd98b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ dependencies = [ [[package]] name = "crunch64" -version = "0.5.4" +version = "0.6.0" dependencies = [ "crc32fast", "pyo3", @@ -140,7 +140,7 @@ dependencies = [ [[package]] name = "crunch64-cli" -version = "0.5.4" +version = "0.6.0" dependencies = [ "clap", "crunch64", @@ -327,11 +327,10 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.23.5" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872" +checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383" dependencies = [ - "cfg-if", "indoc", "libc", "memoffset", @@ -345,19 +344,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.23.5" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb" +checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f" dependencies = [ - "once_cell", "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.23.5" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d" +checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105" dependencies = [ "libc", "pyo3-build-config", @@ -365,9 +363,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.23.5" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da" +checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -377,9 +375,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.23.5" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028" +checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf" dependencies = [ "heck", "proc-macro2", @@ -501,24 +499,24 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.16" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" [[package]] name = "thiserror" -version = "1.0.69" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.69" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1695043..b95e8ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,17 @@ [workspace] members = ["lib", "cli"] resolver = "2" + +[workspace.package] +# Version should be synced with lib/pyproject.toml and lib/crunch64/__init__.py +version = "0.6.0" +edition = "2021" +repository = "https://github.com/decompals/crunch64" +license = "MIT" + +# Use https://github.com/foresterre/cargo-msrv to check the MSRV +# ``` +# cargo install cargo-msrv --locked --force +# cargo msrv find -- cargo check -p crunch64 +# ``` +rust-version = "1.74.0" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4ebb183..46579a6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "crunch64-cli" -version = "0.5.4" -edition = "2021" +version.workspace = true +edition.workspace = true description = "A utility for compressing/decompressing files with common n64 formats" -repository = "https://github.com/decompals/crunch64" -license = "MIT" -rust-version = "1.74.0" +repository.workspace = true +license .workspace = true +rust-version.workspace = true [[bin]] name = "crunch64" path = "src/main.rs" [dependencies] -crunch64 = { version = "0.5.4", path = "../lib" } +crunch64 = { version = "0.6.0", path = "../lib" } clap = { version = "4.4.11", features = ["derive"] } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 3895fd7..8ef9595 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "crunch64" -# Version should be synced with lib/pyproject.toml and lib/crunch64/__init__.py -version = "0.5.4" -edition = "2021" +version.workspace = true +edition.workspace = true description = "A library for handling common compression formats for N64 games" -repository = "https://github.com/decompals/crunch64" -license = "MIT" -rust-version = "1.74.0" +repository.workspace = true +license.workspace = true +rust-version.workspace = true +categories = ["no-std"] [lib] name = "crunch64" @@ -15,12 +15,16 @@ crate-type = ["lib", "staticlib", "cdylib"] [dependencies] crc32fast = "1.4.2" -pyo3 = { version="0.23.5", features = ["extension-module"], optional = true } -thiserror = "1.0" +pyo3 = { version="0.26", features = ["extension-module", "abi3"], optional = true } +thiserror = { version="2", default-features = false } [dev-dependencies] rstest = "0.18.2" [features] +default = [] + +std = ["thiserror/std"] + c_bindings = [] -python_bindings = ["dep:pyo3"] +python_bindings = ["dep:pyo3", "std"] diff --git a/lib/crunch64/__init__.py b/lib/crunch64/__init__.py index 1a6a2cf..3362a43 100644 --- a/lib/crunch64/__init__.py +++ b/lib/crunch64/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations # Version should be synced with lib/Cargo.toml and lib/pyproject.toml -__version_info__ = (0, 5, 3) +__version_info__ = (0, 6, 0) __version__ = ".".join(map(str, __version_info__)) __author__ = "decompals" diff --git a/lib/pyproject.toml b/lib/pyproject.toml index 1aae951..4d1be01 100644 --- a/lib/pyproject.toml +++ b/lib/pyproject.toml @@ -1,9 +1,9 @@ [project] name = "crunch64" # Version should be synced with lib/Cargo.toml and lib/crunch64/__init__.py -version = "0.5.4" +version = "0.6.0" description = "A library for handling common compression formats for N64 games" -requires-python = ">=3.9" +requires-python = ">=3.0" dependencies = [ ] classifiers = [ diff --git a/lib/src/gzip.rs b/lib/src/gzip.rs index f106aa7..06180d4 100644 --- a/lib/src/gzip.rs +++ b/lib/src/gzip.rs @@ -5,6 +5,9 @@ // original gzip code and https://datatracker.ietf.org/doc/html/rfc1951 for // details on the DEFLATE compression format. +use alloc::{boxed::Box, vec::Vec}; +use core::cmp; + use crate::{utils, Crunch64Error}; // Bitstream writer for compressed output @@ -146,13 +149,13 @@ struct Tree { } impl Ord for Tree { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> cmp::Ordering { (self.freq, self.depth).cmp(&(other.freq, other.depth)) } } impl PartialOrd for Tree { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } @@ -253,7 +256,7 @@ impl HuffmanCode { let new_tree = Tree { root: new_node, freq: node1.freq + node2.freq, - depth: 1 + std::cmp::max(node1.depth, node2.depth), + depth: 1 + cmp::max(node1.depth, node2.depth), }; heap.replace_min(new_tree); } @@ -731,7 +734,7 @@ impl BlockWriter { } else { usize::MAX }; - let compressed_size_bytes = std::cmp::min(fixed_size_bytes, dynamic_size_bytes); + let compressed_size_bytes = cmp::min(fixed_size_bytes, dynamic_size_bytes); // Write block output.write_bits(eof as u16, 1); @@ -916,7 +919,7 @@ pub fn compress(bytes: &[u8], level: usize, small_mem: bool) -> Result .copy_from_slice(ORIGINAL_GZIP_GARBAGE); // Position in input buffer - let mut input_pos = std::cmp::min(2 * WINDOW_SIZE, input_size); + let mut input_pos = cmp::min(2 * WINDOW_SIZE, input_size); // True if we have reached the end of input let mut eof: bool = input_size < 2 * WINDOW_SIZE; // Length of current block @@ -999,7 +1002,7 @@ pub fn compress(bytes: &[u8], level: usize, small_mem: bool) -> Result } } - best_len = std::cmp::min(best_len, lookahead); + best_len = cmp::min(best_len, lookahead); if best_len == MIN_MATCH && pos - best_pos > TOO_FAR { best_len = MIN_MATCH - 1; } @@ -1080,7 +1083,7 @@ pub fn compress(bytes: &[u8], level: usize, small_mem: bool) -> Result } let refill_start = input_pos; - let refill_end = std::cmp::min(refill_start + WINDOW_SIZE, input_size); + let refill_end = cmp::min(refill_start + WINDOW_SIZE, input_size); let refill_size = refill_end - refill_start; window[WINDOW_SIZE..WINDOW_SIZE + refill_size] .copy_from_slice(&bytes[refill_start..refill_end]); @@ -1112,7 +1115,7 @@ pub fn compress(bytes: &[u8], level: usize, small_mem: bool) -> Result #[cfg(feature = "c_bindings")] mod c_bindings { - use std::ffi::c_int; + use core::ffi::c_int; #[no_mangle] pub extern "C" fn crunch64_gzip_compress_bound( @@ -1189,6 +1192,7 @@ pub(crate) mod python_bindings { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use crate::Crunch64Error; use core::panic; diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 3f5036f..bb38bd1 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,3 +1,8 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +#[macro_use] +extern crate alloc; + pub mod gzip; pub mod mio0; pub mod yay0; diff --git a/lib/src/mio0.rs b/lib/src/mio0.rs index 21cd380..0561b89 100644 --- a/lib/src/mio0.rs +++ b/lib/src/mio0.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, vec::Vec}; + use crate::{utils, Crunch64Error}; fn parse_header(bytes: &[u8]) -> Result<(usize, usize, usize), Crunch64Error> { @@ -304,6 +306,7 @@ pub(crate) mod python_bindings { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use crate::Crunch64Error; use core::panic; diff --git a/lib/src/utils.rs b/lib/src/utils.rs index c59d241..7cf045d 100644 --- a/lib/src/utils.rs +++ b/lib/src/utils.rs @@ -1,4 +1,4 @@ -use std::cmp; +use core::cmp; use crate::Crunch64Error; @@ -36,12 +36,12 @@ pub fn read_u32(bytes: &[u8], offset: usize) -> Result { pub(crate) fn u8_vec_from_pointer_array( src_len: usize, src: *const u8, -) -> Result, Crunch64Error> { +) -> Result, Crunch64Error> { if src.is_null() { return Err(Crunch64Error::NullPointer); } - let mut bytes = Vec::with_capacity(src_len); + let mut bytes = alloc::vec::Vec::with_capacity(src_len); for i in 0..src_len { bytes.push(unsafe { *src.add(i) }); diff --git a/lib/src/yay0.rs b/lib/src/yay0.rs index c27544a..379b4d9 100644 --- a/lib/src/yay0.rs +++ b/lib/src/yay0.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, vec::Vec}; + use crate::{utils, Crunch64Error}; fn parse_header(bytes: &[u8]) -> Result<(usize, usize, usize), Crunch64Error> { @@ -317,6 +319,7 @@ pub(crate) mod python_bindings { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use crate::Crunch64Error; use core::panic; diff --git a/lib/src/yaz0.rs b/lib/src/yaz0.rs index 9ec6fce..59bb098 100644 --- a/lib/src/yaz0.rs +++ b/lib/src/yaz0.rs @@ -1,5 +1,7 @@ // Based on https://gist.github.com/Mr-Wiseguy/6cca110d74b32b5bb19b76cfa2d7ab4f +use alloc::{boxed::Box, vec::Vec}; + use crate::{utils, Crunch64Error}; fn parse_header(bytes: &[u8]) -> Result { @@ -305,6 +307,7 @@ pub(crate) mod python_bindings { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use crate::Crunch64Error; use core::panic; diff --git a/mypy.ini b/mypy.ini index 2145f40..31671bd 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,2 @@ [mypy] -python_version = 3.9 check_untyped_defs = True