Skip to content

Commit 13cfa70

Browse files
edgarribaclaude
andauthored
refactor: inline dlpack-sys into dlpack-rs; single publishable crate 0.3.3 (#8)
* refactor: inline dlpack-sys into dlpack-rs; single crate, bump 0.3.3 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) <noreply@anthropic.com> * 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) <noreply@anthropic.com> * style: rustfmt — order mod declarations Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0f2e2a2 commit 13cfa70

12 files changed

Lines changed: 66 additions & 40 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ jobs:
8484
- name: Install libclang
8585
run: sudo apt-get update && sudo apt-get install -y libclang-dev clang
8686
- name: Regenerate bindings
87-
run: cargo build -p dlpack-sys --features bindgen
87+
run: cargo build --features bindgen
8888
- name: Check committed bindings are up to date
89-
run: git diff --exit-code dlpack-sys/src/bindings.rs
89+
run: git diff --exit-code src/bindings.rs

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
confirm:
7+
description: 'Type "publish" to confirm — this publishes dlpack-rs to crates.io and is irreversible'
8+
required: true
9+
default: ''
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
publish:
16+
name: cargo publish dlpack-rs
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Guard — require explicit confirmation
20+
env:
21+
CONFIRM: ${{ inputs.confirm }}
22+
run: |
23+
if [ "$CONFIRM" != "publish" ]; then
24+
echo "::error::Confirmation field must be exactly 'publish' (got: '$CONFIRM')"
25+
echo "::error::This workflow publishes to crates.io and is irreversible."
26+
exit 1
27+
fi
28+
29+
- uses: actions/checkout@v4
30+
- uses: dtolnay/rust-toolchain@stable
31+
32+
- name: cargo publish --dry-run
33+
run: cargo publish --dry-run
34+
35+
- name: cargo publish
36+
env:
37+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
38+
run: cargo publish

Cargo.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
[workspace]
2-
members = [".", "dlpack-sys"]
3-
resolver = "2"
4-
51
[package]
62
name = "dlpack-rs"
73
description = "Portable Rust bindings for the DLPack protocol (FFI + safe wrappers + optional pyo3 glue)"
84
repository = "https://github.com/kornia/dlpack-rs"
9-
version = "0.3.2"
5+
version = "0.3.3"
106
license = "Apache-2.0"
117
edition = "2021"
128

9+
[lib]
10+
# The bindgen-generated bindings carry DLPack's C doc comments; some contain
11+
# fenced blocks that rustdoc would treat as (failing) doctests. No real
12+
# doctests in this crate.
13+
doctest = false
14+
1315
[features]
1416
default = []
1517
pyo3 = ["dep:pyo3"]
18+
# Regenerate src/bindings.rs from vendor/dlpack/dlpack.h (needs libclang).
19+
# Default builds use the committed bindings — no libclang required.
20+
bindgen = ["dep:bindgen"]
1621

1722
[dependencies]
18-
dlpack-sys = { path = "dlpack-sys", version = "0.3.2" }
1923
pyo3 = { version = "0.28", optional = true }
24+
25+
[build-dependencies]
26+
bindgen = { version = "0.71", optional = true }
File renamed without changes.

dlpack-sys/Cargo.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Re-export of auto-generated DLPack FFI bindings from `dlpack-sys`.
1+
//! Re-export of auto-generated DLPack FFI bindings from the inlined `sys` module.
22
//! The bindgen-generated types replace the former hand-written structs.
33
#[allow(unused_imports)]
4-
pub use dlpack_sys::*;
4+
pub use crate::sys::*;
55

66
// ── Stable public aliases ──────────────────────────────────────────────────────
77
// These insulate consumers from bindgen naming (DLDeviceType::kDLCPU, etc.) and
@@ -30,7 +30,7 @@ pub const K_DL_FLOAT: u8 = DLDataTypeCode::kDLFloat as u8;
3030
pub const K_DL_BOOL: u8 = DLDataTypeCode::kDLBool as u8;
3131

3232
/// Read-only bitmask for `DLManagedTensorVersioned::flags` (u64).
33-
pub const DLPACK_FLAG_BITMASK_READ_ONLY: u64 = dlpack_sys::DLPACK_FLAG_BITMASK_READ_ONLY as u64;
33+
pub const DLPACK_FLAG_BITMASK_READ_ONLY: u64 = crate::sys::DLPACK_FLAG_BITMASK_READ_ONLY as u64;
3434

3535
/// Is-copied bitmask for `DLManagedTensorVersioned::flags` (u64).
36-
pub const DLPACK_FLAG_BITMASK_IS_COPIED: u64 = dlpack_sys::DLPACK_FLAG_BITMASK_IS_COPIED as u64;
36+
pub const DLPACK_FLAG_BITMASK_IS_COPIED: u64 = crate::sys::DLPACK_FLAG_BITMASK_IS_COPIED as u64;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod ffi;
44
#[cfg(feature = "pyo3")]
55
pub mod pyo3_glue;
66
pub mod safe;
7+
mod sys;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
//! Auto-generated DLPack FFI bindings (rust-bindgen from `vendor/dlpack/dlpack.h`).
2+
//!
3+
//! Formerly the separate `dlpack-rs-sys` crate; inlined here so `dlpack-rs`
4+
//! publishes to crates.io as a single crate (no sys crate to publish).
5+
//! Regenerate `bindings.rs` with `--features bindgen` (needs libclang).
16
#![allow(
27
non_upper_case_globals,
38
non_camel_case_types,
49
non_snake_case,
510
dead_code
611
)]
12+
713
include!("bindings.rs");
814

915
#[cfg(test)]

0 commit comments

Comments
 (0)