Skip to content

Commit adb79f2

Browse files
committed
cgo: add support for stdio in picolibc
This is simple: just add the required header file. But this commit also adds a simple test to make sure it remains supported.
1 parent 1573826 commit adb79f2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

compileopts/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ func (c *Config) CFlags() []string {
206206
}
207207
if c.Target.Libc == "picolibc" {
208208
root := goenv.Get("TINYGOROOT")
209-
cflags = append(cflags, "-nostdlibinc", "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "picolibc", "newlib", "libc", "include"))
209+
picolibcDir := filepath.Join(root, "lib", "picolibc", "newlib", "libc")
210+
cflags = append(cflags,
211+
"-nostdlibinc",
212+
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "include"),
213+
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "tinystdio"),
214+
)
210215
cflags = append(cflags, "-I"+filepath.Join(root, "lib/picolibc-include"))
211216
}
212217
// Always emit debug information. It is optionally stripped at link time.

testdata/cgo/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
/*
4+
#include <stdio.h>
45
int fortytwo(void);
56
#include "main.h"
67
int mul(int, int);
@@ -129,6 +130,9 @@ func main() {
129130
buf2 := make([]byte, len(buf1))
130131
C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
131132
println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))
133+
134+
// libc: test basic stdio functionality
135+
println("SEEK_CUR:", C.SEEK_CUR)
132136
}
133137

134138
func printUnion(union C.joined_t) C.joined_t {

testdata/cgo/out.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ option 3A: 21
6161
enum width matches: true
6262
CFLAGS value: 17
6363
copied string: foobar
64+
SEEK_CUR: 1

0 commit comments

Comments
 (0)