]> Cypherpunks repositories - gostls13.git/commitdiff
build: allow builds without cgo
authorRuss Cox <rsc@golang.org>
Thu, 11 Aug 2011 01:36:48 +0000 (21:36 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 11 Aug 2011 01:36:48 +0000 (21:36 -0400)
R=bradfitz, dsymonds, fshahriar
CC=golang-dev
https://golang.org/cl/4859043

src/Make.inc
src/pkg/net/Makefile
src/pkg/os/user/Makefile
src/pkg/os/user/lookup_unix.go
src/pkg/os/user/user.go
src/pkg/os/user/user_test.go
src/pkg/runtime/cgo/Makefile
src/run.bash

index a6edb165a7100be5a7bd6e7ae206ffc7fb78cc7f..8f549f62456ee29db87853334c6267a95b36d264 100644 (file)
@@ -121,6 +121,21 @@ HOST_CFLAGS=-I"$(GOROOT)/include" $(HOST_EXTRA_CFLAGS)
 HOST_LDFLAGS=$(HOST_EXTRA_LDFLAGS)
 PWD=$(shell pwd)
 
+# Decide whether use of cgo is okay.
+ifeq ($(CGO_ENABLED),)
+# Default on...
+CGO_ENABLED:=1
+ifeq ($(GOARCH),arm)  # ... but not on ARM
+CGO_ENABLED:=0
+endif
+ifeq ($(GOOS),plan9)  # ... and not on Plan 9
+CGO_ENABLED:=0
+endif
+ifeq ($(GOOS),openbsd)  # ... and not on OpenBSD
+CGO_ENABLED:=0
+endif
+endif
+
 # Make environment more standard.
 LANG:=
 LC_ALL:=C
@@ -130,11 +145,12 @@ GREP_COLORS:=
 export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS
 
 go-env:
-       @echo export GOARCH=$(GOARCH)
-       @echo export GOOS=$(GOOS)
-       @echo export GOHOSTARCH=$(GOHOSTARCH)
-       @echo export GOHOSTOS=$(GOHOSTOS)
-       @echo export O=$O
+       @echo export GOARCH="$(GOARCH)"
+       @echo export GOOS="$(GOOS)"
+       @echo export GOHOSTARCH="$(GOHOSTARCH)"
+       @echo export GOHOSTOS="$(GOHOSTOS)"
+       @echo export CGO_ENABLED="$(CGO_ENABLED)"
+       @echo export O="$O"
        @echo export AS="$(AS)"
        @echo export CC="$(CC)"
        @echo export GC="$(GC)"
index 6b3d0b328ba4f773efbefcb94d6edee14796e476..cc895f75680bb12d834b49a2a99f7dbf2ce3041f 100644 (file)
@@ -36,9 +36,13 @@ GOFILES_freebsd=\
        sendfile_stub.go\
        sock_bsd.go\
 
+ifeq ($(CGO_ENABLED),1)
 CGOFILES_freebsd=\
        cgo_bsd.go\
-       cgo_unix.go\
+       cgo_unix.go
+else
+GOFILES_freebsd+=cgo_stub.go
+endif
 
 GOFILES_darwin=\
        dnsclient_unix.go\
@@ -53,9 +57,13 @@ GOFILES_darwin=\
        sendfile_stub.go\
        sock_bsd.go\
 
+ifeq ($(CGO_ENABLED),1)
 CGOFILES_darwin=\
        cgo_bsd.go\
-       cgo_unix.go\
+       cgo_unix.go
+else
+GOFILES_darwin+=cgo_stub.go
+endif
 
 GOFILES_linux=\
        dnsclient_unix.go\
@@ -69,6 +77,14 @@ GOFILES_linux=\
        sendfile_linux.go\
        sock_linux.go\
 
+ifeq ($(CGO_ENABLED),1)
+CGOFILES_linux=\
+       cgo_linux.go\
+       cgo_unix.go
+else
+GOFILES_linux+=cgo_stub.go
+endif
+
 GOFILES_openbsd=\
        dnsclient.go\
        dnsconfig.go\
@@ -86,15 +102,6 @@ GOFILES_plan9=\
        lookup_unix.go\
        sendfile_stub.go\
 
-ifeq ($(GOARCH),arm)
-# ARM has no cgo, so use the stubs.
-GOFILES_linux+=cgo_stub.go
-else
-CGOFILES_linux=\
-       cgo_linux.go\
-       cgo_unix.go
-endif
-
 GOFILES_windows=\
        file_windows.go\
        interface_windows.go\
index 731f7999ace42ee68ceaa73a3b3fead6a035e8d5..aabb54995d26b275d5e56a6edb32bf874297e541 100644 (file)
@@ -8,7 +8,7 @@ TARG=os/user
 GOFILES=\
        user.go\
 
-ifneq ($(GOARCH),arm)
+ifeq ($(CGO_ENABLED),1)
 CGOFILES_linux=\
        lookup_unix.go
 CGOFILES_freebsd=\
index 678de802b5176111b44a829a0913ff8226e26c76..1b2c9e8c9937ba2d8adf222dfeb4645be7b29fa7 100644 (file)
@@ -25,6 +25,10 @@ static int mygetpwuid_r(int uid, struct passwd *pwd,
 */
 import "C"
 
+func init() {
+       implemented = true
+}
+
 // Lookup looks up a user by username. If the user cannot be found,
 // the returned error is of type UnknownUserError.
 func Lookup(username string) (*User, os.Error) {
index dd009211d76421d961701ade4ccf7c2972e70618..f71e11d8b21d83caf1c9f25db9336643d32f0203 100644 (file)
@@ -9,6 +9,8 @@ import (
        "strconv"
 )
 
+var implemented = false // set to true by lookup_unix.go's init
+
 // User represents a user account.
 type User struct {
        Uid      int // user id
index ee917b57af2675ec0feefa0d9e63ba6a816123bd..59f15e4c67551bbe67b3d4dbf4b34411f1c6a2ba 100644 (file)
@@ -13,8 +13,8 @@ import (
 )
 
 func skip(t *testing.T) bool {
-       if runtime.GOARCH == "arm" {
-               t.Logf("user: cgo not implemented on arm; skipping tests")
+       if !implemented {
+               t.Logf("user: not implemented; skipping tests")
                return true
        }
 
index e7a2fa7c64a0a4affe15a7b4583d48c481b01214..766794797f69bbd1db2cbbf3b83f1ea3723c6476 100644 (file)
@@ -4,29 +4,12 @@
 
 include ../../../Make.inc
 
-ENABLED:=1
-
-ifeq ($(GOARCH),arm)
-ENABLED:=0
-endif
-
-ifeq ($(GOOS),plan9)
-ENABLED:=0
-endif
-ifeq ($(GOOS),openbsd)
-ENABLED:=0
-endif
-
-ifeq ($(DISABLE_CGO),1)
-ENABLED:=0
-endif
-
 TARG=runtime/cgo
 
 GOFILES=\
        cgo.go\
 
-ifeq ($(ENABLED),1)
+ifeq ($(CGO_ENABLED),1)
 
 # Unwarranted chumminess with Make.pkg's cgo rules.
 # Do not try this at home.
@@ -59,7 +42,7 @@ endif
 
 include ../../../Make.pkg
 
-ifeq ($(ENABLED),1)
+ifeq ($(CGO_ENABLED),1)
 _cgo_defun.c:
        echo >$@
 
index ae79a0cec3fbb398eb84068046b3953970d4505e..a9689bf15e986463310d7eaee1fc54f83bdf427a 100755 (executable)
@@ -49,20 +49,20 @@ GOMAXPROCS=10 gomake testshort
 time gomake test
 ) || exit $?
 
-[ "$GOARCH" == arm ] ||
+[ "$CGO_ENABLED" != 1 ] ||
 [ "$GOHOSTOS" == windows ] ||
 (xcd ../misc/cgo/stdio
 gomake clean
 ./test.bash
 ) || exit $?
 
-[ "$GOARCH" == arm ] ||
+[ "$CGO_ENABLED" != 1 ] ||
 (xcd ../misc/cgo/life
 gomake clean
 ./test.bash
 ) || exit $?
 
-[ "$GOARCH" == arm ] ||
+[ "$CGO_ENABLED" != 1 ] ||
 [ "$GOHOSTOS" == windows ] ||
 (xcd ../misc/cgo/test
 gomake clean