Skip to content

x/tools/gopls: fatal error: 'dirent.h' file not found when trying to install gopls/Go tools via Visual Studio Code #56663

@JALsnipe

Description

@JALsnipe

gopls version

latest (unable to install)

go env

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/joshualieberman/Library/Caches/go-build"
GOENV="/Users/joshualieberman/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/joshualieberman/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/joshualieberman/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/brew/Cellar/go/1.19.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/brew/Cellar/go/1.19.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/joshualieberman/workspace/paracord/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/r6/1ytk_pjn24lgzhyg06r45hl40000gn/T/go-build1224701754=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am trying to install the Go tools in Visual Studio Code and am getting the following error when installing gopls complaining about dirent.h not found.

I know I have dirent.h because I see results in my local Xcode SDKs when running find / -iregex ".*/dirent.h$" 2>/dev/null.

I am following the steps here: https://learn.microsoft.com/en-us/azure/developer/go/configure-visual-studio-code

My setup is:

  • Fresh install of go from Homebrew
  • Fresh install of VSCode macOS from go.dev/doc/install
  • Instal the Go plugin
  • In the Command Palette, search for and select "Go: Install/Update tools" and select all tools in the dropdown

All tools are installed successfully except for gopls. I have installed go via Homebrew and have also installed gopls via Homebrew but am not sure how to configure VSCode to point to this alternative gopls path.

What did you expect to see?

Installation Success

What did you see instead?

1 tools failed to install.

Editor and settings

Visual Studio Code
Version: 1.73.0 (Universal)
Commit: 8fa188b2b301d36553cbc9ce1b0a146ccb93351f
Date: 2022-11-01T15:38:50.881Z (1 wk ago)
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 21.6.0
Sandboxed: No

Logs

Tools environment: GOPATH=/Users/joshualieberman/go
Installing 1 tool at /Users/joshualieberman/go/bin in module mode.
  gopls

Installing golang.org/x/tools/gopls@latest FAILED
{
 "killed": false,
 "code": 2,
 "signal": null,
 "cmd": "/opt/brew/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "golang.org/x/tools/internal/fastwalk\n# golang.org/x/tools/internal/fastwalk\n../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found\n#include <dirent.h>\n         ^~~~~~~~~~\n1 error generated.\n"
}

1 tools failed to install.

gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /opt/brew/bin/go install -v golang.org/x/tools/gopls@latest
golang.org/x/tools/internal/fastwalk
# golang.org/x/tools/internal/fastwalk
../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found
#include <dirent.h>
         ^~~~~~~~~~
1 error generated.

Also asked on Stack Overflow: https://stackoverflow.com/q/74367673/2415822

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions