Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JALsnipe opened this issue Nov 8, 2022 · 6 comments
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@JALsnipe
Copy link

JALsnipe commented Nov 8, 2022

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

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 8, 2022
@gopherbot gopherbot added this to the Unreleased milestone Nov 8, 2022
@palmamartin
Copy link

I get the same error after upgrading to MacOS Ventura. I have Go installed manually not using Homebrew.

@hyangah
Copy link
Contributor

hyangah commented Nov 10, 2022

I think this was caused by the change in https://go-review.git.corp.google.com/c/tools/+/436780 for #51356

BTW, by any chance, any of you @JALsnipe @palmamartin is on M1? (I guess not because both VSCode and go env claim x86/amd64, but want to make sure if we have all info)

@hyangah hyangah added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 10, 2022
@JALsnipe
Copy link
Author

JALsnipe commented Nov 10, 2022

I'm not on an M1, I'm on a 2019 Intel MacBook Pro.

Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro16,1
Processor Name: 8-Core Intel Core i9
Processor Speed: 2.4 GHz
Number of Processors: 1
Total Number of Cores: 8
L2 Cache (per Core): 256 KB
L3 Cache: 16 MB
Hyper-Threading Technology: Enabled
Memory: 64 GB

@JALsnipe
Copy link
Author

JALsnipe commented Nov 10, 2022

After playing around with several configurations (including installing gopls via homebrew and symlinking it to /Users/joshualieberman/go/bin), a fresh install of Xcode AND the Command Line Tools from https://developer.apple.com/download/all/ seems to resolve this.

@hyangah
Copy link
Contributor

hyangah commented Nov 10, 2022

Thanks for sharing it. @JALsnipe
We discussed internally and we also concluded this problem occurs either by corrupted C tool chains or outdated XCode. Especially, after OS upgrade, it's often necessary to update XCode and the command line tools as well (@palmamartin)

Closing it since this is an issue in the dev environment setup.

@hyangah hyangah closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@Conca147
Copy link

Conca147 commented Jun 21, 2023

I have the same question,but I'm on a M1 MacBook Pro.My command line tools is the latest version(2395),but I didn't resolve this question yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants