diff --git a/.github/workflows/build-c-abi-libs.yml b/.github/workflows/build-c-abi-libs.yml new file mode 100644 index 00000000..cf3371e1 --- /dev/null +++ b/.github/workflows/build-c-abi-libs.yml @@ -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/_/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- artifact and commit it into lib//). 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//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 + +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//). + # 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: + # target: aarch64-apple-darwin + # - platform: darwin_amd64 + # runner_label: + # target: x86_64-apple-darwin + # - platform: linux_arm64 + # runner_label: + # 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//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-/ + merge-multiple: false + + - name: Upload assets to the release + run: | + set -euo pipefail + tag="${GITHUB_REF_NAME}" + shopt -s nullglob + uploaded=0 + 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}" + 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" + cp "$sha" "${asset}.sha256" + gh release upload "$tag" "$asset" "${asset}.sha256" \ + --repo "$GITHUB_REPOSITORY" --clobber + uploaded=$((uploaded + 1)) + done + echo "uploaded ${uploaded} platform archive(s) to release ${tag}"