Skip to content

Commit

Permalink
cgo: add support for stdio in picolibc
Browse files Browse the repository at this point in the history
This is simple: just add the required header file. But this commit also
adds a simple test to make sure it remains supported.
  • Loading branch information
aykevl committed Sep 24, 2021
1 parent 1573826 commit 7500373
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compileopts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ func (c *Config) CFlags() []string {
}
if c.Target.Libc == "picolibc" {
root := goenv.Get("TINYGOROOT")
cflags = append(cflags, "-nostdlibinc", "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "picolibc", "newlib", "libc", "include"))
picolibcDir := filepath.Join(root, "lib", "picolibc", "newlib", "libc")
cflags = append(cflags,
"-nostdlibinc",
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "include"),
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "tinystdio"),
)
cflags = append(cflags, "-I"+filepath.Join(root, "lib/picolibc-include"))
}
// Always emit debug information. It is optionally stripped at link time.
Expand Down
4 changes: 4 additions & 0 deletions testdata/cgo/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

/*
#include <stdio.h>
int fortytwo(void);
#include "main.h"
int mul(int, int);
Expand Down Expand Up @@ -129,6 +130,9 @@ func main() {
buf2 := make([]byte, len(buf1))
C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))

// libc: test basic stdio functionality
println("SEEK_CUR:", C.SEEK_CUR)
}

func printUnion(union C.joined_t) C.joined_t {
Expand Down
1 change: 1 addition & 0 deletions testdata/cgo/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ option 3A: 21
enum width matches: true
CFLAGS value: 17
copied string: foobar
SEEK_CUR: 1

0 comments on commit 7500373

Please sign in to comment.