wasix-org / wasix-libc

wasix libc implementation for WebAssembly
https://wasi.dev
Other
116 stars 19 forks source link

Build instructions don't work #4

Open jedisct1 opened 1 year ago

jedisct1 commented 1 year ago

I tried to build wasix-libc as documented:

make CC='zig cc -target wasm32-freestanding` AR=`zig ar` NM=`zig nm`

But that fails with:

find: ‘libc-bottom-half/getpid’: No such file or directory
find: ‘build/-wasi’: No such file or directory
#
# Install the include files.
#
mkdir -p "/tmp/wasix-libc/sysroot/include"
cp -r "libc-bottom-half/headers/public"/* "/tmp/wasix-libc/sysroot/include"
# Generate musl's bits/alltypes.h header.
mkdir -p "/tmp/wasix-libc/sysroot/include/bits"
sed -f libc-top-half/musl/tools/mkalltypes.sed \
    libc-top-half/musl/arch//bits/alltypes.h.in \
    libc-top-half/musl/include/alltypes.h.in \
    > "/tmp/wasix-libc/sysroot/include/bits/alltypes.h"
sed: can't read libc-top-half/musl/arch//bits/alltypes.h.in: No such file or directory
make: *** [Makefile:611: include_dirs] Error 2

The build32.sh script fails on macOS due to GNUisms. On Linux, it successfully completes. But then, the sysroot folder contains headers, but lib/wasm32-wasi folder is empty.

How to build wasix-libc?

waikuen2010 commented 1 year ago

I face similar issue as you did. It took me quite a while to build the wasix sysroot. I believe the build instruction need to be updated. Here is what I found.

First, there is not need to run build32.sh and build64.sh. What these script did (except the final make step, because /sysroot is in the .gitignore file) is already reflect in the current commit of the repo.

Second I found some issues in the Makefile, as the output suggest

find: ‘libc-bottom-half/getpid’: No such file or directory
find: ‘build/-wasi’: No such file or directory

The first line is complaining about not finding getpid.c which is not in /libc-bottom-half but inside /libc-bottom-half/sources Correcting the Makefile get me through this part.

The second line is caused by missing environment variables.

# or wasm64
export TARGET_ARCH=wasm32
export TARGET_OS=wasix

Finally, I use wasi-sdk to build the sysroot

CC=${WASI_SDK_PATH}/bin/clang AR=${WASI_SDK_PATH}/bin/llvm-ar NM=${WASI_SDK_PATH}/bin/llvm-nm make -j $NUM_OF_CPUS
lauler1 commented 1 year ago
# or wasm64
export TARGET_ARCH=wasm32
export TARGET_OS=wasix

Finally, I use wasi-sdk to build the sysroot

CC=${WASI_SDK_PATH}/bin/clang AR=${WASI_SDK_PATH}/bin/llvm-ar NM=${WASI_SDK_PATH}/bin/llvm-nm make -j $NUM_OF_CPUS

Worked!!!!