Skip to content

Commit 1f512ff

Browse files
authored
feat(napi): napi-rs binding crate skeleton (re-targets #27 against main) (#66)
Re-targets [#27](#27) against `main`. ## What happened PR #27 was stacked on PR #26's branch (`msrathore/kernel-async-public-api`). When PR #26 squash-merged into `main` (commit `f4a18ba`), PR #27's base was not re-pointed to `main`, so merging PR #27 landed its content on the now-stale `msrathore/kernel-async-public-api` branch (merge commit `b73a688`) rather than on `main`. Result: the napi-skeleton content is not on `main` despite #27 being marked as merged. ## What this PR does Cherry-picks the squash commit from #27 (`b73a688`) onto a fresh branch from current `main`. Content is identical to what #27 should have landed — same 12 files, same `+3771 / -2` line counts. ## Review history All review approval is on #27; this PR carries the identical diff. Re-review is not required but pre-commit gate has been verified: - `cargo fmt --all -- --check` — clean - `cargo clippy --all-targets --locked -- -D warnings` — clean - `cargo test --locked` — 14 / 14 pass - `cargo build --release --locked` — clean ## Stack context This is the second of an 8-PR kernel stack (PR #26 was the first; #25/#29/#28/#30/#24/#23 follow). Each subsequent PR's base will need to be updated to point at this PR's branch (`msrathore/kernel-napi-skeleton-to-main`) once it merges to main, mirroring the same re-target pattern. ## Files - `.github/workflows/napi-checks.yml` — CI workflow for the napi crate (fmt + clippy + test + release-build with `--locked`) - `Cargo.toml` — root workspace tweak so the napi sub-crate's standalone-workspace pattern works - `napi/.gitignore`, `napi/Cargo.toml`, `napi/Cargo.lock`, `napi/build.rs`, `napi/package.json` — crate manifest + napi-rs build glue - `napi/src/lib.rs` — crate root, `version()` napi export - `napi/src/error.rs` — kernel `Error` → napi `Error` envelope mapper + pyo3 field-parity guards - `napi/src/util.rs` — `guarded()` panic-catching wrapper + `panic = "abort"` compile-time guard - `napi/src/runtime.rs` — captured tokio `Handle` accessor + PERF NOTE + async-cleanup-hook TODO for PR #25 - `napi/src/logger.rs` — Round-3 logger bridge stub with inline design sketch Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent f4a18ba commit 1f512ff

12 files changed

Lines changed: 3771 additions & 2 deletions

File tree

‎.github/workflows/napi-checks.yml‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Copyright (c) 2026 Databricks, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# napi-rs sub-crate CI. The napi/ directory is a *standalone* Cargo
16+
# workspace (see napi/Cargo.toml — `[workspace] members = ["."]`)
17+
# because it pins `tls-rustls` on the kernel while the root workspace
18+
# picks `tls-native` via pyo3. Feature-unification under a single
19+
# workspace would link both TLS stacks into the resulting cdylib.
20+
#
21+
# Consequence: every cargo invocation here runs from `napi/`, not the
22+
# repo root. Lockfile drift detection uses `--locked` against
23+
# `napi/Cargo.lock` rather than the kernel's root lock.
24+
#
25+
# Path-gated on `napi/**` so this workflow fires only when the
26+
# directory or its inputs change.
27+
28+
name: napi Checks
29+
30+
on:
31+
push:
32+
branches: [main]
33+
paths:
34+
- "napi/**"
35+
# Root Cargo.toml change can affect napi via its `path = ".."`
36+
# kernel dep, so this workflow re-runs to catch mismatches.
37+
- "Cargo.toml"
38+
- ".github/workflows/napi-checks.yml"
39+
pull_request:
40+
branches: [main]
41+
paths:
42+
- "napi/**"
43+
- "Cargo.toml"
44+
- ".github/workflows/napi-checks.yml"
45+
46+
concurrency:
47+
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
48+
cancel-in-progress: true
49+
50+
permissions:
51+
contents: read
52+
53+
defaults:
54+
run:
55+
shell: bash
56+
57+
jobs:
58+
# Cheap gate job — runs once, no toolchain installs. The check-and-test
59+
# job depends on this and is skipped (no runner boot beyond the
60+
# precondition runner itself) when the napi/ sub-crate doesn't
61+
# exist. Avoids wasted setup cost on kernel-only PRs that trigger
62+
# this workflow via root Cargo.toml changes before the napi crate
63+
# has merged.
64+
precondition:
65+
name: "Check napi/ sub-crate exists"
66+
runs-on:
67+
group: databricks-protected-runner-group
68+
labels: linux-ubuntu-latest
69+
outputs:
70+
ready: ${{ steps.check.outputs.ready }}
71+
steps:
72+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
73+
74+
- name: "Check for napi/Cargo.toml"
75+
id: check
76+
run: |
77+
if [[ -f "napi/Cargo.toml" ]]; then
78+
echo "ready=true" >> "$GITHUB_OUTPUT"
79+
else
80+
echo "::notice::napi/ sub-crate does not exist yet — skipping napi checks. (Workflow may fire on root Cargo.toml changes before the napi crate has merged.)"
81+
echo "ready=false" >> "$GITHUB_OUTPUT"
82+
fi
83+
84+
check-and-test:
85+
name: "napi fmt + clippy + test"
86+
needs: precondition
87+
if: needs.precondition.outputs.ready == 'true'
88+
runs-on:
89+
group: databricks-protected-runner-group
90+
labels: linux-ubuntu-latest
91+
defaults:
92+
run:
93+
# All cargo commands run from the napi/ standalone workspace.
94+
working-directory: napi
95+
steps:
96+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
97+
98+
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
99+
with:
100+
components: rustfmt, clippy
101+
102+
- name: cargo fmt --all -- --check
103+
run: cargo fmt --all -- --check
104+
105+
# `--locked` makes the build fail if `napi/Cargo.lock` is out of
106+
# sync with `napi/Cargo.toml` — catches contributors who bump a
107+
# dep version in Cargo.toml without re-running `cargo update`.
108+
# Mirrors the dual-Cargo.lock-drift concern from review.
109+
- name: cargo clippy --all-targets --locked -- -D warnings
110+
run: cargo clippy --all-targets --locked -- -D warnings
111+
112+
- name: cargo test --locked
113+
# The napi crate's Rust-side unit tests (error envelope, panic
114+
# guard, runtime handle, version) run here. No network, no
115+
# secrets — purely cdylib + rlib in-tree tests.
116+
run: cargo test --locked
117+
118+
# Release-profile build verifies the cdylib actually links with
119+
# the production profile knobs (lto=true, codegen-units=1,
120+
# strip="debuginfo"). Slower (~1m) but cheap insurance against
121+
# release-only regressions that the debug-profile `cargo test`
122+
# above wouldn't catch.
123+
- name: cargo build --release --locked
124+
run: cargo build --release --locked

‎Cargo.toml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ tls-rustls = ["reqwest/rustls-tls"]
135135
name = "databricks_sql_kernel"
136136
crate-type = ["lib", "cdylib", "staticlib"]
137137

138-
# Workspace — the kernel is the root crate; language bindings live as
139-
# sibling members. PyO3 first; napi-rs / etc. slot in here later.
138+
# Workspace — the kernel is the root crate; pyo3 is a sibling member.
139+
#
140+
# The napi binding crate (`napi/`) is deliberately NOT a member: it
141+
# uses `tls-rustls` while pyo3 uses the default `tls-native`, and a
142+
# single-workspace build would unify both kernel features and link
143+
# both TLS stacks (defeating the rustls switch — see [features]
144+
# comment above). napi declares its own `[workspace]` at `napi/Cargo.toml`
145+
# and reaches the kernel via `path = ".."`.
140146
[workspace]
141147
members = [".", "pyo3"]

‎napi/.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target/
2+
index.node
3+
*.node
4+
index.d.ts
5+
index.js

0 commit comments

Comments
 (0)