You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/testdata/scripts/cgo.txt

72 lines
1.1 KiB
Plaintext

[!cgo] skip 'this test requires cgo to be enabled'
env GOGARBLE=test/main
garble build
exec ./main
cmp stdout main.stdout
binsubstr main$exe 'privateAdd'
[short] stop # no need to verify this with -short
env GOGARBLE=*
garble build
exec ./main
cmp stdout main.stdout
binsubstr main$exe 'privateAdd'
env GOGARBLE=test/main
garble -tiny build
exec ./main
cmp stdout main.stdout
binsubstr main$exe 'privateAdd'
go build
exec ./main
cmp stdout main.stdout
-- go.mod --
module test/main
go 1.17
-- main.go --
package main
import "os/user"
/*
static int privateAdd(int a, int b) {
return a + b;
}
extern void goCallback();
static void callGoCallback() {
goCallback();
}
struct portedStruct {
char* PortedField;
};
*/
import "C"
import "fmt"
func main() {
fmt.Println(C.privateAdd(C.int(1), C.int(2)))
_, _ = user.Current()
fmt.Printf("%#v\n", C.struct_portedStruct{})
C.callGoCallback()
}
//export goCallback
func goCallback() {
fmt.Println("go callback")
}
-- main.stdout --
3
main._Ctype_struct_portedStruct{PortedField:(*main._Ctype_char)(nil)}
go callback