From e9af4238619d41dbab3edd2def78e4f0c2d1797b Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 9 Oct 2025 10:11:44 +0200 Subject: [PATCH] Use CGO_CFLAGS and CGO_LDFLAGS to build --- .github/workflows/ci.yml | 4 ++-- .vscode/settings.json | 7 +++++++ Makefile | 13 +++++++++++-- codex/bridge.h | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5f4c58..c18609d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,9 @@ jobs: - name: Build codex go run: | cd codex - go build -o codex-go + make - name: Go test env: CGO_ENABLED: 1 - run: go test ./... + run: make test diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c4036ba --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "go.toolsEnvVars": { + "CGO_CFLAGS": "-I${workspaceFolder}/vendor/nim-codex/library", + "CGO_LDFLAGS": "-L${workspaceFolder}/vendor/nim-codex/build -Wl,-rpath,${workspaceFolder}/vendor/nim-codex/build", + "LD_LIBRARY_PATH": "${workspaceFolder}/vendor/nim-codex/build:${env:LD_LIBRARY_PATH}" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index e086243..4e3125a 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ # Makefile for Codex Go Bindings NIM_CODEX_DIR := vendor/nim-codex +NIM_CODEX_LIB_DIR := $(abspath $(NIM_CODEX_DIR)/library) +NIM_CODEX_BUILD_DIR := $(abspath $(NIM_CODEX_DIR)/build) -.PHONY: all clean update build-libcodex build +CGO_CFLAGS := -I$(NIM_CODEX_LIB_DIR) +CGO_LDFLAGS := -L$(NIM_CODEX_BUILD_DIR) -Wl,-rpath,$(NIM_CODEX_BUILD_DIR) + +.PHONY: all clean update libcodex build test all: build @@ -20,7 +25,11 @@ libcodex: build: @echo "Building Codex Go Bindings..." - go build -o codex-go codex + CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o codex-go ./codex + +test: + @echo "Running tests..." + CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test ./... clean: @echo "Cleaning up..." diff --git a/codex/bridge.h b/codex/bridge.h index 3224ad1..4c6c7c9 100644 --- a/codex/bridge.h +++ b/codex/bridge.h @@ -1,6 +1,6 @@ #pragma once #include -#include "../vendor/nim-codex/library/libcodex.h" +#include "libcodex.h" extern void callback(int ret, char* msg, size_t len, void* resp); \ No newline at end of file