Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

ci(go): validate native routing bindings (#1126)

Alex Fournierb0001eaecf58
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0a91a88b4..f327f16a6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -131,6 +131,12 @@ jobs:
- name: cargo test (prefill-router)
run: cargo test -p switchyard-runner --features prefill-router --locked
+ go:
+ name: Go bindings
+ needs: changes
+ if: needs.changes.outputs.full_ci == 'true'
+ uses: ./.github/workflows/go-bindings.yml
+
node:
name: TypeScript bindings and Pi example
needs: changes
@@ -284,7 +290,7 @@ jobs:
ci-success:
name: CI Success
if: always()
- needs: [changes, lint, spdx-headers, rust, node, typecheck, test, litellm, slim-install-smoke]
+ needs: [changes, lint, spdx-headers, rust, go, node, typecheck, test, litellm, slim-install-smoke]
runs-on: ubuntu-latest
steps:
- name: Verify all jobs succeeded
diff --git a/.github/workflows/go-bindings.yml b/.github/workflows/go-bindings.yml
new file mode 100644
index 000000000..964ff0bd1
--- /dev/null
+++ b/.github/workflows/go-bindings.yml
@@ -0,0 +1,46 @@
+name: Go bindings
+
+on:
+ workflow_call:
+
+permissions:
+ contents: read
+
+jobs:
+ native:
+ name: Native (${{ matrix.os }})
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, ubuntu-24.04-arm]
+ timeout-minutes: 30
+ env:
+ CGO_ENABLED: "1"
+ GOEXPERIMENT: cgocheck2
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
+ with:
+ go-version-file: bindings/go/go.mod
+ # Go's cache does not track the external Rust library or C header.
+ cache: false
+ - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
+ with:
+ cache-bin: false
+ save-if: ${{ github.ref == 'refs/heads/main' }}
+ - name: Build switchyard-ffi
+ run: cargo build -p switchyard-ffi --release --locked
+ - name: go test (native)
+ working-directory: bindings/go
+ run: go test -count=1 -race -tags switchyard_native ./...
+ - name: go vet (native)
+ working-directory: bindings/go
+ run: go vet -tags switchyard_native ./...
+ - name: Build and run shared host
+ working-directory: bindings/go
+ run: |
+ go build -tags switchyard_native -buildmode=c-shared -o "$RUNNER_TEMP/libswitchyard_smoke.so" ./testdata/cshared
+ cc testdata/cshared.c -I "$RUNNER_TEMP" -L "$RUNNER_TEMP" \
+ -Wl,-rpath,"$RUNNER_TEMP" -lswitchyard_smoke -o "$RUNNER_TEMP/shared-host"
+ "$RUNNER_TEMP/shared-host"
diff --git a/bindings/go/testdata/cshared.c b/bindings/go/testdata/cshared.c
new file mode 100644
index 000000000..227edc152
--- /dev/null
+++ b/bindings/go/testdata/cshared.c
@@ -0,0 +1,6 @@
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "libswitchyard_smoke.h"
+
+int main(void) { return SwitchyardSmoke(); }
diff --git a/bindings/go/testdata/cshared/main.go b/bindings/go/testdata/cshared/main.go
new file mode 100644
index 000000000..3203b3f9c
--- /dev/null
+++ b/bindings/go/testdata/cshared/main.go
@@ -0,0 +1,38 @@
+//go:build cgo && switchyard_native
+
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+// A C host exercises Go routing linked with the Rust static library.
+package main
+
+import "C"
+
+import (
+ "context"
+ "encoding/json"
+ "time"
+
+ switchyard "github.com/NVIDIA-NeMo/Switchyard/bindings/go"
+)
+
+//export SwitchyardSmoke
+func SwitchyardSmoke() C.int {
+ router, err := switchyard.New(json.RawMessage(`{"algorithm":{"type":"random","targets":["target"]},"targets":{"target":"model"}}`))
+ if err != nil {
+ return 1
+ }
+ defer router.Close()
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ outcome, err := router.Route(ctx, switchyard.Input{
+ Request: json.RawMessage(`{"messages":[]}`),
+ Models: map[string][]string{"any": {"model"}},
+ }, nil)
+ if err != nil || len(outcome.SelectedModelIDs) != 1 || outcome.SelectedModelIDs[0] != "model" {
+ return 2
+ }
+ return 0
+}
+
+func main() {}