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: latest gopls install fails on MacOS #62162

Closed
enyuhsu opened this issue Aug 20, 2023 · 6 comments
Closed

x/tools/gopls: latest gopls install fails on MacOS #62162

enyuhsu opened this issue Aug 20, 2023 · 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. OS-Darwin Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@enyuhsu
Copy link

enyuhsu commented Aug 20, 2023

gopls version

Unable to install gopls

my go version: go version go1.21.0 darwin/arm64

go env

GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/enyuhsu/Library/Caches/go-build'
GOENV='/Users/enyuhsu/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/enyuhsu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/enyuhsu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/g1/1fskx_g53rd89kqbx3vjm48c0000gn/T/go-build2489256433=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go install golang.org/x/tools/gopls@latest

What did you expect to see?

Successful installation of gopls

What did you see instead?

Failed with this message:

# runtime/cgo
In file included from _cgo_export.c:4:
cgo-builtin-export-prolog:8:33: error: unknown type name 'ptrdiff_t'

Editor and settings

Editor is N/A but here is my OS info

Screenshot 2023-08-19 at 8 47 37 PM
@enyuhsu enyuhsu added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Aug 20, 2023
@gopherbot gopherbot added this to the Unreleased milestone Aug 20, 2023
@enyuhsu
Copy link
Author

enyuhsu commented Aug 20, 2023

I appear to have stddef.h on my system, which as I understand is where ptrdiff_t is defined.

sudo fd  stddef.h /Library/Developer/CommandLineTools

/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/lib/swift/shims/SwiftStddef.h
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Clang/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/tapi/14.0.0/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/tapi/14.0.3/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/tapi/13.1.6/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/tapi/13.0.0/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/stddef.h
/Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/stddef.h
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include/stddef.h
/Library/Developer/CommandLineTools/usr/include/c++/v1/stddef.h
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/lib/swift/shims/SwiftStddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib/swift/shims/SwiftStddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/lib/swift/shims/SwiftStddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/stddef.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/stddef.h

@dmitshur
Copy link
Contributor

dmitshur commented Aug 20, 2023

What is your Xcode version? I think xcodebuild -version should print it. If it's Xcode 15 (beta), there are some known issues that are being worked on, e.g., see #61229, although this failure mode looks different. I'm not able to reproduce this on darwin/arm64 with Go 1.21.0 and Xcode 14.3.1.

Does the error go away if you temporarily disable cgo, i.e., CGO_ENABLED=0 go install golang.org/x/tools/gopls@latest?

@dmitshur dmitshur added OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 20, 2023
@enyuhsu
Copy link
Author

enyuhsu commented Aug 20, 2023

Hi @dmitshur thanks for the response.

xcodebuild -version
Xcode 14.3.1
Build version 14E300c

Yes! CGO_ENABLED=0 allowed me to install the language server :)

@dmitshur
Copy link
Contributor

dmitshur commented Aug 21, 2023

It's good that the workaround of disabling cgo works.

I'm not sure what's causing the problem when cgo is left enabled. It might be something about the environment you're running this on. Has installing gopls worked on the same machine previously and no longer works, or is it the first time you're trying it?

You can check if a simple C program works, for example:

#include <stddef.h>

typedef struct { const char *p; ptrdiff_t n; } _GoString_;

int main() {}

Does clang try.c work okay, or produce try.c:3:33: error: unknown type name 'ptrdiff_t'?

Another thing you can try to get more information is to try to install gopls via a downloaded version of a Go toolchain, as a quick check that the problem isn't your main Go toolchain installation being corrupted somehow. For example, does this work or do you still get the same error this way?

$ GOTOOLCHAIN=go1.21rc4 go install golang.org/x/tools/gopls@latest
go: downloading go1.21rc4 (darwin/arm64)
$ echo $?
0

CC @findley, @cherrymui.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 21, 2023
@cherrymui
Copy link
Member

As @dmitshur pointed out, this looks like a problem for C compilation. This would make almost all cgo code unable to build, not just gopls. Could you try @dmitshur 's example

#include <stddef.h>

typedef struct { const char *p; ptrdiff_t n; } _GoString_;

int main() {}

for a simple C compilation, and see if that works? Thanks.

@enyuhsu
Copy link
Author

enyuhsu commented Aug 25, 2023

Yes, it appears to be an issue deeper than anything Go-specific. Trying to compile this trivial C program produces the same error:

foo.c:3:33: error: unknown type name 'ptrdiff_t'
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
                                ^
1 error generated.

Same happens when trying to build other tools, like I just noticed it when trying to install a tree-sitter parser for YAML.
Closing the issue as it is a problem with my environment.

Thanks for the help y'all!

UPDATE: Somehow I had a 0-byte file /usr/local/include/stddef.h on my system... No idea how that happened. Deleting it fixed everything 🤷‍♀️

@enyuhsu enyuhsu closed this as completed Aug 25, 2023
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. OS-Darwin Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants