Skip to content

Commit e35ddfb

Browse files
committed
Add cross-platform CI matrix and Windows loader support
1 parent 6fbb76a commit e35ddfb

7 files changed

Lines changed: 134 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-test-lint:
14+
name: Build/Test/Lint (${{ matrix.os }})
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
- macos-latest
22+
- windows-latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version-file: go.mod
32+
cache: true
33+
34+
- name: Set up Rust
35+
uses: dtolnay/rust-toolchain@stable
36+
with:
37+
components: clippy
38+
39+
- name: Cache Rust dependencies
40+
uses: Swatinem/rust-cache@v2
41+
with:
42+
workspaces: "shim -> target"
43+
44+
- name: Build Rust shim (debug)
45+
working-directory: shim
46+
run: cargo build --locked
47+
48+
- name: Run Go tests
49+
shell: pwsh
50+
run: |
51+
$libName = switch ("${{ runner.os }}") {
52+
"Linux" { "libchroma_go_shim.so" }
53+
"macOS" { "libchroma_go_shim.dylib" }
54+
"Windows" { "chroma_go_shim.dll" }
55+
default { throw "Unsupported OS: ${{ runner.os }}" }
56+
}
57+
58+
$env:CHROMA_LIB_PATH = [System.IO.Path]::GetFullPath((Join-Path $env:GITHUB_WORKSPACE "shim/target/debug/$libName"))
59+
Write-Host "CHROMA_LIB_PATH=$env:CHROMA_LIB_PATH"
60+
go test -v ./...
61+
62+
- name: Run Go lint
63+
uses: golangci/golangci-lint-action@v8
64+
with:
65+
version: latest
66+
args: --timeout=30m ./...
67+
68+
- name: Run Rust lint
69+
working-directory: shim
70+
run: cargo clippy --locked -- -D warnings

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ make test-all # Run both Go and Rust tests
185185
make test-release # Run Go tests with release build
186186
```
187187

188+
## CI
189+
190+
GitHub Actions runs a cross-platform matrix (`ubuntu-latest`, `macos-latest`, `windows-latest`) on pushes to `main` and pull requests. Each matrix job runs:
191+
192+
1. `cargo build --locked` in `shim/`
193+
2. `go test -v ./...` with platform-specific `CHROMA_LIB_PATH`
194+
3. `golangci-lint run ./...`
195+
4. `cargo clippy --locked -- -D warnings` in `shim/`
196+
188197
### Benchmarks
189198

190199
```bash

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ require (
77
github.com/pkg/errors v0.9.1
88
)
99

10-
require github.com/leanovate/gopter v0.2.11
10+
require (
11+
github.com/leanovate/gopter v0.2.11
12+
golang.org/x/sys v0.6.0
13+
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
406406
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
407407
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
408408
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
409+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
409410
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
410411
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
411412
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

library.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@ package chroma
33
import (
44
"os"
55

6-
"github.com/ebitengine/purego"
76
"github.com/pkg/errors"
87
)
98

109
const envLibPath = "CHROMA_LIB_PATH"
1110

12-
func loadLibrary(path string) (uintptr, error) {
11+
func resolveLibraryPath(path string) (string, error) {
1312
if path == "" {
1413
path = os.Getenv(envLibPath)
1514
}
1615
if path == "" {
17-
return 0, errors.New("library path not specified and CHROMA_LIB_PATH not set")
16+
return "", errors.New("library path not specified and CHROMA_LIB_PATH not set")
1817
}
19-
20-
libHandle, err := purego.Dlopen(path, purego.RTLD_NOW|purego.RTLD_GLOBAL)
21-
if err != nil || libHandle == 0 {
22-
return 0, errors.Wrapf(err, "failed to load library: %s", path)
23-
}
24-
return libHandle, nil
18+
return path, nil
2519
}

library_unix.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !windows
2+
3+
package chroma
4+
5+
import (
6+
"github.com/ebitengine/purego"
7+
"github.com/pkg/errors"
8+
)
9+
10+
func loadLibrary(path string) (uintptr, error) {
11+
resolvedPath, err := resolveLibraryPath(path)
12+
if err != nil {
13+
return 0, err
14+
}
15+
16+
libHandle, err := purego.Dlopen(resolvedPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
17+
if err != nil || libHandle == 0 {
18+
return 0, errors.Wrapf(err, "failed to load library: %s", resolvedPath)
19+
}
20+
return libHandle, nil
21+
}

library_windows.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build windows
2+
3+
package chroma
4+
5+
import (
6+
"golang.org/x/sys/windows"
7+
8+
"github.com/pkg/errors"
9+
)
10+
11+
func loadLibrary(path string) (uintptr, error) {
12+
resolvedPath, err := resolveLibraryPath(path)
13+
if err != nil {
14+
return 0, err
15+
}
16+
17+
handle, err := windows.LoadLibrary(resolvedPath)
18+
if err != nil {
19+
return 0, errors.Wrapf(err, "failed to load library: %s", resolvedPath)
20+
}
21+
if handle == 0 {
22+
return 0, errors.Errorf("failed to load library: %s", resolvedPath)
23+
}
24+
25+
return uintptr(handle), nil
26+
}

0 commit comments

Comments
 (0)