code review 12350044: build: on OS X use clang instead of gcc (issue 12350044)

58 views
Skip to first unread message

r...@golang.org

unread,
Aug 2, 2013, 12:08:33 PM8/2/13
to golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-dev1,

Message:
Hello golan...@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go/


Description:
build: on OS X use clang instead of gcc

Fixes issue 5822.
Will no doubt cause other problems, but Apple has forced our hand.

Please review this at https://codereview.appspot.com/12350044/

Affected files:
M src/cmd/dist/build.c
M src/cmd/go/build.go


Index: src/cmd/dist/build.c
===================================================================
--- a/src/cmd/dist/build.c
+++ b/src/cmd/dist/build.c
@@ -617,8 +617,17 @@
// set up gcc command line on first run.
if(gccargs.len == 0) {
xgetenv(&b, "CC");
- if(b.len == 0)
- bprintf(&b, "gcc");
+ if(b.len == 0) {
+ // Use clang on OS X, because gcc is deprecated there.
+ // Xcode for OS X 10.9 Mavericks will ship a fake "gcc" binary that
+ // actually runs clang. We prepare different command
+ // lines for the two binaries, so it matters what we call it.
+ // See golang.org/issue/5822.
+ if(streq(gohostos, "darwin")
+ bprintf(&b, "clang");
+ else
+ bprintf(&b, "gcc");
+ }
clang = contains(bstr(&b), "clang");
splitfields(&gccargs, bstr(&b));
for(i=0; i<nelem(proto_gccargs); i++)
Index: src/cmd/go/build.go
===================================================================
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -1771,6 +1771,19 @@
return b.run(p.Dir, p.ImportPath, nil, cmd, "-o", out, obj, flags)
}

+var defaultCC = "gcc"
+
+func init() {
+ // Use clang on OS X, because gcc is deprecated there.
+ // Xcode for OS X 10.9 Mavericks will ship a fake "gcc" binary that
+ // actually runs clang. We prepare different command
+ // lines for the two binaries, so it matters what we call it.
+ // See golang.org/issue/5822.
+ if runtime.GOOS == "darwin" {
+ defaultCC = "clang"
+ }
+}
+
// gccCmd returns a gcc command line prefix
func (b *builder) gccCmd(objdir string) []string {
return b.ccompilerCmd("CC", "gcc", objdir)


Brad Fitzpatrick

unread,
Aug 2, 2013, 12:12:26 PM8/2/13
to Russ Cox, re...@codereview-hr.appspotmail.com, golang-dev

LGTM

On all versions? Even 10.6? Did clang work then, having all the flags we need?

--

---You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Russ Cox

unread,
Aug 2, 2013, 1:23:48 PM8/2/13
to Brad Fitzpatrick, re...@codereview-hr.appspotmail.com, golang-dev
I have no idea what the version story is. We may need to be more precise about that. For now I want to see what breaks.


Brad Fitzpatrick

unread,
Aug 2, 2013, 1:33:38 PM8/2/13
to Russ Cox, re...@codereview-hr.appspotmail.com, golang-dev
Go for it.  I have a 10.6 machine at home still which I can test later.

r...@golang.org

unread,
Aug 2, 2013, 1:46:41 PM8/2/13
to golan...@googlegroups.com, brad...@golang.org, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com

Russ Cox

unread,
Aug 2, 2013, 1:46:51 PM8/2/13
to Brad Fitzpatrick, re...@codereview-hr.appspotmail.com, golang-dev
PTAL 

Added logic to cmd/cgo and disabled the cgo -godefs test.

Keith Randall

unread,
Aug 2, 2013, 1:59:30 PM8/2/13
to Russ Cox, Brad Fitzpatrick, re...@codereview-hr.appspotmail.com, golang-dev
I get errors when running this on 10.6:

# crypto/x509
/var/folders/a0/a0ATNr3xHliked0p+c3lIU+++TI/-Tmp-/go-build255322058/crypto/x509/_obj/_cgo_gotypes.go:14: syntax error: unexpected type, expecting name
/var/folders/a0/a0ATNr3xHliked0p+c3lIU+++TI/-Tmp-/go-build255322058/crypto/x509/_obj/_cgo_gotypes.go:26: syntax error: unexpected .
:7[/var/folders/a0/a0ATNr3xHliked0p+c3lIU+++TI/-Tmp-/go-build255322058/crypto/x509/_obj/_cgo_gotypes.go:34]: syntax error: unexpected type, expecting name
:8[/var/folders/a0/a0ATNr3xHliked0p+c3lIU+++TI/-Tmp-/go-build255322058/crypto/x509/_obj/_cgo_gotypes.go:35]: syntax error: unexpected type, expecting name



On Fri, Aug 2, 2013 at 10:46 AM, Russ Cox <r...@golang.org> wrote:
PTAL 

Added logic to cmd/cgo and disabled the cgo -godefs test.

--
 
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.

Russ Cox

unread,
Aug 2, 2013, 2:43:57 PM8/2/13
to Keith Randall, Brad Fitzpatrick, re...@codereview-hr.appspotmail.com, golang-dev
PTAL

Clang is now only used as the default on OS X 10.8 and later.

brad...@golang.org

unread,
Aug 2, 2013, 2:55:53 PM8/2/13
to r...@golang.org, golan...@googlegroups.com, k...@google.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com

r...@golang.org

unread,
Aug 2, 2013, 2:58:34 PM8/2/13
to r...@golang.org, golan...@googlegroups.com, brad...@golang.org, k...@google.com, re...@codereview-hr.appspotmail.com
*** Submitted as
https://code.google.com/p/go/source/detail?r=ede1d772501b ***

build: on OS X 10.8 and later, use clang instead of gcc

Fixes issue 5822.
Will no doubt cause other problems, but Apple has forced our hand.

R=golang-dev, bradfitz, khr
CC=golang-dev
https://codereview.appspot.com/12350044


https://codereview.appspot.com/12350044/

Brad Fitzpatrick

unread,
Aug 2, 2013, 2:59:45 PM8/2/13
to Russ Cox, golang-dev, Brad Fitzpatrick, Keith Randall, re...@codereview-hr.appspotmail.com
Breaks on Linux:

# Building C bootstrap tool.
cmd/dist
cmd/dist/build.c: In function 'install':
cmd/dist/build.c:642:5: error: 'clang' may be used uninitialized in this function [-Werror=uninitialized]
cc1: all warnings being treated as errors
Build complete, duration 1.367061013s. Result: error: exit status 1

Russ Cox

unread,
Aug 2, 2013, 3:11:09 PM8/2/13
to Brad Fitzpatrick, golang-dev, Keith Randall, re...@codereview-hr.appspotmail.com
Fixing, thanks.

Francisco Souza

unread,
Aug 2, 2013, 3:12:59 PM8/2/13
to Brad Fitzpatrick, Russ Cox, golang-dev, Keith Randall, re...@codereview-hr.appspotmail.com
Breaks on 10.8 too:

% clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix
% ./make.bash
# Building C bootstrap tool.
cmd/dist
cmd/dist/build.c:642:6: error: variable 'clang' is uninitialized when
used here [-Werror,-Wuninitialized]
if(clang) {
^~~~~
cmd/dist/build.c:592:39: note: initialize the variable 'clang' to
silence this warning
bool islib, ispkg, isgo, stale, clang;
^
= 0
1 error generated.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "golang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-dev+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Francisco Souza
Reply all
Reply to author
Forward
0 new messages