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

86 lines
1.3 KiB
Plaintext

[!cgo] skip 'this test requires cgo to be enabled'
env GOGARBLE=test/main
garble build
! stderr 'warning' # check that the C toolchain is happy
exec ./main
cmp stdout main.stdout
! binsubstr main$exe 'PortedField' 'test/main'
[short] stop # no need to verify this with -short
env GOGARBLE=*
garble build
exec ./main
cmp stdout main.stdout
env GOGARBLE=test/main
garble -tiny build
exec ./main
cmp stdout main.stdout
go build
! stderr 'warning' # check that the C toolchain is happy
exec ./main
cmp stdout main.stdout
binsubstr main$exe 'privateAdd'
-- go.mod --
module test/main
go 1.18
-- main.go --
package main
import "os/user"
/*
#include "separate.h"
static int privateAdd(int a, int b) {
return a + b;
}
extern void goCallback();
static void callGoCallback() {
goCallback();
separateFunction();
}
struct portedStruct {
char* PortedField;
};
*/
import "C"
import "fmt"
func main() {
fmt.Println(C.privateAdd(C.int(1), C.int(2)))
_, _ = user.Current()
st := C.struct_portedStruct{}
fmt.Println(st.PortedField == nil)
C.callGoCallback()
}
//export goCallback
func goCallback() {
fmt.Println("go callback")
}
-- separate.h --
void separateFunction();
-- separate.c --
#include "_cgo_export.h"
void separateFunction() {
goCallback();
}
-- main.stdout --
3
true
go callback
go callback