mirror of
https://github.com/golang/go
synced 2024-11-26 21:21:34 -07:00
misc/cgo/testcarchive: test -buildmode=c-archive
Change-Id: I1668a6885c45180ff88fe673d04cec7eba395ee7 Reviewed-on: https://go-review.googlesource.com/8861 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
a888fcf7a7
commit
fdab2f92ea
34
misc/cgo/testcarchive/main.c
Normal file
34
misc/cgo/testcarchive/main.c
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct { char *p; intmax_t n; } GoString;
|
||||
extern signed char DidInitRun();
|
||||
extern signed char DidMainRun();
|
||||
extern GoString FromPkg();
|
||||
|
||||
int main(void) {
|
||||
GoString res;
|
||||
|
||||
if (DidMainRun()) {
|
||||
fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!DidInitRun()) {
|
||||
fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
res = FromPkg();
|
||||
if (strcmp(res.p, "str")) {
|
||||
fprintf(stderr, "ERROR: FromPkg()='%s', want 'str'\n", res.p);
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
24
misc/cgo/testcarchive/src/libgo/libgo.go
Normal file
24
misc/cgo/testcarchive/src/libgo/libgo.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
package main
|
||||
|
||||
import _ "p"
|
||||
|
||||
import "C"
|
||||
|
||||
var (
|
||||
ranInit bool
|
||||
ranMain bool
|
||||
)
|
||||
|
||||
func init() { ranInit = true }
|
||||
|
||||
func main() { ranMain = true }
|
||||
|
||||
//export DidInitRun
|
||||
func DidInitRun() bool { return ranInit }
|
||||
|
||||
//export DidMainRun
|
||||
func DidMainRun() bool { return ranMain }
|
10
misc/cgo/testcarchive/src/p/p.go
Normal file
10
misc/cgo/testcarchive/src/p/p.go
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
package p
|
||||
|
||||
import "C"
|
||||
|
||||
//export FromPkg
|
||||
func FromPkg() string { return "str" }
|
31
misc/cgo/testcarchive/test.bash
Executable file
31
misc/cgo/testcarchive/test.bash
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2015 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.
|
||||
|
||||
set -e
|
||||
|
||||
ccargs=""
|
||||
if [ "$(go env GOOS)" == "darwin" ]; then
|
||||
ccargs="-Wl,-no_pie"
|
||||
# For darwin/arm.
|
||||
# TODO(crawshaw): Can we do better?
|
||||
ccargs="$ccargs -framework CoreFoundation"
|
||||
fi
|
||||
|
||||
# TODO(crawshaw): Consider a go env for exec script name.
|
||||
bin=./testp
|
||||
exec_script=go_$(go env GOOS)_$(go env GOARCH)_exec
|
||||
if [ "$(which $exec_script)" != "" ]; then
|
||||
bin="$exec_script ./testp"
|
||||
fi
|
||||
|
||||
GOPATH=$(pwd) go build -buildmode=c-archive src/libgo/libgo.go
|
||||
$(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a
|
||||
$bin
|
||||
rm libgo.a testp
|
||||
|
||||
GOPATH=$(pwd) go build -buildmode=c-archive -o libgo.a libgo
|
||||
$(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a
|
||||
$bin
|
||||
rm libgo.a testp
|
4
src/cmd/dist/test.go
vendored
4
src/cmd/dist/test.go
vendored
@ -272,6 +272,10 @@ func (t *tester) registerTests() {
|
||||
} else if t.hasBash() && t.goos != "android" && !iOS {
|
||||
t.registerTest("testso", "../misc/cgo/testso", "./test.bash")
|
||||
}
|
||||
if t.goos == "darwin" && t.goarch == "amd64" {
|
||||
// TODO(crawshaw): add darwin/arm{,64}
|
||||
t.registerTest("testcarchive", "../misc/cgo/testcarchive", "./test.bash")
|
||||
}
|
||||
if t.gohostos == "linux" && t.goarch == "amd64" {
|
||||
t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", "main.go")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user