Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 258 additions & 0 deletions .github/workflows/build-c-abi-libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# Copyright (c) 2026 Databricks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Builds the kernel C-ABI static library for every supported OS/arch on a NATIVE
# runner, checksums each one, and publishes them as workflow artifacts (and, on a
# tag, GitHub release assets).
#
# These archives are the per-platform Go bindings distributed by
# github.com/databricks/databricks-sql-kernel-bindings — that repo holds one
# nested Go module per platform (lib/<os>_<arch>/libdatabricks_sql_kernel.a), and
# the Go driver (databricks-sql-go) requires the matching module so a kernel
# opt-in `go get` build links a prebuilt archive with no Rust toolchain and no
# `make kernel-lib` step.
#
# ARTIFACT-ONLY (no automated push): this workflow only BUILDS + uploads. Getting
# the archives into the bindings repo is a deliberate maintainer step (download
# the kernel-c-abi-<platform> artifact and commit it into lib/<platform>/). No
# cross-repo token is used here.
#
# ── Runner reality in the `databricks` org (verified against databricks-odbc) ──
# The `databricks` org enforces an IP allow list, so GitHub-hosted runners CANNOT
# be used at all — they get arbitrary Azure IPs and fail `actions/checkout` with
# 403 before auth even runs (see databricks-odbc/.github/workflows/macos.yml).
# Every job here therefore runs on `databricks-protected-runner-group`. Only two
# labels exist in that group today, confirmed across databricks-odbc + this repo:
# * linux-ubuntu-latest (linux/amd64)
# * windows-server-latest (windows/amd64) — used by databricks-odbc/pr.yml
# There is NO macOS label (self-hosted macOS is expected ~Oct 2026; ODBC's
# macos.yml is dormant for the same reason) and NO arm64/Graviton label. So:
# * linux_amd64 — builds here, now.
# * windows_amd64 — builds here, now (see the Windows toolchain note below).
# * darwin_arm64 / darwin_amd64 / linux_arm64 — cannot run until the protected
# group gains macOS and arm64 labels; they are listed in the matrix but
# COMMENTED OUT so they neither fail nor post empty required checks. Uncomment
# each once its label exists (one-line change).
#
# ── Windows toolchain (UNVERIFIED — flagged, not assumed) ──────────────────────
# The Go driver links the kernel through Go cgo, which on Windows uses MinGW/gcc
# and links a GNU archive (libNAME.a), NOT an MSVC import lib (.lib). So this
# workflow builds Windows for x86_64-pc-windows-GNU. NOTE the divergence from
# databricks-odbc, which builds Windows as x86_64-pc-windows-MSVC — that is
# correct for ODBC (a C++ consumer linking with MSVC) but wrong for Go cgo.
# Whether the `windows-server-latest` protected runner has a working MinGW gcc
# for the gnu target is UNVERIFIED; the first Windows run will confirm. If MinGW
# is unavailable there, options are: install it in-job, or reconsider whether the
# Windows kernel target ships at all (the driver's cgo_windows.go notes Windows
# "is not yet exercised"). Do not assume this leg is green until CI proves it.
#
# ── Build flags ────────────────────────────────────────────────────────────────
# Explicit `--target` per leg (never host-inferred), so the output triple is
# unambiguous and lands at target/<triple>/release/libdatabricks_sql_kernel.a
# (uniform name across gnu/darwin targets). Flags mirror the driver's
# build/kernel-lib.sh exactly (`--release --locked --no-default-features
# --features tls-rustls`, pure-Rust TLS).
#
# Triggered by a `v*` tag (release path) or manual workflow_dispatch.

name: Build C-ABI Libraries

on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
upload_release:
description: "Attach archives to the GitHub release for the triggering tag (tag runs do this automatically)"
required: false
type: boolean
default: false

concurrency:
# One archive-build run per ref; a newer push supersedes an in-flight build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Least privilege at the top level; the release job elevates contents:write for
# itself only.
permissions:
contents: read

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The workflow grants only contents: read, but the final step runs gh release upload "$TAG" ... to attach archives to the GitHub release. Uploading release assets requires contents: write; with contents: read the gh release upload call will fail with a 403 on every tag build — the exact path this workflow exists to serve. Other release-oriented workflows in this repo that push/attach use contents: write (e.g. engineer-bot.yml:35, trigger-integration-tests.yml). Either bump the top-level contents to write, or (safer, least-privilege) scope contents: write to just the build job / the attach step.

Suggested change
contents: read
permissions:
contents: write


defaults:
run:
shell: bash

jobs:
build:
name: "C-ABI ${{ matrix.platform }}"
runs-on:
group: databricks-protected-runner-group
labels: [ "${{ matrix.runner_label }}" ]
permissions:
contents: read
# OIDC token exchange for the .github/actions/setup-jfrog composite (cargo
# dependency proxy). See go/hardened-gha.
id-token: write
strategy:
fail-fast: false
matrix:
include:
# platform : the GOOS_GOARCH tag the bindings repo keys off (lib/<platform>/).
# target : the explicit Rust triple we build (never host-inferred).
# runner_label : the label within databricks-protected-runner-group.
#
# Only linux_amd64 and windows_amd64 run today — those are the only
# labels the protected group has (verified against databricks-odbc). The
# macOS and arm64 legs are COMMENTED OUT because no such label exists yet
# (self-hosted macOS ~Oct 2026; no Graviton label). Uncomment each once
# its label lands in the protected group — one line, nothing else changes.
- platform: linux_amd64
runner_label: linux-ubuntu-latest
target: x86_64-unknown-linux-gnu
- platform: windows_amd64
runner_label: windows-server-latest
target: x86_64-pc-windows-gnu # MinGW .a for Go cgo — see header (UNVERIFIED)
# - platform: darwin_arm64
# runner_label: <macos-arm64-label-once-it-exists>
# target: aarch64-apple-darwin
# - platform: darwin_amd64
# runner_label: <macos-amd64-label-once-it-exists>
# target: x86_64-apple-darwin
# - platform: linux_arm64
# runner_label: <linux-arm64-label-once-it-exists>
# target: aarch64-unknown-linux-gnu
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1

- name: Configure JFrog Artifactory access (cargo proxy)
uses: ./.github/actions/setup-jfrog
with:
cargo: "true"

# Install the toolchain WITH the explicit target for this matrix entry.
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
with:
target: ${{ matrix.target }}

# Build the staticlib for the EXPLICIT target. The root Cargo.toml declares
# crate-type = [..., "staticlib"], and the lib name is databricks_sql_kernel,
# so every gnu/unix target emits `libdatabricks_sql_kernel.a`. With an
# explicit --target the output lands under target/<triple>/release/, so the
# staging step reads from there (NOT target/release/).
- name: Build C-ABI static library
run: |
cargo build --release --locked --no-default-features --features tls-rustls --target ${{ matrix.target }}

# Stage the produced archive + a SHA-256 for verification, under a
# per-platform dir. Uniform archive name across all platforms:
# libdatabricks_sql_kernel.a (guaranteed by the gnu targets above).
- name: Stage archive + checksum
run: |
set -euo pipefail
ARCHIVE="libdatabricks_sql_kernel.a"
SRC="target/${{ matrix.target }}/release/${ARCHIVE}"
OUT="dist/${{ matrix.platform }}"
mkdir -p "$OUT"
if [ ! -f "$SRC" ]; then
echo "::error::expected static archive not found at ${SRC}"
echo "contents of target/${{ matrix.target }}/release:"
ls -la "target/${{ matrix.target }}/release" || true
exit 1
fi
cp "$SRC" "$OUT/${ARCHIVE}"
# Commit the matching C header so the bindings repo can pin a header at
# the same kernel revision. It is committed at include/databricks_kernel.h.
if [ ! -f include/databricks_kernel.h ]; then
echo "::error::include/databricks_kernel.h not found (expected committed header)"
exit 1
fi
cp include/databricks_kernel.h "$OUT/databricks_kernel.h"
# SHA-256 over the archive. sha256sum exists on the Linux runners;
# shasum on macOS. Windows jobs run under Git-bash (shell: bash) which
# ships neither reliably, so fall back to Go-less openssl, which the
# runners have.
( cd "$OUT"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${ARCHIVE}" > "${ARCHIVE}.sha256"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "${ARCHIVE}" > "${ARCHIVE}.sha256"
else
openssl dgst -sha256 -r "${ARCHIVE}" > "${ARCHIVE}.sha256"
fi
echo "staged $(pwd):"
ls -la
echo "archive size: $(wc -c < "${ARCHIVE}") bytes"
cat "${ARCHIVE}.sha256"
)

- name: Upload archive artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: kernel-c-abi-${{ matrix.platform }}
path: dist/${{ matrix.platform }}/
if-no-files-found: error
retention-days: 14

# Attach every platform's archive to the GitHub release for the triggering tag.
# Separate job so it runs ONCE (not per-matrix-entry), needs all builds first,
# and is the only place that holds contents:write.
release-assets:
name: Attach archives to release
needs: build
if: startsWith(github.ref, 'refs/tags/v') || inputs.upload_release
runs-on:
group: databricks-protected-runner-group
labels: linux-ubuntu-latest
permissions:
contents: write # gh release upload
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Download all platform archives
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
pattern: kernel-c-abi-*
path: archives
# keep each artifact in its own subdir: archives/kernel-c-abi-<platform>/
merge-multiple: false

- name: Upload assets to the release
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
shopt -s nullglob
uploaded=0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — The upload step derives the release target from GITHUB_REF_NAME, but that value is only a tag on the push/v* path. The workflow_dispatch + upload_release: true branch is a documented, first-class trigger for this job (see the if: at L219 and the input at L82), yet on a manual dispatch GITHUB_REF_NAME is the branch the workflow ran on (e.g. main), not a tag. gh release upload "main" ... then fails with "release not found", so the upload_release input can never actually succeed as described — there is no way for a dispatch run to name the release/tag to attach to.

Separately, even on the tag path this assumes a GitHub Release already exists for the tag. A bare git push of a v* tag does not create a Release; gh release upload errors on a missing release rather than creating one. Unless a prior release-creation step/workflow runs first, the advertised "push a v* tag → assets attached automatically" flow will fail on its first run.

Consider: (a) gating the upload on github.ref_type == 'tag' (or adding a tag workflow_dispatch input) so a dispatch run can't target a branch name, and (b) using gh release create "$tag" ... || true before upload, or gh release upload --clobber against a release you ensure exists.

for dir in archives/kernel-c-abi-*; do
platform="${dir##*/kernel-c-abi-}"
archive="$dir/libdatabricks_sql_kernel.a"
sha="$dir/libdatabricks_sql_kernel.a.sha256"
if [ ! -f "$archive" ]; then
echo "::error::missing archive for ${platform} at ${archive}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — When triggered via workflow_dispatch with upload_release: true from a branch (the documented "run after merge" path), the release-assets job runs but tag="${GITHUB_REF_NAME}" resolves to the branch name (e.g. main), not a v* tag. gh release upload main ... will then fail because there is no release named after the branch. The upload_release dispatch option is therefore only usable when dispatching from a tag ref. Worth either guarding the job to tag refs only, or validating that $tag looks like a release tag before attempting upload.

exit 1
fi
# Namespace the asset by platform so all archives coexist on one
# release. Keep the .a extension — every platform's archive IS a .a.
asset="libdatabricks_sql_kernel-${platform}.a"
cp "$archive" "$asset"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The staged checksum file is generated over the archive named libdatabricks_sql_kernel.a (e.g. sha256sum libdatabricks_sql_kernel.a), so its contents embed that filename. When the asset is renamed to libdatabricks_sql_kernel-${platform}.a and its .sha256 uploaded alongside, the checksum file still references the old, un-namespaced name. A consumer running sha256sum -c libdatabricks_sql_kernel-<platform>.a.sha256 will fail because the filename recorded in the file no longer matches the asset on disk (the hash is still correct, but -c keys on the name). Consider regenerating/rewriting the .sha256 to reference the renamed asset, or documenting that only the hash value (not the filename) is authoritative.

cp "$sha" "${asset}.sha256"
gh release upload "$tag" "$asset" "${asset}.sha256" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — gh release upload does not create a release — it fails with release not found if one does not already exist for the tag. On a v* tag push, GitHub does not auto-create a release, and no other workflow in this repo creates one (grep for gh release/release create/action-gh-release finds only this file). So the primary release path — push a v* tag → attach archives — will fail at this step unless a maintainer manually created the release first.

The workflow_dispatch + upload_release: true path is worse: on a branch dispatch GITHUB_REF_NAME is a branch name, so gh release upload <branch> targets a nonexistent release and fails.

Consider creating (or ensuring) the release first, e.g. gh release create "$tag" --generate-notes --verify-tag || true before the upload loop, or use an action that creates-or-updates the release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — gh release upload "$tag" ... uploads assets to an existing GitHub release — it does not create one. On a v* tag push, GitHub does not auto-create a release object, and no other workflow in this repo creates one for the tag (verified: only cargo-publish.yml and this file trigger on v* tags, neither runs gh release create). So the primary trigger — a tag push — will fail this step with release not found on the first asset unless a maintainer has already created the release manually.

Consider ensuring the release exists first, e.g.:

gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1 \
  || gh release create "$tag" --repo "$GITHUB_REPOSITORY" --generate-notes --verify-tag

before the upload loop. Otherwise document that a release must be created out-of-band before this workflow runs.

--repo "$GITHUB_REPOSITORY" --clobber
uploaded=$((uploaded + 1))
done
echo "uploaded ${uploaded} platform archive(s) to release ${tag}"
Loading