Commit 54fb9940 authored by Russ Cox's avatar Russ Cox

go: build runtime/cgo

Also rename -v to -x in the build and install commands,
to match the flag in go test (which we can't change
because -v is taken).  Matches sh -x anyway.

R=r, iant, ality
CC=golang-dev
https://golang.org/cl/5504045
parent 6b772462
......@@ -133,7 +133,7 @@ var cdefs = flag.Bool("cdefs", false, "for bootstrap: write C definitions for C
var objDir = flag.String("objdir", "", "object directory")
var gccgo = flag.Bool("gccgo", false, "generate files for use with gccgo")
var importRuntimeCgo = flag.Bool("import_runtime_cgo", true, "import runtime/cgo in generated code")
var goarch, goos string
func main() {
......
......@@ -32,7 +32,13 @@ func (p *Package) writeDefs() {
// Write C main file for using gcc to resolve imports.
fmt.Fprintf(fm, "int main() { return 0; }\n")
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*, int), void *a, int c) { }\n")
if *importRuntimeCgo {
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*, int), void *a, int c) { }\n")
} else {
// If we're not importing runtime/cgo, we *are* runtime/cgo,
// which provides crosscall2. We just need a prototype.
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*, int), void *a, int c);")
}
fmt.Fprintf(fm, "void _cgo_allocate(void *a, int c) { }\n")
fmt.Fprintf(fm, "void _cgo_panic(void *a, int c) { }\n")
......@@ -43,7 +49,7 @@ func (p *Package) writeDefs() {
fmt.Fprintf(fgo2, "package %s\n\n", p.PackageName)
fmt.Fprintf(fgo2, "import \"unsafe\"\n\n")
fmt.Fprintf(fgo2, "import \"syscall\"\n\n")
if !*gccgo {
if !*gccgo && *importRuntimeCgo {
fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n")
}
fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n")
......
This diff is collapsed.
......@@ -20,22 +20,22 @@ type Package struct {
// See list.go. It is okay to add fields, but not to change or
// remove existing ones. Keep in sync with list.go
Name string // package name
Doc string // package documentation string
Doc string `json:",omitempty"` // package documentation string
ImportPath string // import path of package in dir
Dir string // directory containing package sources
Version string // version of installed package (TODO)
Standard bool // is this package part of the standard Go library?
Version string `json:",omitempty"` // version of installed package (TODO)
Standard bool `json:",omitempty"` // is this package part of the standard Go library?
// Source files
GoFiles []string // .go source files (excluding CgoFiles)
CFiles []string // .c source files
HFiles []string // .h source files
SFiles []string // .s source files
CgoFiles []string // .go sources files that import "C"
CFiles []string `json:",omitempty"` // .c source files
HFiles []string `json:",omitempty"` // .h source files
SFiles []string `json:",omitempty"` // .s source files
CgoFiles []string `json:",omitempty"` // .go sources files that import "C"
// Dependency information
Imports []string // import paths used by this package
Deps []string // all (recursively) imported dependencies
Imports []string `json:",omitempty"` // import paths used by this package
Deps []string `json:",omitempty"` // all (recursively) imported dependencies
// Unexported fields are not part of the public API.
t *build.Tree
......
......@@ -12,14 +12,14 @@ func init() {
}
var cmdRun = &Command{
UsageLine: "run [-a] [-n] [-v] gofiles...",
UsageLine: "run [-a] [-n] [-x] gofiles...",
Short: "compile and run Go program",
Long: `
Run compiles and runs the main package comprising the named Go source files.
The -a flag forces reinstallation of packages that are already up-to-date.
The -n flag prints the commands but does not run them.
The -v flag prints the commands.
The -x flag prints the commands.
See also: go build.
`,
......@@ -27,11 +27,11 @@ See also: go build.
var runA = cmdRun.Flag.Bool("a", false, "")
var runN = cmdRun.Flag.Bool("n", false, "")
var runV = cmdRun.Flag.Bool("v", false, "")
var runX = cmdRun.Flag.Bool("x", false, "")
func runRun(cmd *Command, args []string) {
var b builder
b.init(*runA, *runN, *runV)
b.init(*runA, *runN, *runX)
p := goFilesPackage(args, "")
p.targ = "" // force rebuild - no up-to-date copy anywhere
a1 := b.action(modeBuild, modeBuild, p)
......
......@@ -248,13 +248,13 @@ func runTest(cmd *Command, args []string) {
}
}
allRuns := &action{f: (*builder).nop, deps: runs}
allRuns := &action{deps: runs}
b.do(allRuns)
}
func (b *builder) test(p *Package) (buildAction, runAction *action, err error) {
if len(p.info.TestGoFiles)+len(p.info.XTestGoFiles) == 0 {
return &action{f: (*builder).nop, p: p}, &action{f: (*builder).notest, p: p}, nil
return &action{p: p}, &action{f: (*builder).notest, p: p}, nil
}
// Build Package structs describing:
......@@ -310,8 +310,8 @@ func (b *builder) test(p *Package) (buildAction, runAction *action, err error) {
ptest.GoFiles = append(ptest.GoFiles, p.GoFiles...)
ptest.GoFiles = append(ptest.GoFiles, p.info.TestGoFiles...)
ptest.targ = "" // must rebuild
ptest.Imports = p.info.TestImports
ptest.imports = imports
ptest.Imports = append(append([]string{}, p.info.Imports...), p.info.TestImports...)
ptest.imports = append(append([]*Package{}, p.imports...), imports...)
ptest.pkgdir = testDir
} else {
ptest = p
......@@ -372,7 +372,7 @@ var pass = []byte("\nPASS\n")
// runTest is the action for running a test binary.
func (b *builder) runTest(a *action) error {
if b.nflag || b.vflag {
if b.nflag || b.xflag {
b.showcmd("%s", strings.Join(append([]string{a.deps[0].pkgbin}, testArgs...), " "))
if b.nflag {
return nil
......
......@@ -14,15 +14,15 @@ ifeq ($(CGO_ENABLED),1)
# Unwarranted chumminess with Make.pkg's cgo rules.
# Do not try this at home.
CGO_OFILES=\
$(GOARCH).o\
$(GOOS)_$(GOARCH).o\
util.o\
gcc_$(GOARCH).o\
gcc_$(GOOS)_$(GOARCH).o\
gcc_util.o\
ifeq ($(GOOS),windows)
CGO_LDFLAGS=-lm -mthreads
else
CGO_LDFLAGS=-lpthread
CGO_OFILES+=setenv.o\
CGO_OFILES+=gcc_setenv.o\
endif
......@@ -50,11 +50,11 @@ _cgo_main.c:
echo 'int main() { return 0; }' >$@
endif
$(GOARCH).o: $(GOARCH).S
gcc_$(GOARCH).o: gcc_$(GOARCH).S
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
$(GOOS)_$(GOARCH).o: $(GOOS)_$(GOARCH).c
gcc_$(GOOS)_$(GOARCH).o: gcc_$(GOOS)_$(GOARCH).c
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
%.o: %.c
gcc_%.o: gcc_%.c
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -O2 -fPIC -o $@ -c $^
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <string.h> /* for strerror */
#include <pthread.h>
#include "libcgo.h"
......
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This tells the go tool that this package builds using cgo.
// TODO: Once we stop using Make, this import can move into cgo.go.
package cgo
import "C"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment