waforthc: Fix linux build

This commit is contained in:
Remko Tronçon 2022-11-12 16:37:51 +01:00
parent 80e261d5af
commit 6e0610dfc4
3 changed files with 26 additions and 14 deletions

View file

@ -9,8 +9,7 @@ runs:
- if: runner.os == 'macOS'
run: brew install wabt
shell: bash
# We depend on a more recent version, not available in current Ubuntu (20.04).
# - run: sudo apt-get install wabt
- run: sudo apt-get install libboost-dev libboost-filesystem-dev libboost-program-options-dev
- if: runner.os == 'Linux'
run: |
curl -L -s https://github.com/WebAssembly/wabt/releases/download/1.0.30/wabt-1.0.30-ubuntu.tar.gz | tar xvz -C /tmp

View file

@ -1,26 +1,39 @@
ifeq ($(OS),Windows_NT)
else
UNAME_S=$(shell uname -s)
UNAME_P=$(shell uname -p)
ifeq ($(UNAME_S),Darwin)
# FIXME: When new WABT 1.0.31 is released, we can update this to standard paths
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
LIBS := -mmacosx-version-min=13.0
CXXFLAGS := -std=c++20
else
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
LIBS := -L$(WABT_LIB_DIR) -lwabt $(BOOST_LIB_DIR)/libboost_filesystem.a $(BOOST_LIB_DIR)/libboost_program_options.a $(LIBS)
CXXFLAGS := $(CXXFLAGS) -g
endif
OBJECTS := waforthc.o
CPPFLAGS := -g \
-I$(WABT_INCLUDE_DIR) \
-I$(BOOST_INCLUDE_DIR)
CXXFLAGS := -g -std=c++20
LIBS := -mmacosx-version-min=13.0 -L$(WABT_LIB_DIR) -lwabt $(BOOST_LIB_DIR)/libboost_filesystem.a $(BOOST_LIB_DIR)/libboost_program_options.a
BIN2H=../../scripts/bin2h
WAT2WASM=wat2wasm
WAT2WASM_FLAGS=--debug-names
OBJECTS := waforthc.o
all: waforthc
@ -51,4 +64,4 @@ waforth_core.wasm: ../waforth.wat
$(WAT2WASM) $(WAT2WASM_FLAGS) -o $@ $<
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 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*

View file

@ -83,7 +83,7 @@ wabt::Result compileToNative(wabt::Module &mod, const std::string &init, const s
wabt::FileStream((wd / "wasm-rt.h").string()).WriteData(waforth_wabt_wasm_rt_h, sizeof(waforth_wabt_wasm_rt_h));
}
bp::child c(bp::search_path("gcc"), "-o", outfile, (wd / "_waforth_rt.c").string(), (wd / "_waforth.c").string(), (wd / "wasm-rt-impl.c").string());
bp::child c(bp::search_path("gcc"), "-o", outfile, (wd / "_waforth_rt.c").string(), (wd / "_waforth.c").string(), (wd / "wasm-rt-impl.c").string(), "-lm");
c.wait();
int result = c.exit_code();
if (result != 0) {
@ -283,12 +283,12 @@ wabt::Result compileToModule(std::vector<wabt::Module> &words, const std::vector
auto dsf = wabt::MakeUnique<wabt::DataSegmentModuleField>();
wabt::DataSegment &ds = dsf->data_segment;
ds.memory_var = wabt::Var(0, wabt::Location());
ds.offset.push_back(MakeUnique<wabt::ConstExpr>(wabt::Const::I32(dataOffset)));
ds.offset.push_back(wabt::MakeUnique<wabt::ConstExpr>(wabt::Const::I32(dataOffset)));
ds.data = data;
compiled.AppendField(std::move(dsf));
compiled.globals[HERE_GLOBAL_INDEX]->init_expr = wabt::ExprList{MakeUnique<wabt::ConstExpr>(wabt::Const::I32(dataOffset + data.size()))};
compiled.globals[LATEST_GLOBAL_INDEX]->init_expr = wabt::ExprList{MakeUnique<wabt::ConstExpr>(wabt::Const::I32(latest))};
compiled.globals[HERE_GLOBAL_INDEX]->init_expr = wabt::ExprList{wabt::MakeUnique<wabt::ConstExpr>(wabt::Const::I32(dataOffset + data.size()))};
compiled.globals[LATEST_GLOBAL_INDEX]->init_expr = wabt::ExprList{wabt::MakeUnique<wabt::ConstExpr>(wabt::Const::I32(latest))};
for (auto &word : words) {
assert(word.funcs.size() == 1);
@ -385,4 +385,4 @@ int main(int argc, char *argv[]) {
return -1;
}
return 0;
}
}