mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
Adds a standalone IPC example: the library serving itself over a CBOR socket. examples/timer/ipc_chronos/serve.nim compiles into libmy_timer only under -d:ffiIpcServe (every other build untouched) and runs a chronos socket server that, per request, decodes CBOR at the socket edge and calls the library's own async procs directly — native, in-process, zero serialization between the socket and the logic, no FFI boundary, no callback bridge. Exposed as my_timer_serve(address). CBOR (not the native struct ABI) is correct at the wire here: a relay's data is serialized regardless, so native would only relocate the decode and add marshalling for no gain — native locally, CBOR for IPC. serve_host.nim starts it; client.nim is a lib-free chronos client. Both use chronos sockets, so the example builds and runs on Linux, macOS and Windows over TCP (unix sockets are a POSIX bonus). CI: tests/e2e/ipc/run_roundtrip.nim builds the dylib + host + client, spawns the server and round-trips over loopback TCP asserting the replies; wired as `nimble test_ipc` and a 3-OS CI matrix (ubuntu/macos/windows). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
291 lines
9.4 KiB
YAML
291 lines
9.4 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [master, main]
|
|
pull_request:
|
|
branches: [master, main]
|
|
|
|
jobs:
|
|
# Single source of truth for Nim / Nimble versions used by every job and
|
|
# every reusable workflow below. Values live in versions.env at the repo
|
|
# root so they're greppable and editable in one place, next to ffi.nimble.
|
|
# The job exposes them as outputs because the `with:` of a reusable-workflow
|
|
# call only accepts the `needs`, `inputs`, `vars`, and `github` contexts —
|
|
# `env` is not allowed there, which rules out plain workflow-level env vars.
|
|
versions:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
nim-versions: ${{ steps.load.outputs.NIM_VERSIONS }}
|
|
nimble: ${{ steps.load.outputs.NIMBLE_VERSION }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- id: load
|
|
run: cat versions.env >> "$GITHUB_OUTPUT"
|
|
|
|
alloc:
|
|
name: Alloc
|
|
needs: versions
|
|
uses: ./.github/workflows/test.yml
|
|
with:
|
|
test: test_alloc
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
ffi-context:
|
|
name: FFI Context
|
|
needs: versions
|
|
uses: ./.github/workflows/test.yml
|
|
with:
|
|
test: test_ffi_context
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
gc-compat:
|
|
name: GC Compatibility
|
|
needs: versions
|
|
uses: ./.github/workflows/test.yml
|
|
with:
|
|
test: test_gc_compat
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
serial:
|
|
name: Serial
|
|
needs: versions
|
|
uses: ./.github/workflows/test.yml
|
|
with:
|
|
test: test_serial
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
ctx-validation:
|
|
name: Context Validation
|
|
needs: versions
|
|
uses: ./.github/workflows/test.yml
|
|
with:
|
|
test: test_ctx_validation
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
cpp-e2e:
|
|
# Codegen output doesn't vary with mm, so we matrix over OS and Nim only.
|
|
# Windows runs MSVC by default and may surface codegen tweaks needed in
|
|
# the generated CMake (e.g. /EHsc, dllexport) — track follow-ups as bugs
|
|
# if they appear. `fail-fast: false` keeps Linux/macOS results visible.
|
|
needs: versions
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-22.04, macos-15, windows-latest]
|
|
nim-version: ${{ fromJSON(needs.versions.outputs.nim-versions) }}
|
|
include:
|
|
- os: ubuntu-22.04
|
|
label: Linux
|
|
- os: macos-15
|
|
label: macOS
|
|
- os: windows-latest
|
|
label: Windows
|
|
runs-on: ${{ matrix.os }}
|
|
name: C++ E2E · ${{ matrix.label }} · Nim ${{ matrix.nim-version }}
|
|
env:
|
|
NIMBLE_VERSION: ${{ needs.versions.outputs.nimble }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Nim
|
|
uses: jiro4989/setup-nim-action@v2
|
|
with:
|
|
nim-version: ${{ matrix.nim-version }}
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Install Nimble ${{ env.NIMBLE_VERSION }}
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$PATH"
|
|
fi
|
|
cd /tmp && nimble install "nimble@${{ env.NIMBLE_VERSION }}" -y
|
|
echo "$HOME/.nimble/bin" >> $GITHUB_PATH
|
|
|
|
- name: Cache nimble deps
|
|
id: cache-nimbledeps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
nimbledeps/
|
|
nimble.paths
|
|
key: ${{ runner.os }}-nimbledeps-${{ matrix.nim-version }}-${{ hashFiles('*.nimble') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nimbledeps-${{ matrix.nim-version }}-
|
|
${{ runner.os }}-nimbledeps-
|
|
|
|
- name: Install nimble deps
|
|
if: steps.cache-nimbledeps.outputs.cache-hit != 'true'
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH"
|
|
fi
|
|
nimble setup --localdeps -y
|
|
|
|
- name: Cache CMake FetchContent (GoogleTest)
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: tests/e2e/cpp/build/_deps
|
|
key: ${{ runner.os }}-cpp-e2e-deps-${{ hashFiles('tests/e2e/cpp/CMakeLists.txt') }}
|
|
|
|
- name: Run C++ e2e tests
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH"
|
|
fi
|
|
nimble test_cpp_e2e -y
|
|
|
|
check-bindings:
|
|
name: Check generated bindings
|
|
needs: versions
|
|
# Codegen output is platform-independent — single OS is enough. Matrix
|
|
# over Nim versions to catch any version-sensitive output. Catches the
|
|
# class of drift surfaced in PR #39 (C++ regen committed, Rust
|
|
# overlooked); see `nimble check_bindings` in ffi.nimble.
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
nim-version: ${{ fromJSON(needs.versions.outputs.nim-versions) }}
|
|
runs-on: ubuntu-22.04
|
|
env:
|
|
NIMBLE_VERSION: ${{ needs.versions.outputs.nimble }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Nim
|
|
uses: jiro4989/setup-nim-action@v2
|
|
with:
|
|
nim-version: ${{ matrix.nim-version }}
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Install Nimble ${{ env.NIMBLE_VERSION }}
|
|
run: |
|
|
cd /tmp && nimble install "nimble@${{ env.NIMBLE_VERSION }}" -y
|
|
echo "$HOME/.nimble/bin" >> $GITHUB_PATH
|
|
|
|
- name: Cache nimble deps
|
|
id: cache-nimbledeps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
nimbledeps/
|
|
nimble.paths
|
|
key: ${{ runner.os }}-nimbledeps-${{ matrix.nim-version }}-${{ hashFiles('*.nimble') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nimbledeps-${{ matrix.nim-version }}-
|
|
${{ runner.os }}-nimbledeps-
|
|
|
|
- name: Install nimble deps
|
|
if: steps.cache-nimbledeps.outputs.cache-hit != 'true'
|
|
run: nimble setup --localdeps -y
|
|
|
|
- name: Verify checked-in bindings match generator output
|
|
run: nimble check_bindings -y
|
|
|
|
tests-asan-ubsan:
|
|
name: Tests · ASan+UBSan+LSan
|
|
needs: versions
|
|
uses: ./.github/workflows/tests-sanitized.yml
|
|
with:
|
|
sanitizer: asan-ubsan
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
tests-tsan:
|
|
name: Tests · TSan
|
|
needs: versions
|
|
uses: ./.github/workflows/tests-sanitized.yml
|
|
with:
|
|
sanitizer: tsan
|
|
nim-versions: ${{ needs.versions.outputs.nim-versions }}
|
|
nimble-version: ${{ needs.versions.outputs.nimble }}
|
|
|
|
ipc:
|
|
# In-library CBOR serve over a socket — must build and round-trip on all
|
|
# three platforms (TCP is the portable transport). fail-fast:false keeps
|
|
# Linux/macOS results visible if Windows trips on the dylib link.
|
|
needs: versions
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-22.04, macos-15, windows-latest]
|
|
include:
|
|
- os: ubuntu-22.04
|
|
label: Linux
|
|
- os: macos-15
|
|
label: macOS
|
|
- os: windows-latest
|
|
label: Windows
|
|
runs-on: ${{ matrix.os }}
|
|
name: IPC round-trip · ${{ matrix.label }}
|
|
env:
|
|
NIMBLE_VERSION: ${{ needs.versions.outputs.nimble }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Nim
|
|
uses: jiro4989/setup-nim-action@v2
|
|
with:
|
|
nim-version: "2.2.4"
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Install Nimble ${{ env.NIMBLE_VERSION }}
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$PATH"
|
|
fi
|
|
cd /tmp && nimble install "nimble@${{ env.NIMBLE_VERSION }}" -y
|
|
echo "$HOME/.nimble/bin" >> $GITHUB_PATH
|
|
|
|
- name: Cache nimble deps
|
|
id: cache-nimbledeps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
nimbledeps/
|
|
nimble.paths
|
|
key: ${{ runner.os }}-nimbledeps-2.2.4-${{ hashFiles('*.nimble') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nimbledeps-2.2.4-
|
|
${{ runner.os }}-nimbledeps-
|
|
|
|
- name: Install nimble deps
|
|
if: steps.cache-nimbledeps.outputs.cache-hit != 'true'
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH"
|
|
fi
|
|
nimble setup --localdeps -y
|
|
|
|
- name: IPC round-trip
|
|
shell: bash
|
|
run: |
|
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
|
export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH"
|
|
fi
|
|
nimble test_ipc -y
|
|
|
|
auto-assign:
|
|
name: Auto-assign PR author
|
|
if: github.event_name == 'pull_request' && github.event.action == 'opened'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- run: gh pr edit "$PR" --repo "$REPO" --add-assignee "$AUTHOR"
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
REPO: ${{ github.repository }}
|
|
PR: ${{ github.event.pull_request.number }}
|
|
AUTHOR: ${{ github.event.pull_request.user.login }}
|