v icon indicating copy to clipboard operation
v copied to clipboard

Unable to build V examples for WASM in Ubuntu-20.04

Open smartiniOnGitHub opened this issue 2 years ago • 6 comments

Describe the bug

Hi all, I'm trying to use the amazing new feature of generating WASM applications from V code, but I have some compilation errors when trying to build related examples. I'm following same steps of related CI pipeline (based on Ubuntu-22.04) but I'm in a Ubuntu-20.04 machine.

Expected Behavior

Source code built and WASM executable/s generated.

Current Behavior

Install binaryen like in CI build job (but on Ubuntu 20.04.x in my case) with:

cd <v installation folder>
./v cmd/tools/install_binaryen.vsh

all installed.

Then try to use it:

v_examples/wasm$ v -b wasm hello_world.v 
cannot compile `/opt/vlang_v/cmd/tools/builders/wasm_builder.v`: 
==================
tcc: error: library 'stdc++' not found
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

same happens even after installing clang gcc libc6-dev-i386-cross. Same error even when forcing clang compiler, with: v -cc clang -b wasm hello_world.v.

Some more diagnostic info:

clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ /sbin/ldconfig -p | grep stdc++
	libstdc++.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstdc++.so.6
	libstdc++.so.6 (libc6) => /lib32/libstdc++.so.6

If I try to build V WASM backend (./v -cc clang -showcc -v cmd/tools/builders/wasm_builder.v) I get the compilation errors, last is:

/usr/bin/ld: /opt/vlang_v/thirdparty/binaryen/lib/libbinaryen.a(binaryen-c.cpp.o):binaryen-c.cpp:(.text._ZN4wasm8Literals7getTypeEv[_ZN4wasm8Literals7getTypeEv]+0x368): more undefined references to `std::__throw_bad_array_new_length()' follow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...

but not sure this is a required step to build V programs to WASM ...

Related CI pipeline is: https://github.com/vlang/v/blob/master/.github/workflows/wasm_backend_tests_ci.yml

Reproduction Steps

See previous paragraph.

Possible Solution

No idea, sorry.

Additional Information/Context

Ask me for additional info.

V version

V 0.3.3 73675dc.7497d84

Environment details (OS name and version, etc.)

OS: linux, Ubuntu 20.04.5 LTS Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

getwd: /opt/vlang_v vmodules: /home/test/.vmodules vroot: /opt/vlang_v vexe: /opt/vlang_v/v vexe mtime: 2023-03-02 12:20:25 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 73675dc.7497d84

Git version: git version 2.25.1 Git vroot status: weekly.2022.24-1657-g7497d845 (3 commit(s) behind V master) .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

smartiniOnGitHub avatar Mar 02 '23 13:03 smartiniOnGitHub

Please try again with latest V. If it isn't fixed now, it is definitely a platform specific bug. For example, on Manjaro Linux it compiles cleanly:

$ v -b wasm hello_world.v
$

JalonSolov avatar Mar 07 '23 14:03 JalonSolov

Hi @JalonSolov sorry but with latest V (updated today) still I see the same error; I'm using an updated Ubuntu-20.04.x, so I just renamed the issue; hope it helps to better understand what is missing (or maybe if/what I forgot/miss to install). Details:

$ v -b wasm hello_world.v
cannot compile `/opt/vlang_v/cmd/tools/builders/wasm_builder.v`: 
==================
tcc: error: library 'stdc++' not found
...

and

$ v -cc clang -b wasm hello_world.v
cannot compile `/opt/vlang_v/cmd/tools/builders/wasm_builder.v`: 
==================
tcc: error: library 'stdc++' not found
...

Let's update. Thanks for now. Bye

smartiniOnGitHub avatar Mar 07 '23 17:03 smartiniOnGitHub

Try sudo apt-get install libstdc++6?

l1mey112 avatar Mar 07 '23 21:03 l1mey112

Hi @l1mey112, thanks for the hint, but it was already installed (as a dependency of previous packages): libstdc++6 is already the newest version (10.3.0-1ubuntu1~20.04). Maybe I'm missing something other but I manually installed same packages of CI build (that is for Ubuntu-22.04 so maybe there are newer packages and compilers) ... Sorry, maybe I need to install something else to target 32 bit (for WASM) or a specific 32 bit version of libraries ?

I can try to add a CI build for WASM even on Ubuntu-20.04 (a very diffuse platform even if not latest LTS) just to better understand the problem, what do you think ?

smartiniOnGitHub avatar Mar 07 '23 22:03 smartiniOnGitHub

According to @spytheman, relating to CI builds testing the WebAssembly backend.

Ubuntu 20.04 is too old; its gcc and libstdc++ by default do not work (gcc-11 does, but needs installing from a separate repo); I'll use Ubuntu 22.04 + macOS 12 on the CI instead

The WebAssembly backend depending on binaryen, an external library, is not optimal. I have the capability and experience to rewrite the backend whilst not depending on an IR. No promises, but this may happen.

l1mey112 avatar Mar 07 '23 23:03 l1mey112

ah ok thanks, I was thinking something like this but of course much better to check with you ... don't worry it's not a big problem, for so new features/backends it's acceptable to require new platforms only. Anyway if/when something new should happen I'll be happy to do some tests. With current issue, do you prefer to keep open (as a reminder, but maybe tag not as a bug but as a feature request or enhancement) or close ? Both options are good for me. Thank you very much for all the work on this powerful and future proof feature. Sorry last thing, maybe a small addition in docs specifying something like this could help others too on the same topic

smartiniOnGitHub avatar Mar 07 '23 23:03 smartiniOnGitHub