Skip to content

Commit

Permalink
tools: Using math.h from NuttX for wasm build
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
no1wudi committed Aug 10, 2023
1 parent 4d2fb8a commit 501907a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
math.h
17 changes: 16 additions & 1 deletion tools/Wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $@

Expand All @@ -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

Expand Down

0 comments on commit 501907a

Please sign in to comment.