WebAssembly/wasi-sdk

Wasi_sdk does'nt work with Boost::filesystem

frawamudi opened this issue · 4 comments

Could it be because am using an older version 17 or there anything special that must be done to boost package before compiling for wasi.

Boost was built from source with the following bash script

#!/bin/sh

export WASI_SDK_PATH=/opt/wasi-sdk-17.0
export CC=${WASI_SDK_PATH}/bin/clang
export CXX=${WASI_SDK_PATH}/bin/clang++
export WASI_SYSROOT=/opt/wasi-sdk-17.0/share/wasi-sysroot

sudo ./bootstrap.sh --without-libraries=thread,atomic --with-toolset=clang threading=multi --prefix=${WASI_SYSROOT}

sudo ./b2 link=shared architecture=wasm -j4

sudo ./b2 install

this is the command i ran on the cammand line

$CXX -v -fstandalone-debug -D_WASI_EMULATED_PROCESS_CLOCKS -DBOOST_DISABLE_THREADS test.cpp -o tt.wasm -fno-exceptions -I${WASI_SDK_PATH}/share/wasi-sysroot/include/boost -L${WASI_SDK_PATH}/share/wasi-sysroot/lib -lboost_filesystem -lboost_system --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot

I get this error
wasm-ld: error: unknown file type: /opt/wasi-sdk-17.0/share/wasi-sysroot/lib/libboost_filesystem.a(operations.o)
looking at the error it seems libboost_filesystem.a built wasn;t compatable with WASI, is there any way this can be fixed?

sbc100 commented

I would try removing the sudo from your configure and build steps.. by default I think sudo doesn't preserve the environment so your CC/CXX/etc settings are likely being ignored.

Thanks
but got another error:

wasm-ld: error: unknown file type: /opt/wasi-sdk-17.0/share/wasi-sysroot/lib/libboost_filesystem.a(operations.o)
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

after executing this command:
$CXX -v -DBOOST_DISABLE_THREADS test.cpp -o tt.wasm -fno-exceptions -I${WASI_SDK_PATH}/share/wasi-sysroot/include/boost -L${WASI_SDK_PATH}/share/wasi-sysroot/lib -lboost_filesystem -lboost_system --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot

sbc100 commented

It looks like that fie (/opt/wasi-sdk-17.0/share/wasi-sysroot/lib/libboost_filesystem.a(operations.o)) was not built with the wasi-sdk, but perhaps with the native compiler. Did you clean everything?

It looks like that fie (/opt/wasi-sdk-17.0/share/wasi-sysroot/lib/libboost_filesystem.a(operations.o)) was not built with the wasi-sdk, but perhaps with the native compiler. Did you clean everything?

yes i did, even tookout the whole wasi-sdk-17.0 folder. it turns out boost build systems ships some built intoolsetthat boost already recognize like gcc, clang, arm etc which are set of Jam files (Boost way of a config or toolchain file), but does have builting toolset for bulding boost for wasi using wasi compilier!

for example executing the --with-toolset=clang tells boost to use clang compiler.