DEV Community

Frédéric G. MARAND
Frédéric G. MARAND

Posted on • Originally published at blog.riff.org on

GoLand tip of the day: when Make run configurations don't find go

The problem

In a GoLand 2018.3 EAP run configuration, a Makefile run configuration finds the go binary on macOS, but not on Ubuntu, causing make targets like this one to fail:

# Makefile
client/test.wasm: client/main.go  # Building WASM
        GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go

$ /usr/bin/make -f (some edited path)/Makefile
client/test.wasm/bin/sh: 1: go: not found
make: *** [client/test.wasm] Error 127
$
Enter fullscreen mode Exit fullscreen mode

Simple enough to fix...

The diagnostic

On the command line, the same GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go line works normally. Looks like a path issue in Goland or the plugin. Checking in the Makefile:

# Makefile
client/test.wasm: client/main.go    
        # "${PATH}" 
        # Building WASM 
        GOARCH=wasm GOOS=js go build -o client/test.wasm client/main.go

$ # Building WASM
make: *** [client/test.wasm] Error 127# "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
$
Enter fullscreen mode Exit fullscreen mode

So indeed, on at least this version, the PATH is not taken into account. Let's fix this.

The solution

Of course, one could just add the Go bin path to the tasks in these targets, but this is uncalled for on other environments, so we can just remind GoLand to add this path to the run configuration.

  1. Edit the Run configuration
  2. Edit the Environment variables field
  3. Add a definition for the PATH variable taken from an echo $PATH on the command line
  4. Apply and close

Oddities

As usual, Make has its own peculiar charm, requiring the variable name to use the braced format shown above instead of a plain $PATH.

Trying to extend the PATH variable by just adding something like $PATH:/usr/local/go/bin or ${PATH}:/usr/local/go/bin won't work:

  • in the first case, Make will receive the result of evaluation $P, then the ATH string, so other binaries beyond the ones in /usr/local/go/bin will be missing
  • in the second case, Make detects a variable referencing itself and aborts the task

Top comments (0)