This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new cdb04f6 Zig hello-example
cdb04f6 is described below
commit cdb04f61727b02e882b9340b8077e7a29faa3aba
Author: Matheus Catarino França <[email protected]>
AuthorDate: Sun Feb 27 15:23:33 2022 -0300
Zig hello-example
rename example - fix
confusion-rename fixed
zigflags added
rm zigflag single-threaded
zig rules added
---
Application.mk | 20 ++++++++++++++++--
Make.defs | 1 +
examples/hello_zig/Kconfig | 29 ++++++++++++++++++++++++++
examples/hello_zig/Make.defs | 23 +++++++++++++++++++++
examples/hello_zig/Makefile | 34 ++++++++++++++++++++++++++++++
examples/hello_zig/hello_zig_main.zig | 39 +++++++++++++++++++++++++++++++++++
6 files changed, 144 insertions(+), 2 deletions(-)
diff --git a/Application.mk b/Application.mk
index b03ff59..e781920 100644
--- a/Application.mk
+++ b/Application.mk
@@ -73,19 +73,22 @@ CAOBJS = $(CASRCS:=$(SUFFIX)$(OBJEXT))
COBJS = $(CSRCS:=$(SUFFIX)$(OBJEXT))
CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT))
RUSTOBJS = $(RUSTSRCS:=$(SUFFIX)$(OBJEXT))
+ZIGOBJS = $(ZIGSRCS:=$(SUFFIX)$(OBJEXT))
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
MAINCSRCS = $(filter %.c,$(MAINSRC))
MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC))
+MAINZIGSRCS = $(filter %$(ZIGEXT), $(MAINSRC))
MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT))
MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT))
MAINRUSTOBJ = $(MAINRUSTSRCS:=$(SUFFIX)$(OBJEXT))
+MAINZIGOBJS = $(MAINZIGSRCS:=$(SUFFIX$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
-OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS)
+OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS)
ifneq ($(BUILD_MODULE),y)
- OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ)
+ OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJS)
endif
DEPPATH += --dep-path .
@@ -119,6 +122,11 @@ define ELFCOMPILERUST
$(Q) $(RUSTC) --emit obj $(RUSTELFFLAGS) $($(strip $1)_RUSTELFFLAGS) $1
-o $2
endef
+define ELFCOMPILEZIG
+ @echo "ZIG: $1"
+ $(Q) $(ZIG) build-obj $(ZIGELFFLAGS) $($(strip $1)_ZIGELFFLAGS) $1
--name $2
+endef
+
define ELFLD
@echo "LD: $2"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDLIBS) -o $2
@@ -144,6 +152,10 @@ $(RUSTOBJS): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
+$(ZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
+ $(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
+ $(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
+
archive:
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $(OBJS))
@@ -195,6 +207,10 @@ $(MAINRUSTOBJ): %$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
+$(MAINZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
+ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
+ $(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
+
install::
endif # BUILD_MODULE
diff --git a/Make.defs b/Make.defs
index 0cfa555..83094e8 100644
--- a/Make.defs
+++ b/Make.defs
@@ -58,6 +58,7 @@ $(foreach BDIR, $(BUILDIRS), $(eval $(call
Add_Application,$(BDIR))))
CXXEXT ?= .cxx
RUSTEXT ?= .rs
+ZIGEXT ?= .zig
# Library path
diff --git a/examples/hello_zig/Kconfig b/examples/hello_zig/Kconfig
new file mode 100644
index 0000000..b3d1d68
--- /dev/null
+++ b/examples/hello_zig/Kconfig
@@ -0,0 +1,29 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_HELLO_ZIG
+ tristate "\"Hello, Zig!\" example"
+ default n
+ ---help---
+ Enable the \"Hello, Zig!\" example
+
+if EXAMPLES_HELLO_ZIG
+
+config EXAMPLES_HELLO_ZIG_PROGNAME
+ string "Program name"
+ default "hello_zig"
+ ---help---
+ This is the name of the program that will be used when the
+ program is installed.
+
+config EXAMPLES_HELLO_ZIG_PRIORITY
+ int "Hello Zig task priority"
+ default 100
+
+config EXAMPLES_HELLO_ZIG_STACKSIZE
+ int "Hello Zig stack size"
+ default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/hello_zig/Make.defs b/examples/hello_zig/Make.defs
new file mode 100644
index 0000000..25dcc18
--- /dev/null
+++ b/examples/hello_zig/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/hello_zig/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+ifneq ($(CONFIG_EXAMPLES_HELLO_ZIG),)
+CONFIGURED_APPS += $(APPDIR)/examples/hello_zig
+endif
diff --git a/examples/hello_zig/Makefile b/examples/hello_zig/Makefile
new file mode 100644
index 0000000..2fb4baa
--- /dev/null
+++ b/examples/hello_zig/Makefile
@@ -0,0 +1,34 @@
+############################################################################
+# apps/examples/hello_zig/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# Hello, Zig! Example
+
+MAINSRC = hello_zig_main.zig
+
+# Hello, Zig! built-in application info
+
+PROGNAME = $(CONFIG_EXAMPLES_HELLO_ZIG_PROGNAME)
+PRIORITY = $(CONFIG_EXAMPLES_HELLO_ZIG_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_HELLO_ZIG_STACKSIZE)
+MODULE = $(CONFIG_EXAMPLES_HELLO_ZIG)
+
+include $(APPDIR)/Application.mk
diff --git a/examples/hello_zig/hello_zig_main.zig
b/examples/hello_zig/hello_zig_main.zig
new file mode 100644
index 0000000..1baef3f
--- /dev/null
+++ b/examples/hello_zig/hello_zig_main.zig
@@ -0,0 +1,39 @@
+//***************************************************************************
+// examples/hello_zig/hello_zig_main.zig
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership. The
+// ASF licenses this file to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance with the
+// License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+//
+//***************************************************************************
+
+//***************************************************************************
+// Included Files
+//***************************************************************************
+const std = @import("std");
+
+//****************************************************************************
+//* Externs
+//****************************************************************************
+
+pub extern fn printf(_format: [*:0]const u8) c_int;
+
+//****************************************************************************
+//* hello_zig_main
+//****************************************************************************
+pub export fn hello_zig_main(_argc: c_int, _argv: [*]const [*]const u8) c_int {
+ _ = _argc;
+ _ = _argv;
+ printf("Hello, Zig!\n");
+}