File tree 3 files changed +26
-47
lines changed
3 files changed +26
-47
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ include $(APPDIR)/Make.defs
25
25
MAINSRC = hello_zig.zig
26
26
27
27
# Hello, Zig! built-in application info
28
-
28
+ ZIGFLAGS += -lc -I $( TOPDIR ) /include
29
29
PROGNAME = $(CONFIG_EXAMPLES_HELLO_ZIG_PROGNAME )
30
30
PRIORITY = $(CONFIG_EXAMPLES_HELLO_ZIG_PRIORITY )
31
31
STACKSIZE = $(CONFIG_EXAMPLES_HELLO_ZIG_STACKSIZE )
Original file line number Diff line number Diff line change 24
24
const std = @import ("std" );
25
25
26
26
//****************************************************************************
27
- //* Externs
27
+ //* C API - need libc linking (freestanding libc is stubs only)
28
28
//****************************************************************************
29
+ // nuttx namespace
30
+ const nuttx = struct {
31
+ pub const c = @cImport ({
32
+ @cInclude ("nuttx/config.h" );
33
+ @cInclude ("stdio.h" );
34
+ });
35
+ };
29
36
30
- pub extern fn printf ( _format : [ * : 0 ] const u8 ) c_int ;
37
+ // or (optional) const c = std.c; // from std library (non-full libc)
31
38
39
+ // typedef alias
40
+ const printf = nuttx .c .printf ;
32
41
//****************************************************************************
33
42
//* hello_zig_main
34
43
//****************************************************************************
35
- pub export fn main (_argc : c_int , _argv : [* ]const [* ]const u8 ) u8 {
36
- _ = _argc ;
37
- _ = _argv ;
38
- _ = printf ("Hello, Zig!\n " );
44
+ comptime {
45
+ // rename to hello_zig_main entry point for nuttx
46
+ @export (hello_zig , .{
47
+ .name = "hello_zig_main" ,
48
+ .linkage = .weak ,
49
+ });
50
+ }
51
+
52
+ fn hello_zig (_ : c_int , _ : ? [* ]const [* ]const u8 ) callconv (.C ) c_int {
53
+ print ("[{s}]: Hello, Zig!\n " , .{nuttx .c .CONFIG_ARCH_BOARD });
39
54
return 0 ;
40
55
}
56
+
57
+ fn print (comptime fmt : [* :0 ]const u8 , args : anytype ) void {
58
+ _ = printf (std .fmt .comptimePrint (std .mem .span (fmt ), args ));
59
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments