Skip to content

PR Description: Go SDK for BoxLite #202

Merged
DorianZheng merged 3 commits intoboxlite-ai:mainfrom
qidi1:feature/support-go-sdks
Feb 25, 2026
Merged

PR Description: Go SDK for BoxLite #202
DorianZheng merged 3 commits intoboxlite-ai:mainfrom
qidi1:feature/support-go-sdks

Conversation

@qidi1
Copy link
Copy Markdown
Contributor

@qidi1 qidi1 commented Feb 4, 2026

#198
Introduces the Go SDK, enabling Go applications to create and manage BoxLite VMs.


What's Included

Phase 1 – Foundation

  • Rust FFI bridge with global Tokio runtime
  • CGO bindings for Go–Rust interop
  • CI: Added Go linting to GitHub Actions

Phase 2 – Lifecycle Management

  • Client.CreateBox() / GetBox() / ListBoxes() / RemoveBox()
  • Box.Start() / Stop() / Info() / Close()
  • JSON-based FFI for complex types

Concurrency Design

  • Goroutine-safe: Avoided thread-local error storage; errors returned via explicit parameters
  • Async bridging: Global Tokio runtime + block_on() bridges CGO sync calls to async Rust
  • Thread-safe core: BoxliteRuntime is Send + Sync with Arc<RwLock> protection

Build System

  • Cross-platform Makefile (macOS + Linux auto-detection)
  • Static linking for Rust bridge + dynamic libkrun

Testing

cd sdks/go && make test  # PASS

Files Changed

  • sdks/go/ – New Go SDK
  • .github/workflows/lint.yml – Added Go linting

@qidi1 qidi1 force-pushed the feature/support-go-sdks branch from a5738a4 to 35a2f60 Compare February 4, 2026 04:49
@qidi1
Copy link
Copy Markdown
Contributor Author

qidi1 commented Feb 5, 2026

@DorianZheng Please have a look

@DorianZheng
Copy link
Copy Markdown
Member

@DorianZheng Please have a look

@qidi1 Sorry for the late response—I’m reviewing it now. I’m impressed that you implemented this in such a short time.

@@ -0,0 +1,360 @@
// BoxLite Go SDK - Rust Bridge Layer
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@qidi1 Do you think we can reuse the C SDK? Or can we extract common codes for both Go and C SDK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for raising this, @DorianZheng! I've been thinking about the architecture carefully.

Options Considered

Option A: Fully Reuse C SDK

Pros: Single source of truth, lower maintenance
Cons: C SDK becomes the "lowest common denominator" for all languages; changes require considering all consumers

Option B: Keep Separate (Current Implementation)

Pros: Full independence for each SDK
Cons: Duplicate FFI code, double maintenance cost, and Go's CGO goes through C ABI anyway — so the "independence" doesn't unlock much optimization

Option C: Extract a Shared FFI Core (boxlite-ffi-core)

Pros:

  • Shared logic (error handling, JSON serialization, runtime management) lives in one place
  • Each SDK can still extend with language-specific features if needed
  • Clean architectural boundary: core handles "Rust → C ABI", each SDK handles "C ABI → language wrapper"
  • Gradual evolution: if needs diverge later, we can add SDK-specific code without touching core

Cons:

  • Requires a one-time refactor to extract the core
  • Need to design the core API boundary carefully

My Preference

I lean toward Option C — extracting a boxlite-ffi-core crate.

Looking at the current code, most of it is shared logic (error handling, string helpers, JSON serialization). The extraction should be straightforward — it's mostly moving code around, no logic changes needed.

Copy link
Copy Markdown
Member

@DorianZheng DorianZheng Feb 9, 2026

Choose a reason for hiding this comment

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

@qidi1 Good analysis. I agree with you. How about just boxlite-ffi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think is good

@DorianZheng
Copy link
Copy Markdown
Member

cc @Wenrh2004. Could you take a look on this PR

@qidi1 qidi1 force-pushed the feature/support-go-sdks branch 2 times, most recently from 95f1561 to 0f904bc Compare February 24, 2026 04:25
@qidi1
Copy link
Copy Markdown
Contributor Author

qidi1 commented Feb 24, 2026

@DorianZheng @Wenrh2004 Please have a look

@qidi1 qidi1 force-pushed the feature/support-go-sdks branch 4 times, most recently from 8ccc18e to 1277212 Compare February 24, 2026 08:16
@qidi1 qidi1 force-pushed the feature/support-go-sdks branch from 1277212 to f74a7a2 Compare February 24, 2026 08:49
Copy link
Copy Markdown
Member

@DorianZheng DorianZheng left a comment

Choose a reason for hiding this comment

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

LGTM

@DorianZheng DorianZheng merged commit 0449a0a into boxlite-ai:main Feb 25, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants