Repository navigation
ci: build per-platform C-ABI static libraries (all platforms, artifact-only) #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d9c6717
370ff9c
de8c2c9
06d73ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — The upload step derives the release target from Separately, even on the tag path this assumes a GitHub Release already exists for the tag. A bare Consider: (a) gating the upload on |
||
| 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}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — When triggered via |
||
| 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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — The staged checksum file is generated over the archive named |
||
| cp "$sha" "${asset}.sha256" | ||
| gh release upload "$tag" "$asset" "${asset}.sha256" \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — The Consider creating (or ensuring) the release first, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — 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-tagbefore 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}" | ||
There was a problem hiding this comment.
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 runsgh release upload "$TAG" ...to attach archives to the GitHub release. Uploading release assets requirescontents: write; withcontents: readthegh release uploadcall 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 usecontents: write(e.g.engineer-bot.yml:35,trigger-integration-tests.yml). Either bump the top-levelcontentstowrite, or (safer, least-privilege) scopecontents: writeto just thebuildjob / the attach step.