Skip to content

Commit cdb04f6

Browse files
kassanexiaoxiang781216
authored andcommitted
Zig hello-example
rename example - fix confusion-rename fixed zigflags added rm zigflag single-threaded zig rules added
1 parent 2dde296 commit cdb04f6

File tree

6 files changed

+144
-2
lines changed

6 files changed

+144
-2
lines changed

Application.mk

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,22 @@ CAOBJS = $(CASRCS:=$(SUFFIX)$(OBJEXT))
7373
COBJS = $(CSRCS:=$(SUFFIX)$(OBJEXT))
7474
CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT))
7575
RUSTOBJS = $(RUSTSRCS:=$(SUFFIX)$(OBJEXT))
76+
ZIGOBJS = $(ZIGSRCS:=$(SUFFIX)$(OBJEXT))
7677

7778
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
7879
MAINCSRCS = $(filter %.c,$(MAINSRC))
7980
MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC))
81+
MAINZIGSRCS = $(filter %$(ZIGEXT), $(MAINSRC))
8082
MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT))
8183
MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT))
8284
MAINRUSTOBJ = $(MAINRUSTSRCS:=$(SUFFIX)$(OBJEXT))
85+
MAINZIGOBJS = $(MAINZIGSRCS:=$(SUFFIX$(OBJEXT))
8386
8487
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
85-
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS)
88+
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS)
8689
8790
ifneq ($(BUILD_MODULE),y)
88-
OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ)
91+
OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJS)
8992
endif
9093

9194
DEPPATH += --dep-path .
@@ -119,6 +122,11 @@ define ELFCOMPILERUST
119122
$(Q) $(RUSTC) --emit obj $(RUSTELFFLAGS) $($(strip $1)_RUSTELFFLAGS) $1 -o $2
120123
endef
121124

125+
define ELFCOMPILEZIG
126+
@echo "ZIG: $1"
127+
$(Q) $(ZIG) build-obj $(ZIGELFFLAGS) $($(strip $1)_ZIGELFFLAGS) $1 --name $2
128+
endef
129+
122130
define ELFLD
123131
@echo "LD: $2"
124132
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDLIBS) -o $2
@@ -144,6 +152,10 @@ $(RUSTOBJS): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
144152
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
145153
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
146154

155+
$(ZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
156+
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
157+
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
158+
147159
archive:
148160
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $(OBJS))
149161

@@ -195,6 +207,10 @@ $(MAINRUSTOBJ): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
195207
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
196208
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
197209

210+
$(MAINZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
211+
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
212+
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
213+
198214
install::
199215

200216
endif # BUILD_MODULE

Make.defs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR))))
5858

5959
CXXEXT ?= .cxx
6060
RUSTEXT ?= .rs
61+
ZIGEXT ?= .zig
6162

6263
# Library path
6364

examples/hello_zig/Kconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config EXAMPLES_HELLO_ZIG
7+
tristate "\"Hello, Zig!\" example"
8+
default n
9+
---help---
10+
Enable the \"Hello, Zig!\" example
11+
12+
if EXAMPLES_HELLO_ZIG
13+
14+
config EXAMPLES_HELLO_ZIG_PROGNAME
15+
string "Program name"
16+
default "hello_zig"
17+
---help---
18+
This is the name of the program that will be used when the
19+
program is installed.
20+
21+
config EXAMPLES_HELLO_ZIG_PRIORITY
22+
int "Hello Zig task priority"
23+
default 100
24+
25+
config EXAMPLES_HELLO_ZIG_STACKSIZE
26+
int "Hello Zig stack size"
27+
default DEFAULT_TASK_STACKSIZE
28+
29+
endif

examples/hello_zig/Make.defs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
############################################################################
2+
# apps/examples/hello_zig/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifneq ($(CONFIG_EXAMPLES_HELLO_ZIG),)
22+
CONFIGURED_APPS += $(APPDIR)/examples/hello_zig
23+
endif

examples/hello_zig/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
############################################################################
2+
# apps/examples/hello_zig/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
include $(APPDIR)/Make.defs
22+
23+
# Hello, Zig! Example
24+
25+
MAINSRC = hello_zig_main.zig
26+
27+
# Hello, Zig! built-in application info
28+
29+
PROGNAME = $(CONFIG_EXAMPLES_HELLO_ZIG_PROGNAME)
30+
PRIORITY = $(CONFIG_EXAMPLES_HELLO_ZIG_PRIORITY)
31+
STACKSIZE = $(CONFIG_EXAMPLES_HELLO_ZIG_STACKSIZE)
32+
MODULE = $(CONFIG_EXAMPLES_HELLO_ZIG)
33+
34+
include $(APPDIR)/Application.mk

examples/hello_zig/hello_zig_main.zig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//***************************************************************************
2+
// examples/hello_zig/hello_zig_main.zig
3+
//
4+
// Licensed to the Apache Software Foundation (ASF) under one or more
5+
// contributor license agreements. See the NOTICE file distributed with
6+
// this work for additional information regarding copyright ownership. The
7+
// ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
// "License"); you may not use this file except in compliance with the
9+
// License. You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
// License for the specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
//***************************************************************************
20+
21+
//***************************************************************************
22+
// Included Files
23+
//***************************************************************************
24+
const std = @import("std");
25+
26+
//****************************************************************************
27+
//* Externs
28+
//****************************************************************************
29+
30+
pub extern fn printf(_format: [*:0]const u8) c_int;
31+
32+
//****************************************************************************
33+
//* hello_zig_main
34+
//****************************************************************************
35+
pub export fn hello_zig_main(_argc: c_int, _argv: [*]const [*]const u8) c_int {
36+
_ = _argc;
37+
_ = _argv;
38+
printf("Hello, Zig!\n");
39+
}

0 commit comments

Comments
 (0)