mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
896a848001
commit
1bed192de0
Vendored
+2
@@ -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() {
|
||||
|
||||
Vendored
+4
@@ -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))
|
||||
|
||||
Vendored
+2
@@ -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;
|
||||
|
||||
Vendored
+1
@@ -58,4 +58,5 @@ option G: 12
|
||||
option 2A: 20
|
||||
option 3A: 21
|
||||
enum width matches: true
|
||||
CFLAGS value: 17
|
||||
copied string: foobar
|
||||
|
||||
Reference in New Issue
Block a user