From 26740b3d9ee0e427eedf67c9889db5e12e298f4a Mon Sep 17 00:00:00 2001 From: edgarriba Date: Mon, 6 Jul 2026 13:43:22 +0200 Subject: [PATCH 1/3] refactor: inline dlpack-sys into dlpack-rs; single crate, bump 0.3.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fold the `dlpack-sys` crate (bindgen bindings + vendored dlpack.h + build.rs) into `dlpack-rs` as a private `sys` module. DLPack is header-only (the FFI is pure structs/consts + fn-pointer types, no native linkage), so no `links`/ sys crate is needed. Motivation: publishing `dlpack-rs` to crates.io required its `dlpack-sys` path dep to be a published, versioned crate — but the `dlpack-sys` name is owned by an unrelated crate. Inlining removes the dependency entirely, so `dlpack-rs` (which we own on crates.io) publishes as a single self-contained crate. `cargo publish --dry-run` passes. - src/sys.rs: `include!("bindings.rs")` + ABI layout test (was dlpack-sys/lib.rs) - src/ffi.rs: re-export `crate::sys::*` instead of the `dlpack_sys` crate - build.rs + vendor/ + bindings.rs moved to crate root; `bindgen` opt-in feature - [lib] doctest = false (bindgen C doc comments carry fenced blocks) - delete dlpack-sys/; bump 0.3.2 -> 0.3.3. No public API change. Builds default + pyo3; tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- Cargo.lock | 11 ++--------- Cargo.toml | 19 +++++++++++++------ dlpack-sys/build.rs => build.rs | 0 dlpack-sys/Cargo.toml | 19 ------------------- {dlpack-sys/src => src}/bindings.rs | 0 src/ffi.rs | 8 ++++---- src/lib.rs | 1 + dlpack-sys/src/lib.rs => src/sys.rs | 6 ++++++ .../vendor => vendor}/dlpack/VENDOR.md | 0 {dlpack-sys/vendor => vendor}/dlpack/dlpack.h | 0 10 files changed, 26 insertions(+), 38 deletions(-) rename dlpack-sys/build.rs => build.rs (100%) delete mode 100644 dlpack-sys/Cargo.toml rename {dlpack-sys/src => src}/bindings.rs (100%) rename dlpack-sys/src/lib.rs => src/sys.rs (59%) rename {dlpack-sys/vendor => vendor}/dlpack/VENDOR.md (100%) rename {dlpack-sys/vendor => vendor}/dlpack/dlpack.h (100%) diff --git a/Cargo.lock b/Cargo.lock index 486963d..4c3b289 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,17 +65,10 @@ dependencies = [ [[package]] name = "dlpack-rs" -version = "0.3.2" -dependencies = [ - "dlpack-sys", - "pyo3", -] - -[[package]] -name = "dlpack-sys" -version = "0.3.2" +version = "0.3.3" dependencies = [ "bindgen", + "pyo3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5d0f815..6396e6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,26 @@ -[workspace] -members = [".", "dlpack-sys"] -resolver = "2" - [package] name = "dlpack-rs" description = "Portable Rust bindings for the DLPack protocol (FFI + safe wrappers + optional pyo3 glue)" repository = "https://github.com/kornia/dlpack-rs" -version = "0.3.2" +version = "0.3.3" license = "Apache-2.0" edition = "2021" +[lib] +# The bindgen-generated bindings carry DLPack's C doc comments; some contain +# fenced blocks that rustdoc would treat as (failing) doctests. No real +# doctests in this crate. +doctest = false + [features] default = [] pyo3 = ["dep:pyo3"] +# Regenerate src/bindings.rs from vendor/dlpack/dlpack.h (needs libclang). +# Default builds use the committed bindings — no libclang required. +bindgen = ["dep:bindgen"] [dependencies] -dlpack-sys = { path = "dlpack-sys", version = "0.3.2" } pyo3 = { version = "0.28", optional = true } + +[build-dependencies] +bindgen = { version = "0.71", optional = true } diff --git a/dlpack-sys/build.rs b/build.rs similarity index 100% rename from dlpack-sys/build.rs rename to build.rs diff --git a/dlpack-sys/Cargo.toml b/dlpack-sys/Cargo.toml deleted file mode 100644 index ece2e3a..0000000 --- a/dlpack-sys/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "dlpack-sys" -version = "0.3.2" -edition = "2021" -description = "Auto-generated FFI bindings for DLPack (dmlc/dlpack v1.3) via bindgen" -license = "Apache-2.0" -repository = "https://github.com/kornia/dlpack-rs" -links = "dlpack" - -[lib] -doctest = false - -[build-dependencies] -bindgen = { version = "0.71", optional = true } - -[features] -# default build uses the committed src/bindings.rs (no libclang needed) -default = [] -bindgen = ["dep:bindgen"] diff --git a/dlpack-sys/src/bindings.rs b/src/bindings.rs similarity index 100% rename from dlpack-sys/src/bindings.rs rename to src/bindings.rs diff --git a/src/ffi.rs b/src/ffi.rs index adb4d2d..9f3598c 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -1,7 +1,7 @@ -//! Re-export of auto-generated DLPack FFI bindings from `dlpack-sys`. +//! Re-export of auto-generated DLPack FFI bindings from the inlined `sys` module. //! The bindgen-generated types replace the former hand-written structs. #[allow(unused_imports)] -pub use dlpack_sys::*; +pub use crate::sys::*; // ── Stable public aliases ────────────────────────────────────────────────────── // These insulate consumers from bindgen naming (DLDeviceType::kDLCPU, etc.) and @@ -30,7 +30,7 @@ pub const K_DL_FLOAT: u8 = DLDataTypeCode::kDLFloat as u8; pub const K_DL_BOOL: u8 = DLDataTypeCode::kDLBool as u8; /// Read-only bitmask for `DLManagedTensorVersioned::flags` (u64). -pub const DLPACK_FLAG_BITMASK_READ_ONLY: u64 = dlpack_sys::DLPACK_FLAG_BITMASK_READ_ONLY as u64; +pub const DLPACK_FLAG_BITMASK_READ_ONLY: u64 = crate::sys::DLPACK_FLAG_BITMASK_READ_ONLY as u64; /// Is-copied bitmask for `DLManagedTensorVersioned::flags` (u64). -pub const DLPACK_FLAG_BITMASK_IS_COPIED: u64 = dlpack_sys::DLPACK_FLAG_BITMASK_IS_COPIED as u64; +pub const DLPACK_FLAG_BITMASK_IS_COPIED: u64 = crate::sys::DLPACK_FLAG_BITMASK_IS_COPIED as u64; diff --git a/src/lib.rs b/src/lib.rs index 9224252..24c410c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ //! Portable DLPack bindings: raw FFI ([`ffi`]), safe builders ([`safe`]), //! and optional pyo3 capsule glue (feature `pyo3`). +mod sys; pub mod ffi; #[cfg(feature = "pyo3")] pub mod pyo3_glue; diff --git a/dlpack-sys/src/lib.rs b/src/sys.rs similarity index 59% rename from dlpack-sys/src/lib.rs rename to src/sys.rs index 60d98a4..0d612af 100644 --- a/dlpack-sys/src/lib.rs +++ b/src/sys.rs @@ -1,9 +1,15 @@ +//! Auto-generated DLPack FFI bindings (rust-bindgen from `vendor/dlpack/dlpack.h`). +//! +//! Formerly the separate `dlpack-rs-sys` crate; inlined here so `dlpack-rs` +//! publishes to crates.io as a single crate (no sys crate to publish). +//! Regenerate `bindings.rs` with `--features bindgen` (needs libclang). #![allow( non_upper_case_globals, non_camel_case_types, non_snake_case, dead_code )] + include!("bindings.rs"); #[cfg(test)] diff --git a/dlpack-sys/vendor/dlpack/VENDOR.md b/vendor/dlpack/VENDOR.md similarity index 100% rename from dlpack-sys/vendor/dlpack/VENDOR.md rename to vendor/dlpack/VENDOR.md diff --git a/dlpack-sys/vendor/dlpack/dlpack.h b/vendor/dlpack/dlpack.h similarity index 100% rename from dlpack-sys/vendor/dlpack/dlpack.h rename to vendor/dlpack/dlpack.h From 71d201b62cab6accc8794803285473ab42f3abfb Mon Sep 17 00:00:00 2001 From: edgarriba Date: Mon, 6 Jul 2026 13:50:14 +0200 Subject: [PATCH 2/3] ci: fix regenerate-check for single-crate layout; add guarded release workflow - regenerate-check: cargo build --features bindgen (was -p dlpack-sys); diff src/bindings.rs (was dlpack-sys/src/bindings.rs) after the inline. - add release.yml: workflow_dispatch, guarded by typing 'publish', runs cargo publish for dlpack-rs using the repo's CARGO_REGISTRY_TOKEN secret. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/ci.yml | 4 ++-- .github/workflows/release.yml | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edbccd5..67e1495 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,6 @@ jobs: - name: Install libclang run: sudo apt-get update && sudo apt-get install -y libclang-dev clang - name: Regenerate bindings - run: cargo build -p dlpack-sys --features bindgen + run: cargo build --features bindgen - name: Check committed bindings are up to date - run: git diff --exit-code dlpack-sys/src/bindings.rs + run: git diff --exit-code src/bindings.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4232000 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Release + +on: + workflow_dispatch: + inputs: + confirm: + description: 'Type "publish" to confirm — this publishes dlpack-rs to crates.io and is irreversible' + required: true + default: '' + +permissions: + contents: read + +jobs: + publish: + name: cargo publish dlpack-rs + runs-on: ubuntu-latest + steps: + - name: Guard — require explicit confirmation + env: + CONFIRM: ${{ inputs.confirm }} + run: | + if [ "$CONFIRM" != "publish" ]; then + echo "::error::Confirmation field must be exactly 'publish' (got: '$CONFIRM')" + echo "::error::This workflow publishes to crates.io and is irreversible." + exit 1 + fi + + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + + - name: cargo publish --dry-run + run: cargo publish --dry-run + + - name: cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: cargo publish From f32af40515cfa3962cd750cc1f9557ac9a350ec7 Mon Sep 17 00:00:00 2001 From: edgarriba Date: Mon, 6 Jul 2026 13:51:38 +0200 Subject: [PATCH 3/3] =?UTF-8?q?style:=20rustfmt=20=E2=80=94=20order=20mod?= =?UTF-8?q?=20declarations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 24c410c..5f1469f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! Portable DLPack bindings: raw FFI ([`ffi`]), safe builders ([`safe`]), //! and optional pyo3 capsule glue (feature `pyo3`). -mod sys; pub mod ffi; #[cfg(feature = "pyo3")] pub mod pyo3_glue; pub mod safe; +mod sys;