@@ -12,6 +12,7 @@ import (
1212 "os"
1313 "os/exec"
1414 "path/filepath"
15+ "runtime"
1516 "strings"
1617 "sync"
1718
@@ -28,9 +29,18 @@ func (c *LocalCluster) dgraphImage() string {
2829 return "dgraph/dgraph:local"
2930}
3031
31- // setupBinary sets up the dgraph binary. The binary is expected to be a version
32- // compiled that is compatible with the host OS and architecture. Search this repo
33- // for DGRAPH_BINARY to learn its use.
32+ // setupBinary sets up dgraph binaries in tempBinDir.
33+ //
34+ // On Linux a single "dgraph" binary from $GOPATH/bin serves both Docker
35+ // containers and local commands (bulk/live loader).
36+ //
37+ // On non-Linux (macOS) two binaries are placed in tempBinDir:
38+ // - "dgraph" – a Linux binary for Docker containers, from
39+ // $GOPATH/linux_<arch> (or LINUX_GOBIN if set).
40+ // - "dgraph_host" – the host-native binary for local commands,
41+ // from $GOPATH/bin.
42+ //
43+ // Both are produced by "make install".
3444func (c * LocalCluster ) setupBinary () error {
3545 if err := ensureDgraphClone (); err != nil {
3646 panic (err )
@@ -43,11 +53,34 @@ func (c *LocalCluster) setupBinary() error {
4353 }
4454 }
4555 if c .conf .version == localVersion {
46- if os .Getenv ("GOPATH" ) == "" {
56+ gopath := os .Getenv ("GOPATH" )
57+ if gopath == "" {
4758 return errors .New ("GOPATH is not set" )
4859 }
49- fromDir := filepath .Join (os .Getenv ("GOPATH" ), "bin" )
50- return copyBinary (fromDir , c .tempBinDir , c .conf .version )
60+
61+ if runtime .GOOS == "linux" {
62+ // On Linux $GOPATH/bin/dgraph is both the native and Docker binary.
63+ return copyBinary (filepath .Join (gopath , "bin" ), c .tempBinDir , c .conf .version )
64+ }
65+
66+ // Non-Linux (macOS): need separate Linux and host-native binaries.
67+ // 1. Copy the Linux binary (for Docker containers) as "dgraph".
68+ linuxDir := os .Getenv ("LINUX_GOBIN" )
69+ if linuxDir == "" {
70+ linuxDir = filepath .Join (gopath , "linux_" + runtime .GOARCH )
71+ }
72+ if err := copyBinary (linuxDir , c .tempBinDir , c .conf .version ); err != nil {
73+ return err
74+ }
75+
76+ // 2. Copy the host-native binary (for local bulk/live commands) as "dgraph_host".
77+ hostSrc := filepath .Join (gopath , "bin" , "dgraph" )
78+
79+ hostDst := filepath .Join (c .tempBinDir , "dgraph_host" )
80+ if err := copy (hostSrc , hostDst ); err != nil {
81+ return errors .Wrapf (err , "error copying host-native binary from [%v] to [%v]" , hostSrc , hostDst )
82+ }
83+ return nil
5184 }
5285
5386 binaryPath := filepath .Join (binariesPath , fmt .Sprintf (binaryNameFmt , c .conf .version ))
0 commit comments