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

cmd/go: race detector and cgo builds needs to diagnose lack of C compiler more gracefully #44271

Closed
dr2chase opened this issue Feb 15, 2021 · 8 comments
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dr2chase
Copy link
Contributor

NB this is forwarded from a Stack Overflow question.
A new user had this experience:

I'm following a tutorial on Go, and I have the actual file tree:
.
├── arrays
├── concurrency
├── di
├── hello-world
├── integers
├── iteration
├── maps
├── mocking
├── pointers
├── racer
└── structs
If I run the tests in all of the folders files, they work, except for the folder called racer, where running the tests gives me the following error:

# runtime/cgo
cgo: exec /missing-cc: fork/exec /missing-cc: no such file or directory
FAIL    github.com/-redacted-/go-with-tests/racer [build failed]

Is it related to something I'm doing in the files?

I can't reproduce this without trashing my Xcode install which I'd rather not, but it is almost certainly the case that said/sad user lacks a C compiler, and building with the race detector requires a C compiler. If we could detect this situation and give a more helpful error message, that would probably improve the on-ramp experience.

@ianlancetaylor ianlancetaylor changed the title Race detector build needs to diagnose lack of C compiler more gracefully cmd/go: race detector and cgo builds needs to diagnose lack of C compiler more gracefully Feb 15, 2021
@ianlancetaylor ianlancetaylor added GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 15, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Feb 15, 2021
@andreybokhanko
Copy link
Contributor

The simplest reproducer I can think of:

$ export CC=missing
$ echo -e "package issue44271\nimport \"C\"" >issue44271.go
$ go build ./issue44271.go
# runtime/cgo
exec: "missing": executable file not found in $PATH

This message is what I see on Linux; apparently, the StackOverflow's user saw something different due to a different OS. The root problem is that C compiler is missing and we print a cryptic (?) message on this. We probably want to check C compiler presence beforehand and print something more understandable.

@ianlancetaylor what do you think? -- is current behavior acceptable or is it better to fix it?

Yours,
Andrey
===
Advanced Software Technology Lab
Huawei

@ianlancetaylor
Copy link
Contributor

I think we should fix this if possible. Thanks.

@andreybokhanko
Copy link
Contributor

Got it. Let me take a stab on this.

@ianlancetaylor could you, please, assign this one on me?

@dr2chase
Copy link
Contributor Author

dr2chase commented Mar 9, 2021

I'm pretty sure the user was on a Mac, where there's at least three failure modes:

  1. No Xcode installed at all.
  2. Xcode installed, but not its command-line tools.
  3. Xcode and command-line tools installed, but user has not agreed to the license yet.
    I'll try to figure out what these look like (and of course it may vary with macOS and Xcode version, because why not?)

@dr2chase
Copy link
Contributor Author

dr2chase commented Mar 9, 2021

Presence of Xcode (on "Catalina", aka macOS 10.15):

% cat /Applications/Xcode.app/Contents/version.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>BuildAliasOf</key>
	<string>IDEFrameworks</string>
	<key>BuildVersion</key>
	<string>62</string>
	<key>CFBundleShortVersionString</key>
	<string>11.5</string>
	<key>CFBundleVersion</key>
	<string>16139</string>
	<key>ProductBuildVersion</key>
	<string>11E608c</string>
	<key>ProjectName</key>
	<string>IDEFrameworks</string>
	<key>SourceVersion</key>
	<string>16139000000000000</string>
</dict>
</plist>

cc is /usr/bin/cc which is a symbolic link to /usr/bin/clang which is a tiny executable:

% ls -l /usr/bin/clang
-rwxr-xr-x  1 root  wheel  31488 Sep 21 20:29 /usr/bin/clang
% clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

The real clang is not small:

ls -l /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-rwxr-xr-x  1 drchase  primarygroup  87983296 May  3  2020 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

The Xcode licensing failure is I think a little bit more self-explanatory when it fails, but not something I'd call new-user-friendly. The "Installing MacPorts" web page provides typical guidance, beginning at "Please note".

@gopherbot
Copy link

Change https://golang.org/cl/301249 mentions this issue: cgo: Check presence of a C compiler

@andreybokhanko
Copy link
Contributor

@dr2chase These references to XCode behavior are definitely useful -- thanks!

However, I don't think it makes sense to replicate it verbatim, let alone handle situations like no Xcode, no command-line tools, etc separately. Remember that go supports a variety of operating systems and toolchain environments.

@andreybokhanko
Copy link
Contributor

@ianlancetaylor I cooked up a patch; please kindly take a look: https://go-review.googlesource.com/c/go/+/301249

There is no unit test, but I don't see how one can be added for the code like this -- unless we want to call the entire "main" function as a unit test.

@golang golang locked and limited conversation to collaborators Mar 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants