mirror of
https://github.com/golang/go
synced 2024-11-21 23:54:40 -07:00
build: allow builds without cgo
R=bradfitz, dsymonds, fshahriar CC=golang-dev https://golang.org/cl/4859043
This commit is contained in:
parent
39fa2a5bf2
commit
c02423902d
26
src/Make.inc
26
src/Make.inc
@ -121,6 +121,21 @@ HOST_CFLAGS=-I"$(GOROOT)/include" $(HOST_EXTRA_CFLAGS)
|
|||||||
HOST_LDFLAGS=$(HOST_EXTRA_LDFLAGS)
|
HOST_LDFLAGS=$(HOST_EXTRA_LDFLAGS)
|
||||||
PWD=$(shell pwd)
|
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.
|
# Make environment more standard.
|
||||||
LANG:=
|
LANG:=
|
||||||
LC_ALL:=C
|
LC_ALL:=C
|
||||||
@ -130,11 +145,12 @@ GREP_COLORS:=
|
|||||||
export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS
|
export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS
|
||||||
|
|
||||||
go-env:
|
go-env:
|
||||||
@echo export GOARCH=$(GOARCH)
|
@echo export GOARCH="$(GOARCH)"
|
||||||
@echo export GOOS=$(GOOS)
|
@echo export GOOS="$(GOOS)"
|
||||||
@echo export GOHOSTARCH=$(GOHOSTARCH)
|
@echo export GOHOSTARCH="$(GOHOSTARCH)"
|
||||||
@echo export GOHOSTOS=$(GOHOSTOS)
|
@echo export GOHOSTOS="$(GOHOSTOS)"
|
||||||
@echo export O=$O
|
@echo export CGO_ENABLED="$(CGO_ENABLED)"
|
||||||
|
@echo export O="$O"
|
||||||
@echo export AS="$(AS)"
|
@echo export AS="$(AS)"
|
||||||
@echo export CC="$(CC)"
|
@echo export CC="$(CC)"
|
||||||
@echo export GC="$(GC)"
|
@echo export GC="$(GC)"
|
||||||
|
@ -36,9 +36,13 @@ GOFILES_freebsd=\
|
|||||||
sendfile_stub.go\
|
sendfile_stub.go\
|
||||||
sock_bsd.go\
|
sock_bsd.go\
|
||||||
|
|
||||||
|
ifeq ($(CGO_ENABLED),1)
|
||||||
CGOFILES_freebsd=\
|
CGOFILES_freebsd=\
|
||||||
cgo_bsd.go\
|
cgo_bsd.go\
|
||||||
cgo_unix.go\
|
cgo_unix.go
|
||||||
|
else
|
||||||
|
GOFILES_freebsd+=cgo_stub.go
|
||||||
|
endif
|
||||||
|
|
||||||
GOFILES_darwin=\
|
GOFILES_darwin=\
|
||||||
dnsclient_unix.go\
|
dnsclient_unix.go\
|
||||||
@ -53,9 +57,13 @@ GOFILES_darwin=\
|
|||||||
sendfile_stub.go\
|
sendfile_stub.go\
|
||||||
sock_bsd.go\
|
sock_bsd.go\
|
||||||
|
|
||||||
|
ifeq ($(CGO_ENABLED),1)
|
||||||
CGOFILES_darwin=\
|
CGOFILES_darwin=\
|
||||||
cgo_bsd.go\
|
cgo_bsd.go\
|
||||||
cgo_unix.go\
|
cgo_unix.go
|
||||||
|
else
|
||||||
|
GOFILES_darwin+=cgo_stub.go
|
||||||
|
endif
|
||||||
|
|
||||||
GOFILES_linux=\
|
GOFILES_linux=\
|
||||||
dnsclient_unix.go\
|
dnsclient_unix.go\
|
||||||
@ -69,6 +77,14 @@ GOFILES_linux=\
|
|||||||
sendfile_linux.go\
|
sendfile_linux.go\
|
||||||
sock_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=\
|
GOFILES_openbsd=\
|
||||||
dnsclient.go\
|
dnsclient.go\
|
||||||
dnsconfig.go\
|
dnsconfig.go\
|
||||||
@ -86,15 +102,6 @@ GOFILES_plan9=\
|
|||||||
lookup_unix.go\
|
lookup_unix.go\
|
||||||
sendfile_stub.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=\
|
GOFILES_windows=\
|
||||||
file_windows.go\
|
file_windows.go\
|
||||||
interface_windows.go\
|
interface_windows.go\
|
||||||
|
@ -8,7 +8,7 @@ TARG=os/user
|
|||||||
GOFILES=\
|
GOFILES=\
|
||||||
user.go\
|
user.go\
|
||||||
|
|
||||||
ifneq ($(GOARCH),arm)
|
ifeq ($(CGO_ENABLED),1)
|
||||||
CGOFILES_linux=\
|
CGOFILES_linux=\
|
||||||
lookup_unix.go
|
lookup_unix.go
|
||||||
CGOFILES_freebsd=\
|
CGOFILES_freebsd=\
|
||||||
|
@ -25,6 +25,10 @@ static int mygetpwuid_r(int uid, struct passwd *pwd,
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
implemented = true
|
||||||
|
}
|
||||||
|
|
||||||
// Lookup looks up a user by username. If the user cannot be found,
|
// Lookup looks up a user by username. If the user cannot be found,
|
||||||
// the returned error is of type UnknownUserError.
|
// the returned error is of type UnknownUserError.
|
||||||
func Lookup(username string) (*User, os.Error) {
|
func Lookup(username string) (*User, os.Error) {
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var implemented = false // set to true by lookup_unix.go's init
|
||||||
|
|
||||||
// User represents a user account.
|
// User represents a user account.
|
||||||
type User struct {
|
type User struct {
|
||||||
Uid int // user id
|
Uid int // user id
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func skip(t *testing.T) bool {
|
func skip(t *testing.T) bool {
|
||||||
if runtime.GOARCH == "arm" {
|
if !implemented {
|
||||||
t.Logf("user: cgo not implemented on arm; skipping tests")
|
t.Logf("user: not implemented; skipping tests")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,29 +4,12 @@
|
|||||||
|
|
||||||
include ../../../Make.inc
|
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
|
TARG=runtime/cgo
|
||||||
|
|
||||||
GOFILES=\
|
GOFILES=\
|
||||||
cgo.go\
|
cgo.go\
|
||||||
|
|
||||||
ifeq ($(ENABLED),1)
|
ifeq ($(CGO_ENABLED),1)
|
||||||
|
|
||||||
# Unwarranted chumminess with Make.pkg's cgo rules.
|
# Unwarranted chumminess with Make.pkg's cgo rules.
|
||||||
# Do not try this at home.
|
# Do not try this at home.
|
||||||
@ -59,7 +42,7 @@ endif
|
|||||||
|
|
||||||
include ../../../Make.pkg
|
include ../../../Make.pkg
|
||||||
|
|
||||||
ifeq ($(ENABLED),1)
|
ifeq ($(CGO_ENABLED),1)
|
||||||
_cgo_defun.c:
|
_cgo_defun.c:
|
||||||
echo >$@
|
echo >$@
|
||||||
|
|
||||||
|
@ -49,20 +49,20 @@ GOMAXPROCS=10 gomake testshort
|
|||||||
time gomake test
|
time gomake test
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
[ "$GOARCH" == arm ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
[ "$GOHOSTOS" == windows ] ||
|
[ "$GOHOSTOS" == windows ] ||
|
||||||
(xcd ../misc/cgo/stdio
|
(xcd ../misc/cgo/stdio
|
||||||
gomake clean
|
gomake clean
|
||||||
./test.bash
|
./test.bash
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
[ "$GOARCH" == arm ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
(xcd ../misc/cgo/life
|
(xcd ../misc/cgo/life
|
||||||
gomake clean
|
gomake clean
|
||||||
./test.bash
|
./test.bash
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
[ "$GOARCH" == arm ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
[ "$GOHOSTOS" == windows ] ||
|
[ "$GOHOSTOS" == windows ] ||
|
||||||
(xcd ../misc/cgo/test
|
(xcd ../misc/cgo/test
|
||||||
gomake clean
|
gomake clean
|
||||||
|
Loading…
Reference in New Issue
Block a user