diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 523c63b..d14e38f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,11 +7,13 @@ on: - "go/**" - "include/**" - "ts/**" + - ".github/workflows/ci.yml" pull_request: paths: - "go/**" - "include/**" - "ts/**" + - ".github/workflows/ci.yml" workflow_dispatch: jobs: @@ -22,6 +24,13 @@ jobs: - uses: actions/setup-go@v5 with: go-version: "1.22" - - name: Run regression tests + - name: Verify generated Go API without CGO working-directory: go - run: CGO_ENABLED=1 go test -v ./... + env: + CGO_ENABLED: "0" + run: go test ./... + - name: Run native regression tests + working-directory: go + env: + CGO_ENABLED: "1" + run: go test -v ./... diff --git a/README.md b/README.md index 18913ca..96bdfe4 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,17 @@ CSTX (CyberSpace Topology eXchange) — 赛博空间拓扑表达协议。将安 go get github.com/chainreactors/libcstx/go ``` -Build (requires CGO for static FFI linkage): +The native `Graph`, `CASStore`, `Parse`, and `Transform` APIs require CGO. Build +consumers of those APIs with: ```bash CGO_ENABLED=1 go build ./... ``` +With `CGO_ENABLED=0`, the package only exposes the generated SCO/SRO data types +and their JSON helpers. Native graph, CAS, parsing, and transform functionality +is intentionally unavailable rather than replaced by a no-op fallback. + Cross-compile or target older Linux (avoid glibc version issues): ```bash @@ -32,6 +37,12 @@ CGO_ENABLED=1 CC="zig cc -target x86_64-linux-gnu.2.17" CXX="zig c++ -target x86 > Go + CGO 在编译时会绑定宿主系统的 glibc 版本(如 `pthread_create` 在 glibc 2.34 后从 `libpthread` 合并到 `libc.so`)。如果产物需要在较旧的 Linux 上运行,使用 [zig](https://ziglang.org/) 作为 CC 可以将 glibc 依赖锁定到指定版本。 +The bundled `libcstx_ffi.a` archives statically package the Rust FFI library, +but they do not guarantee that the final Go executable is fully static. The C +toolchain may still add a dynamic loader or shared system libraries. Scratch or +other libc-free images must use explicit external static linking and verify the +resulting ELF has neither an interpreter nor `NEEDED` entries before release. + ### Python ```bash diff --git a/go/graph_test.go b/go/graph_test.go index 7fdf715..08a0d58 100644 --- a/go/graph_test.go +++ b/go/graph_test.go @@ -1,3 +1,5 @@ +//go:build cgo + package cstx import "testing" diff --git a/go/transform.go b/go/transform.go index d2ca4e8..572a5c1 100644 --- a/go/transform.go +++ b/go/transform.go @@ -1,3 +1,5 @@ +//go:build cgo + package cstx import (