From 772cf77dcc2347ce4740cb3461e9eaec236c75f5 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 2 Feb 2024 17:18:39 +0100 Subject: [PATCH] Fix build and test on darwin Signed-off-by: Evan Lezar --- Makefile | 16 ++++++++++------ internal/cuda/cuda.go | 3 ++- internal/dxcore/dxcore.go | 4 +++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 922e4445..e232e9e9 100644 --- a/Makefile +++ b/Makefile @@ -53,22 +53,26 @@ CLI_VERSION = $(VERSION) endif CLI_VERSION_PACKAGE = github.com/NVIDIA/nvidia-container-toolkit/internal/info -GOOS ?= linux - binaries: cmds ifneq ($(PREFIX),) cmd-%: COMMAND_BUILD_OPTIONS = -o $(PREFIX)/$(*) endif cmds: $(CMD_TARGETS) + +ifneq ($(shell uname),Darwin) +EXTLDFLAGS = -Wl,--export-dynamic -Wl,--unresolved-symbols=ignore-in-object-files +else +EXTLDFLAGS = -Wl,-undefined,dynamic_lookup +endif $(CMD_TARGETS): cmd-%: - GOOS=$(GOOS) go build -ldflags "-extldflags=-Wl,-z,lazy -s -w -X $(CLI_VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) -X $(CLI_VERSION_PACKAGE).version=$(CLI_VERSION)" $(COMMAND_BUILD_OPTIONS) $(MODULE)/cmd/$(*) + go build -ldflags "-s -w '-extldflags=$(EXTLDFLAGS)' -X $(CLI_VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) -X $(CLI_VERSION_PACKAGE).version=$(CLI_VERSION)" $(COMMAND_BUILD_OPTIONS) $(MODULE)/cmd/$(*) build: - GOOS=$(GOOS) go build ./... + go build ./... examples: $(EXAMPLE_TARGETS) $(EXAMPLE_TARGETS): example-%: - GOOS=$(GOOS) go build ./examples/$(*) + go build ./examples/$(*) all: check test build binary check: $(CHECK_TARGETS) @@ -100,7 +104,7 @@ coverage: test generate: go generate $(MODULE)/... -$(DOCKER_TARGETS): docker-%: +$(DOCKER_TARGETS): docker-%: @echo "Running 'make $(*)' in container image $(BUILDIMAGE)" $(DOCKER) run \ --rm \ diff --git a/internal/cuda/cuda.go b/internal/cuda/cuda.go index 2c70a821..5e8b96c2 100644 --- a/internal/cuda/cuda.go +++ b/internal/cuda/cuda.go @@ -23,7 +23,8 @@ import ( ) /* -#cgo LDFLAGS: -Wl,--unresolved-symbols=ignore-in-object-files +#cgo linux LDFLAGS: -Wl,--export-dynamic -Wl,--unresolved-symbols=ignore-in-object-files +#cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup #ifdef _WIN32 #define CUDAAPI __stdcall diff --git a/internal/dxcore/dxcore.go b/internal/dxcore/dxcore.go index 76cc53f8..cbac0141 100644 --- a/internal/dxcore/dxcore.go +++ b/internal/dxcore/dxcore.go @@ -17,7 +17,9 @@ package dxcore /* -#cgo LDFLAGS: -Wl,--unresolved-symbols=ignore-in-object-files +#cgo linux LDFLAGS: -Wl,--export-dynamic -Wl,--unresolved-symbols=ignore-in-object-files +#cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup + #include */ import "C"