wajic icon indicating copy to clipboard operation
wajic copied to clipboard

Building system.bc manually

Open nsauzede opened this issue 3 years ago • 11 comments

@schellingb I just tried to manually build the "system/" libraries/headers on Ubuntu 21.10 (because the prebuilt archives you provide do not work for me, I get <math.h> include error..)

$ ls system
include  lib  system.bc
$ make -j 8 -f wajic.mk ./system/system.bc
wajic.mk:90: *** No source files found for build.  Stop.

Do you know what's happening, can you help ?

nsauzede avatar Nov 28 '21 20:11 nsauzede

Note, your latest commits seemed to solve the above error:

nico@lenovo:~/perso/git/wajic$ make -j 8 -f wajic.mk ./system/system.bc
/home/nico/perso/git/wajic/system/lib/libc/musl/src/complex/cabs.c
/home/nico/perso/git/wajic/system/lib/libc/musl/src/complex/cabsf.c
...
/home/nico/perso/git/wajic/system/lib/libc/wasi-helpers.c
/home/nico/perso/git/wajic/system/lib/emmalloc.c
Creating archive system/system.bc ...
nico@lenovo:~/perso/git/wajic$ 

But now, when trying to build the advanced example, I get this:

$ clang -isystem./system/include/libcxx -isystem./system/include/compat -isystem./system/include -isystem./system/include/libc -isystem./system/lib/libc/musl/arch/emscripten -Xlinker ./system/system.bc -D__EMSCRIPTEN__ -D_LIBCPP_ABI_VERSION=2 -I. -Os -target wasm32 -nostartfiles -nodefaultlibs -nostdinc -nostdinc++ -Wno-unused-command-line-argument -DNDEBUG -D__WAJIC__ -fvisibility=hidden -fno-rtti -fno-exceptions -fno-threadsafe-statics -Xlinker -strip-all -Xlinker -gc-sections -Xlinker -no-entry -Xlinker -allow-undefined -Xlinker -export=__wasm_call_ctors -Xlinker -export=main -export=malloc -export=free samples/WebGL.c -o WebGL.wasm
In file included from samples/WebGL.c:28:
./system/include/compat/math.h:12:15: fatal error: 'math.h' file not found
#include_next <math.h>
              ^~~~~~~~
1 error generated.

I don't know if that's related to the actual system.bc generation ? (Or should I create another issue ?)

nsauzede avatar Nov 28 '21 20:11 nsauzede

Thanks for the report. Due to recent upstream system library changes, the command needed to be extended. This was already done in wajic.mk and wajicup.js but not in the README.md. Oops. This is fixed now, please try the updated command:

clang -isystem./system/include/libcxx -isystem./system/include/compat -isystem./system/include -isystem./system/include/libc -isystem./system/lib/libc/musl/arch/emscripten -Xlinker ./system/system.bc -D__EMSCRIPTEN__ -D_LIBCPP_ABI_VERSION=2 -I. -Os -target wasm32 -nostartfiles -nodefaultlibs -nostdinc -nostdinc++ -Wno-unused-command-line-argument -DNDEBUG -D__WAJIC__ -fvisibility=hidden -fno-rtti -fno-exceptions -fno-threadsafe-statics -Xlinker -strip-all -Xlinker -gc-sections -Xlinker -no-entry -Xlinker -allow-undefined -Xlinker -export=__wasm_call_ctors -Xlinker -export=main -export=malloc -export=free samples/WebGL.c -o WebGL.wasm

schellingb avatar Nov 29 '21 13:11 schellingb

@schellingb thanks for the heads-up I confirm that I'm now able to build the WebGL.wasm without errors. however, it seems like it doesn't do much when loaded in the WAJIC Viewer. All I get in the top right window is:

WAjic Viewer
Loading...
Finished main

Note that of course when I load the Basic.wasm I created myself, I get the expected:

WAjic Viewer
Loading...
add(2, 3): 5
Finished main

Also, if I load the online precompiled WebGL sample, I can see the colorful triangle with rotating palette. (I'm using Firefox 94 on Ubuntu 21.10) Here is the WebGL.wasm I get locally:

nico@lenovo:~/perso/git/wajic$ file WebGL.wasm 
WebGL.wasm: WebAssembly (wasm) binary module version 0x1 (MVP)
nico@lenovo:~/perso/git/wajic$ ls -l WebGL.wasm 
-rwxrwxr-x 1 nico nico 4859 nov.  29 23:11 WebGL.wasm
nico@lenovo:~/perso/git/wajic$ sha1sum WebGL.wasm 
82be0c9fa8bc4c5ce3a9558764a947fb704d1214  WebGL.wasm

Do you see anything that could have gone wrong ?

nsauzede avatar Nov 29 '21 22:11 nsauzede

Sorry I somehow managed to paste the old command in the comment above. Here is the new command from the README:

clang -isystem./system/include/libcxx -isystem./system/lib/libcxx/include -isystem./system/include/compat -isystem./system/include -isystem./system/include/libc -isystem./system/lib/libc/musl/include -isystem./system/lib/libc/musl/arch/emscripten -isystem./system/lib/libc/musl/arch/generic -Xlinker ./system/system.bc -D__EMSCRIPTEN__ -D_LIBCPP_ABI_VERSION=2 -I. -Os -target wasm32 -nostartfiles -nodefaultlibs -nostdinc -nostdinc++ -Wno-unused-command-line-argument -DNDEBUG -D__WAJIC__ -fvisibility=hidden -fno-rtti -fno-exceptions -fno-threadsafe-statics -Xlinker -strip-all -Xlinker -gc-sections -Xlinker -no-entry -Xlinker -allow-undefined -Xlinker -export=__wasm_call_ctors -Xlinker -export=main -Xlinker -export=malloc -Xlinker -export=free samples/WebGL.c -o WebGL.wasm

It should create a 13kb wasm so yours (at 4kb) is certainly missing something.

If it's still not working, can you run this clang command with an added -v at the very end and paste what it outputs?

schellingb avatar Nov 30 '21 00:11 schellingb

Hmmm seems to still produce the same:

nico@lenovo:~/perso/git/wajic$ clang -isystem./system/include/libcxx -isystem./system/lib/libcxx/include -isystem./system/include/compat -isystem./system/include -isystem./system/include/libc -isystem./system/lib/libc/musl/include -isystem./system/lib/libc/musl/arch/emscripten -isystem./system/lib/libc/musl/arch/generic -Xlinker ./system/system.bc -D__EMSCRIPTEN__ -D_LIBCPP_ABI_VERSION=2 -I. -Os -target wasm32 -nostartfiles -nodefaultlibs -nostdinc -nostdinc++ -Wno-unused-command-line-argument -DNDEBUG -D__WAJIC__ -fvisibility=hidden -fno-rtti -fno-exceptions -fno-threadsafe-statics -Xlinker -strip-all -Xlinker -gc-sections -Xlinker -no-entry -Xlinker -allow-undefined -Xlinker -export=__wasm_call_ctors -Xlinker -export=main -Xlinker -export=malloc -Xlinker -export=free samples/WebGL.c -o WebGL.wasm -v
Ubuntu clang version 13.0.0-2
Target: wasm32
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-13/bin/clang" -cc1 -triple wasm32 -emit-obj --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name WebGL.c -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/nico/perso/git/wajic -nostdsysteminc -nobuiltininc -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -isystem ./system/include/libcxx -isystem ./system/lib/libcxx/include -isystem ./system/include/compat -isystem ./system/include -isystem ./system/include/libc -isystem ./system/lib/libc/musl/include -isystem ./system/lib/libc/musl/arch/emscripten -isystem ./system/lib/libc/musl/arch/generic -D __EMSCRIPTEN__ -D _LIBCPP_ABI_VERSION=2 -I . -D NDEBUG -D __WAJIC__ -Os -Wno-unused-command-line-argument -fdebug-compilation-dir=/home/nico/perso/git/wajic -ferror-limit 19 -fvisibility hidden -fgnuc-version=4.2.1 -fno-threadsafe-statics -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/WebGL-ba9ceb.o -x c samples/WebGL.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "./system/include/libcxx"
ignoring nonexistent directory "./system/include/libc"
#include "..." search starts here:
#include <...> search starts here:
 .
 ./system/lib/libcxx/include
 ./system/include/compat
 ./system/include
 ./system/lib/libc/musl/include
 ./system/lib/libc/musl/arch/emscripten
 ./system/lib/libc/musl/arch/generic
End of search list.
 "/usr/bin/wasm-ld" -m wasm32 -L/lib ./system/system.bc -strip-all -gc-sections -no-entry -allow-undefined -export=__wasm_call_ctors -export=main -export=malloc -export=free /tmp/WebGL-ba9ceb.o -o WebGL.wasm
nico@lenovo:~/perso/git/wajic$ ls -l WebGL.wasm 
-rwxrwxr-x 1 nico nico 4859 nov.  30 01:39 WebGL.wasm

nsauzede avatar Nov 30 '21 00:11 nsauzede

This completely matches with my output of the same command. Can you do ls -l system/system.bc ? That file should be around 800 kb. If it's much smaller, can you delete system.bc and run make -f wajic.mk -j 8 system/system.bc again?

schellingb avatar Nov 30 '21 14:11 schellingb

nico@lenovo:~/perso/git/wajic$ ls -l system/
total 844
drwxrwxr-x  2 nico nico   4096 nov.  25 02:42 bin
drwxrwxr-x 18 nico nico   4096 nov.  25 02:42 include
drwxrwxr-x 17 nico nico   4096 nov.  25 02:42 lib
-rwxrwxr-x  1 nico nico 849698 nov.  29 23:07 system.bc

nsauzede avatar Nov 30 '21 15:11 nsauzede

Wajic does not like me :-)

nsauzede avatar Nov 30 '21 16:11 nsauzede

Can you ZIP and attach your WebGL.wasm file to here?

schellingb avatar Nov 30 '21 16:11 schellingb

there you go! WebGL.zip

nsauzede avatar Nov 30 '21 17:11 nsauzede

Should I also provide the system.bc file I manually obtain ? @schellingb

nsauzede avatar Dec 01 '21 09:12 nsauzede