diff --git a/Makefile b/Makefile index d1dcf74..b76d169 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help build test clean check fmt lint install dev docker-build docker-up docker-down official-smoke +.PHONY: help build build-ffi test clean check fmt lint install dev docker-build docker-up docker-down official-smoke # 默认目标 .DEFAULT_GOAL := help @@ -24,7 +24,11 @@ build-rust: ## 构建 Rust 组件 @echo "$(BLUE)Building Rust workspace...$(NC)" cargo build --release --workspace -build-go: ## 构建 Go 组件 +build-ffi: ## 构建 bat-ffi release 库(cgo 链接依赖) + @echo "$(BLUE)Building bat-ffi (release)...$(NC)" + cargo build --release -p bat-ffi + +build-go: build-ffi ## 构建 Go 组件 @echo "$(BLUE)Building Go CLI...$(NC)" @if [ -f cmd/bat/main.go ]; then \ go build -o bin/bat ./cmd/bat; \ @@ -50,7 +54,7 @@ test-rust: ## 运行 Rust 测试 @echo "$(BLUE)Running Rust tests...$(NC)" cargo test --workspace -test-go: ## 运行 Go 测试 +test-go: build-ffi ## 运行 Go 测试 @echo "$(BLUE)Running Go tests...$(NC)" @if [ -n "$$(go list ./... 2>/dev/null)" ]; then \ go test -v ./...; \ diff --git a/internal/ffi/ffi.go b/internal/ffi/ffi.go index f530b65..e299367 100644 --- a/internal/ffi/ffi.go +++ b/internal/ffi/ffi.go @@ -6,8 +6,10 @@ package ffi /* -#cgo CFLAGS: -I${SRCDIR}/../../target/bat-ffi -#cgo LDFLAGS: -L${SRCDIR}/../../target/debug -lbat_ffi +// Links against the release bat-ffi library built by `cargo build --release -p bat-ffi` +// (see the `build-ffi` Make target). The rpath lets the resulting binary locate +// libbat_ffi.so at runtime without setting LD_LIBRARY_PATH during local development. +#cgo LDFLAGS: -L${SRCDIR}/../../target/release -lbat_ffi -Wl,-rpath,${SRCDIR}/../../target/release #include typedef char* ccharp;