From b69323bb1f19a5adfed3854e57ef89caf53d7b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 12 Nov 2022 19:43:47 +0100 Subject: [PATCH] waforthc: Add test target --- .github/workflows/build-waforthc.yml | 4 +- src/standalone/Makefile | 12 +++-- src/waforthc/.gitignore | 1 + src/waforthc/Makefile | 66 +++++++++++++++++++++------- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build-waforthc.yml b/.github/workflows/build-waforthc.yml index 2593e56..bb03f17 100644 --- a/.github/workflows/build-waforthc.yml +++ b/.github/workflows/build-waforthc.yml @@ -15,5 +15,5 @@ jobs: steps: - uses: actions/checkout@v2 - uses: ./.github/actions/setup - # - run: make -C src/standalone install-deps package - # - run: make -C src/standalone check + - run: make -C src/waforthc package + - run: make -C src/waforthc check diff --git a/src/standalone/Makefile b/src/standalone/Makefile index 98af57c..a3c60d8 100644 --- a/src/standalone/Makefile +++ b/src/standalone/Makefile @@ -71,9 +71,15 @@ package: waforth endif endif -CFLAGS:=-I$(WASMTIME_DIR)/include $(CFLAGS) +CFLAGS:= -I$(WASMTIME_DIR)/include $(CFLAGS) LIBS:=$(WASMTIME_DIR)/lib/libwasmtime.a $(LIBS) +ifeq ($(DEBUG),1) +CFLAGS := $(CFLAGS) -g +else +CFLAGS := $(CFLAGS) -O2 +endif + ################################################ BIN2H=../../scripts/bin2h @@ -86,7 +92,7 @@ OBJECTS=main.o $(RESOURCE_OBJECTS) all: waforth waforth: $(OBJECTS) - $(CC) -o $@ $(OBJECTS) $(LDFLAGS) $(LIBS) + $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LDFLAGS) $(LIBS) main.o: waforth_core.h @@ -114,4 +120,4 @@ check: .PHONY: clean clean: - -rm -f waforth_core.wasm waforth_core.h $(OBJECTS) waforth *.tgz *.zip test.out + -rm -f waforth_core.wasm waforth_core.h $(OBJECTS) waforth *.exe *.tgz *.zip test.out diff --git a/src/waforthc/.gitignore b/src/waforthc/.gitignore index e99a8ce..740efa2 100644 --- a/src/waforthc/.gitignore +++ b/src/waforthc/.gitignore @@ -2,3 +2,4 @@ /waforth_*.h /_waforth* /hello +/waforth*.tgz diff --git a/src/waforthc/Makefile b/src/waforthc/Makefile index 3379741..c1d1cd9 100644 --- a/src/waforthc/Makefile +++ b/src/waforthc/Makefile @@ -1,44 +1,67 @@ -ifeq ($(OS),Windows_NT) +.DEFAULT_GOAL := all +VERSION?=$(shell cat ../../package.json | grep '"version"' | sed -e 's/.*:.*"\(.*\)".*/\1/') + +ifeq ($(OS),Windows_NT) +package: waforthc + 7z a -tzip waforthc-v$(VERSION)-windows.zip waforthc.exe +else # $(OS) +ifeq (, $(shell which gtar)) +TAR := tar else +# bsd-tar corrupts files on GitHub: https://github.com/actions/virtual-environments/issues/2619 +TAR := gtar +endif UNAME_S=$(shell uname -s) UNAME_P=$(shell uname -p) ifeq ($(UNAME_S),Darwin) +ifeq ($(UNAME_P),arm) +PACKAGE_SUFFIX=arm64-macos +else +PACKAGE_SUFFIX=x86_64-macos +endif # FIXME: When new WABT 1.0.31 is released, we can update this to standard paths +HOMEBREW_DIR = $(shell brew --prefix) WABT_INCLUDE_DIR := $(HOME)/Downloads/src/wabt/include WABT_LIB_DIR := $(HOME)/Downloads/src/wabt/build WABT_WASM2C_SRC_DIR = $(HOME)/Downloads/src/wabt/wasm2c -# BOOST_INCLUDE_DIR := /opt/homebrew/include -# BOOST_LIB_DIR := /opt/homebrew/lib -BOOST_INCLUDE_DIR = /opt/homebrew/Cellar/boost/1.80.0/include -BOOST_LIB_DIR := /opt/homebrew/Cellar/boost/1.80.0/lib +BOOST_INCLUDE_DIR := $(HOMEBREW_DIR)/include +BOOST_LIB_DIR := $(HOMEBREW_DIR)/lib LIBS := -mmacosx-version-min=13.0 -CXXFLAGS := -std=c++20 -else +CXXFLAGS := -std=c++17 +else # $(UNAME_S) WABT_INCLUDE_DIR := /usr/local/wabt/include WABT_LIB_DIR := /usr/local/wabt/lib WABT_WASM2C_SRC_DIR = /usr/local/wasm2c BOOST_INCLUDE_DIR = /usr/include BOOST_LIB_DIR := /usr/lib/x86_64-linux-gnu -endif +PACKAGE_SUFFIX=x86_64-linux +endif # $(UNAME_S) LIBS := -L$(WABT_LIB_DIR) -lwabt $(BOOST_LIB_DIR)/libboost_filesystem.a $(BOOST_LIB_DIR)/libboost_program_options.a $(LIBS) -CXXFLAGS := $(CXXFLAGS) -g -endif +package: waforthc + $(TAR) czf waforthc-v$(VERSION)-$(PACKAGE_SUFFIX).tgz waforthc +endif # $(OS) -CPPFLAGS := -g \ - -I$(WABT_INCLUDE_DIR) \ - -I$(BOOST_INCLUDE_DIR) +CPPFLAGS := -I$(WABT_INCLUDE_DIR) -I$(BOOST_INCLUDE_DIR) + +ifeq ($(DEBUG),1) +CXXFLAGS := $(CXXFLAGS) -g +else +CXXFLAGS := $(CXXFLAGS) -O2 +endif BIN2H=../../scripts/bin2h WAT2WASM=wat2wasm WAT2WASM_FLAGS=--debug-names +CPPFLAGS:=-DVERSION='"$(VERSION)"' $(CPPFLAGS) + OBJECTS := waforthc.o all: waforthc waforthc: $(OBJECTS) - $(CXX) -o $@ $^ $(LIBS) + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) waforthc.o: waforth_core.h waforth_rt.h waforth_wabt_wasm-rt-impl_c.h waforth_wabt_wasm-rt-impl_h.h waforth_wabt_wasm-rt_h.h @@ -63,5 +86,18 @@ waforth_wabt_wasm-rt_h.h: $(WABT_WASM2C_SRC_DIR)/wasm-rt.h waforth_core.wasm: ../waforth.wat $(WAT2WASM) $(WAT2WASM_FLAGS) -o $@ $< +.PHONY: check +check: + -rm -f test test.out + ./waforthc -o test --init=SAY_HELLO ../examples/hello.fs | tee test.out + grep -q "Hello, Forth" test.out + ./test | tee test.out + grep -q "Hello, Forth" test.out + -rm -f test test.out + +.PHONY: clean clean: - -rm -rf waforthc waforth_core.wasm waforth_core.h waforth_rt.h waforth_wabt_wasm-rt-impl_c.h waforth_wabt_wasm-rt-impl_c.h waforth_wabt_wasm-rt_h.h waforth_wabt_wasm-rt-impl_h.h waforth *.o _waforth* + -rm -rf waforthc *.exe *.o *.tgz *.zip \ + waforth_core.wasm waforth_core.h \ + waforth_rt.h \ + waforth_wabt_wasm-rt-impl_c.h waforth_wabt_wasm-rt-impl_c.h waforth_wabt_wasm-rt_h.h waforth_wabt_wasm-rt-impl_h.h \ No newline at end of file