# moq-go-ffi

Raw Go bindings for [Media over QUIC](https://datatracker.ietf.org/doc/draft-lcurley-moq-lite/), generated from [rs/moq-ffi](../../rs/moq-ffi) via [uniffi-bindgen-go](https://github.com/NordSecurity/uniffi-bindgen-go).

**Most callers want the ergonomic [`github.com/moq-dev/moq-go`](../wrapper) wrapper instead.** This module is the native foundation it builds on: it ships the prebuilt `libmoq_ffi.a` per platform and links statically through cgo. The wrapper is pure Go and depends on this module.

The published module lives at [moq-dev/moq-go-ffi](https://github.com/moq-dev/moq-go-ffi), populated by CI on every `moq-ffi-v*` tag, lockstep with the `moq-ffi` crate version. This in-tree directory is the source skeleton, not a buildable Go module on its own.

## Install

```bash
go get github.com/moq-dev/moq-go-ffi@latest
```

```go
import moqffi "github.com/moq-dev/moq-go-ffi/moq"
```

The published module ships prebuilt `libmoq_ffi.a` for `linux/amd64`, `linux/arm64`, `darwin/arm64`, and `windows/amd64`. The Darwin archive needs macOS 12.3+, since the video backend links ScreenCaptureKit. cgo selects the right archive at link time via build tags; no `LD_LIBRARY_PATH` or extra setup needed. Building requires `CGO_ENABLED=1` (the default on Unix).

## Local development

`go/scripts/check.sh` builds `moq-ffi` for the host, runs `uniffi-bindgen-go` to regenerate `moq.go`, stages this module plus the wrapper into `dist/`, and runs `go build`/`go vet`/`go test`. Run via `just go check`. Skips cleanly without `cargo`, `go`, or `uniffi-bindgen-go`.

Install `uniffi-bindgen-go` once:

```bash
cargo install uniffi-bindgen-go \
    --git https://github.com/NordSecurity/uniffi-bindgen-go \
    --tag v0.7.1+v0.31.0
```

## Layout

```text
go/ffi/
  go.mod              Module declaration (github.com/moq-dev/moq-go-ffi)
  moq/
    cgo.go            Per-platform cgo LDFLAGS only (committed)
    moq.go            Generated by uniffi-bindgen-go (gitignored, staged at release time)
    moq.h             Generated C header (gitignored, staged at release time)
    lib/<goos>_<goarch>/libmoq_ffi.a  (gitignored, staged at release time)
```

Compiled binaries never live in the source tree. `scripts/check.sh` stages into the gitignored `dist/` working dir under the repo root; CI does the equivalent assembly into the [moq-dev/moq-go-ffi](https://github.com/moq-dev/moq-go-ffi) mirror.

## Release

The `release-go-ffi.yml` workflow fires on every `moq-ffi-v*` tag, builds per-target static libraries, runs `uniffi-bindgen-go`, calls `go/scripts/package-ffi.sh` to assemble the module, and `go/scripts/publish-ffi.sh` to push the result to `moq-dev/moq-go-ffi` with a bare-semver tag (e.g. `v0.2.18`) lockstep with the crate. Go's module proxy picks up the new tag automatically.
