Skip to content

Commit a886c3f

Browse files
authored
fix: build on macos
fix: build on macos
2 parents f1081f2 + 703180f commit a886c3f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
LIBS_DIR := $(abspath ./libs)
33

44
UNAME_S := $(shell uname -s)
5-
65
# Flags for CGO to find the headers and the shared library
76
ifeq ($(UNAME_S),Darwin)
87
CGO_CFLAGS := -I$(LIBS_DIR)
9-
CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,@executable_path/./libs
8+
CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,@executable_path/libs
109
else
1110
CGO_CFLAGS := -I$(LIBS_DIR)
1211
CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,$(LIBS_DIR)
@@ -29,9 +28,13 @@ all: run
2928

3029
fetch:
3130
@echo "Fetching libcodex from GitHub Actions: ${LATEST_URL}"
32-
@curl -fSL --create-dirs -o $(LIBS_DIR)/codex-${OS}-${ARCH}.zip ${LATEST_URL}
31+
curl -fSL --create-dirs -o $(LIBS_DIR)/codex-${OS}-${ARCH}.zip ${LATEST_URL}
3332
unzip -o -qq $(LIBS_DIR)/codex-${OS}-${ARCH}.zip -d $(LIBS_DIR)
3433
rm -f $(LIBS_DIR)/*.zip
34+
# Update the path to the shared library on macOS
35+
ifeq ($(UNAME_S),Darwin)
36+
install_name_tool -id @rpath/libcodex.dylib $(LIBS_DIR)/libcodex.dylib
37+
endif
3538

3639
build:
3740
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o $(BIN_NAME) main.go
@@ -40,6 +43,10 @@ run:
4043
ifeq ($(OS),Windows_NT)
4144
pwsh -Command "Copy-Item libs\libcodex.dll ."
4245
pwsh -Command ".\$(BIN_NAME)"
46+
else ifeq ($(UNAME_S),Darwin)
47+
# Instead of relying on install_name_tool, we can define DYLD_LIBRARY_PATH
48+
# DYLD_LIBRARY_PATH=$(LIBS_DIR) ./$(BIN_NAME)
49+
./$(BIN_NAME)
4350
else
4451
./$(BIN_NAME)
4552
endif

0 commit comments

Comments
 (0)