You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/08/10 04:14:08 UTC
[nuttx-apps] branch master updated: tools: Using math.h from NuttX for wasm build
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/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 712d008f6 tools: Using math.h from NuttX for wasm build
712d008f6 is described below
commit 712d008f66afae174ddb3786ad2e4962dbc0a5a1
Author: Huang Qi <hu...@xiaomi.com>
AuthorDate: Wed Jun 7 17:57:14 2023 +0800
tools: Using math.h from NuttX for wasm build
wasm clang can't find math.h if using libm from toolchain.
It's OK to using math.h from NuttX since only declaration is needed for wasm build.
Signed-off-by: Huang Qi <hu...@xiaomi.com>
---
include/wasm/.gitignore | 1 +
tools/Wasm.mk | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/wasm/.gitignore b/include/wasm/.gitignore
new file mode 100644
index 000000000..e27b5465e
--- /dev/null
+++ b/include/wasm/.gitignore
@@ -0,0 +1 @@
+math.h
\ No newline at end of file
diff --git a/tools/Wasm.mk b/tools/Wasm.mk
index 77497c19d..a26ee334a 100644
--- a/tools/Wasm.mk
+++ b/tools/Wasm.mk
@@ -57,6 +57,11 @@ CFLAGS_STRIP += $(ARCHCPUFLAGS) $(ARCHCFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(A
WCFLAGS += $(filter-out $(CFLAGS_STRIP),$(CFLAGS))
WCFLAGS += --sysroot=$(WSYSROOT) -nostdlib -D__NuttX__
+# If CONFIG_LIBM not defined, then define it to 1
+ifeq ($(CONFIG_LIBM),)
+WCFLAGS += -DCONFIG_LIBM=1 -I$(APPDIR)$(DELIM)include$(DELIM)wasm
+endif
+
WLDFLAGS = -z stack-size=$(STACKSIZE) -Wl,--initial-memory=$(INITIAL_MEMORY)
WLDFLAGS += -Wl,--export=main -Wl,--export=__main_argc_argv
WLDFLAGS += -Wl,--export=__heap_base -Wl,--export=__data_end
@@ -121,8 +126,18 @@ WAMR_MODE ?= INT
WSRCS := $(MAINSRC) $(CSRCS)
WOBJS := $(WSRCS:=$(SUFFIX).wo)
+# Copy math.h from $(TOPDIR)/include/nuttx/lib/math.h to $(APPDIR)/include/wasm/math.h
+# Using declaration of math.h is OK for Wasm build
+
+$(APPDIR)$(DELIM)include$(DELIM)wasm$(DELIM)math.h:
+ifeq ($(CONFIG_LIBM),)
+ $(call COPYFILE,$(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)lib$(DELIM)math.h,$@)
+endif
+
all:: $(WBIN)
+depend:: $(APPDIR)$(DELIM)include$(DELIM)wasm$(DELIM)math.h
+
$(WOBJS): %.c$(SUFFIX).wo : %.c
$(Q) $(WCC) $(WCFLAGS) -c $^ -o $@
@@ -140,7 +155,7 @@ $(WBIN): $(WOBJS)
clean::
$(call DELFILE, $(WOBJS))
$(call DELFILE, $(WBIN))
-
+ $(call DELFILE, $(APPDIR)$(DELIM)include$(DELIM)wasm$(DELIM)math.h)
endif # WASM_BUILD