diff options
author | Ayke van Laethem <[email protected]> | 2021-03-12 17:47:06 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-04-06 10:57:50 +0200 |
commit | 1bed192de059e05bda2d024dae39adbb43ba335f (patch) | |
tree | 0e1ec7b7950a7b79e6e486e353895e61fa10b47a /testdata | |
parent | 896a848001c511a20ad6ef3fd8175cd18b448fe5 (diff) | |
download | tinygo-1bed192de059e05bda2d024dae39adbb43ba335f.tar.gz tinygo-1bed192de059e05bda2d024dae39adbb43ba335f.zip |
cgo: add support for CFLAGS in .c files
This patch adds support for passing CFLAGS added in #cgo lines of the
CGo preprocessing phase to the compiler when compiling C files inside
packages. This is expected and convenient but didn't work before.
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/cgo/main.c | 2 | ||||
-rw-r--r-- | testdata/cgo/main.go | 4 | ||||
-rw-r--r-- | testdata/cgo/main.h | 2 | ||||
-rw-r--r-- | testdata/cgo/out.txt | 1 |
4 files changed, 9 insertions, 0 deletions
diff --git a/testdata/cgo/main.c b/testdata/cgo/main.c index 3a2e9c57e..7954b91f6 100644 --- a/testdata/cgo/main.c +++ b/testdata/cgo/main.c @@ -20,6 +20,8 @@ int globalUnionSize = sizeof(globalUnion); option_t globalOption = optionG; bitfield_t globalBitfield = {244, 15, 1, 2, 47, 5}; +int cflagsConstant = SOME_CONSTANT; + int smallEnumWidth = sizeof(option2_t); int fortytwo() { diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go index d9e2d7297..55f9f4c41 100644 --- a/testdata/cgo/main.go +++ b/testdata/cgo/main.go @@ -5,6 +5,7 @@ int fortytwo(void); #include "main.h" int mul(int, int); #include <string.h> +#cgo CFLAGS: -DSOME_CONSTANT=17 */ import "C" @@ -118,6 +119,9 @@ func main() { // Check that enums are considered the same width in C and CGo. println("enum width matches:", unsafe.Sizeof(C.option2_t(0)) == uintptr(C.smallEnumWidth)) + // Check whether CFLAGS are correctly passed on to compiled C files. + println("CFLAGS value:", C.cflagsConstant) + // libc: test whether C functions work at all. buf1 := []byte("foobar\x00") buf2 := make([]byte, len(buf1)) diff --git a/testdata/cgo/main.h b/testdata/cgo/main.h index 857a796ef..ddd07efa9 100644 --- a/testdata/cgo/main.h +++ b/testdata/cgo/main.h @@ -139,6 +139,8 @@ extern bitfield_t globalBitfield; extern int smallEnumWidth; +extern int cflagsConstant; + // test duplicate definitions int add(int a, int b); extern int global; diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt index 31fd4d330..2eb4f3546 100644 --- a/testdata/cgo/out.txt +++ b/testdata/cgo/out.txt @@ -58,4 +58,5 @@ option G: 12 option 2A: 20 option 3A: 21 enum width matches: true +CFLAGS value: 17 copied string: foobar |