Skip to content

Commit 05847cd

Browse files
[runner] Allow to compile runner on macOS (for development purposes only) (#3276)
1 parent 8e89462 commit 05847cd

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

runner/.justfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ build-runner-binary:
4545
#!/usr/bin/env bash
4646
set -e
4747
echo "Building runner for linux/amd64"
48-
cd {{source_directory()}}/cmd/runner && GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
48+
cd {{source_directory()}}/cmd/runner && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
4949
echo "Runner build complete!"
5050

5151
# Build shim
@@ -56,7 +56,12 @@ build-shim-binary:
5656
cd {{source_directory()}}/cmd/shim
5757
if [ -n "$shim_os" ] && [ -n "$shim_arch" ]; then
5858
echo "Building shim for $shim_os/$shim_arch"
59-
GOOS=$shim_os GOARCH=$shim_arch go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
59+
if [ "$shim_os" = "linux" ] && [ "$(uname -s)" != "Linux" ]; then
60+
echo "WARNING: Cross-compiling to Linux, disabling CGO (DCGM unavailable)"
61+
CGO_ENABLED=0 GOOS=$shim_os GOARCH=$shim_arch go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
62+
else
63+
CGO_ENABLED=1 GOOS=$shim_os GOARCH=$shim_arch go build -ldflags "-X 'main.Version=$version'"
64+
fi
6065
else
6166
echo "Building shim for current platform"
6267
go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"

runner/internal/shim/dcgm/wrapper_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux
1+
//go:build linux && cgo
22

33
package dcgm
44

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build linux && !cgo
2+
3+
package dcgm
4+
5+
import "fmt"
6+
7+
func NewDCGMWrapper(address string) (DCGMWrapperInterface, error) {
8+
return nil, fmt.Errorf("DCGM unavailable: built with CGO disabled (cross-compilation)")
9+
}

runner/internal/shim/dcgm/wrapper_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux
1+
//go:build linux && cgo
22

33
package dcgm
44

0 commit comments

Comments
 (0)