Skip to content

Expose Tailcat through a cancellable C-compatible shared library API - #130

Open
vvuk wants to merge 2 commits into
tailscale:mainfrom
vvuk:vlad/c-api
Open

vvuk wants to merge 2 commits into
tailscale:mainfrom
vvuk:vlad/c-api

Conversation

@vvuk

@vvuk vvuk commented Sep 22, 2026

Copy link
Copy Markdown

Yes, another C API; I became aware of #64 and #6 but I think there are two improvements here that aren't in either of those:

  1. Cancellation/deadline tokens. This API allows any operation to be cancelled from another thread.
  2. Per-operation error message returns; makes the API slightly more verbose, but ensures that errors can be connected to the operation that caused them.

I'm using this to implement a python wrapper for tailcat, as well as a httpx/httpcore transport (which I'm happy to put in here, but I think it's probably better served as a separate repo/library, like other language wrappers?)

Written mostly by Astra and a bit with Fable, reviewed by me.

Comment thread .github/workflows/test.yml Outdated
- run: go test -count=1 -timeout 600s ./...
- run: go vet ./...
- name: build libtailcat and run its C smoke test
if: runner.os != 'Windows'

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.

no Windows support, eh? That was the other thing tempering my enthusiasm for the other PRs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hm I'm actually not 100% sure why we ended up with no windows support -- I think it's mostly a toolchain issue and so should be fixable. Luckily I have lots of windows knowledge, so I can add this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a commit for windows -- it was already working, just added CI build steps and instructions.

libtailcat already builds as a DLL with MinGW-w64 gcc, Go's default
CC on Windows, but CI skipped the C smoke test there and nothing
documented how MSVC users, who cannot build the DLL themselves, link
against it.

Run the smoke test step on all three runners under bash, picking the
library suffix from the runner OS and building into a relative build/
directory so Git Bash needs no path conversion and Windows finds the
DLL next to smoke.exe. Add a Windows-only step that builds an import
library from a checked-in libtailcat.def with lib /def:, compiles the
smoke test with cl /W4 /WX, and runs it against the MinGW-built DLL.

A test in internal/capi keeps libtailcat.def, the prototypes in
tailcat.h, and the //export directives in main.go in agreement.
Document the Windows toolchain requirements and the import library
step in the libtailcat README.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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