Hello WebAssembly! 奮闘メモ
お題
C言語で書いた
Hello, world! をブラウザで表示するGCE (Google Compute Engine) の Debian (n1-standard-1; vCPU x 1、メモリ 3.75 GB) で動かしたときのメモ
最終的にはメモリ 8GB に増設した
最終的にはハードディスク30GB必要だった
GCE上でブラウザ起動はできないだろうから,最終生成物の
.html など一式をを作ってダウンロードしてローカル表示するcmakeのバージョン古すぎた
apt-get からは必要とされるバージョン入れられなかったCMake 3.4.3 or higher is required. You are running version 3.0.2
自分で入れる
これを
v3.4.3 でやる CMakeうまくいった
挑戦中
$ ./emsdk install sdk-incoming-64bit binaryen-master-64bit
時間かかる(=お金かかる)
???
err.logScanning dependencies of target llvm-lto[ 55%] Building CXX object tools/llvm-lto/CMakeFiles/llvm-lto.dir/llvm-lto.cpp.o[ 55%] Linking CXX executable ../../bin/llvm-lto
collect2: error: ld returned 1 exit statustools/llvm-lto/CMakeFiles/llvm-lto.dir/build.make:141: recipe for target 'bin/llvm-lto' failedmake[2]: *** [bin/llvm-lto] Error 1CMakeFiles/Makefile2:6532: recipe for target 'tools/llvm-lto/CMakeFiles/llvm-lto.dir/all' failedmake[1]: *** [tools/llvm-lto/CMakeFiles/llvm-lto.dir/all] Error 2Makefile:149: recipe for target 'all' failedmake: *** [all] Error 2Build failed due to exception!Working directory: /home/daiki/emsdk/clang/fastcomp/build_incoming_64Command '['make', '-j1']' returned non-zero exit status 2Installation failed!これ? 似てるけど若干違う.
sudo
$ sudo ./emsdk install sdk-incoming-64bit binaryen-master-64bit
実行していく
!!!!
err.log[ 68%] Linking CXX static library ../../../../lib/libclangParse.a/usr/bin/ranlib: ../../../../lib/libclangParse.a: No space left on devicetools/clang/lib/Parse/CMakeFiles/clangParse.dir/build.make:458: recipe for target 'lib/libclangParse.a' failedmake[2]: *** [lib/libclangParse.a] Error 1make[2]: *** Deleting file 'lib/libclangParse.a'CMakeFiles/Makefile2:8578: recipe for target 'tools/clang/lib/Parse/CMakeFiles/clangParse.dir/all' failedmake[1]: *** [tools/clang/lib/Parse/CMakeFiles/clangParse.dir/all] Error 2Makefile:149: recipe for target 'all' failedmake: *** [all] Error 2Build failed due to exception!Working directory: /home/daiki/emsdk/clang/fastcomp/build_incoming_64Command '['make', '-j1']' returned non-zero exit status 2Installation failed!
~/emsdk$ dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda1 10188088 10040576 0 100% /udev 10240 0 10240 0% /devtmpfs 760204 8404 751800 2% /runtmpfs 1900508 0 1900508 0% /dev/shmtmpfs 5120 0 5120 0% /run/locktmpfs 1900508 0 1900508 0% /sys/fs/cgroup
~/emsdk$ df -iFilesystem Inodes IUsed IFree IUse% Mounted on/dev/sda1 655360 149778 505582 23% /udev 472930 280 472650 1% /devtmpfs 475127 293 474834 1% /runtmpfs 475127 1 475126 1% /dev/shmtmpfs 475127 8 475119 1% /run/locktmpfs 475127 13 475114 1% /sys/fs/cgroup→ ディスク 10GB では足りない???
20GBにした
df.logFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda1 20509288 10045780 9503604 52% /udev 10240 0 10240 0% /devtmpfs 760204 8404 751800 2% /runtmpfs 1900508 0 1900508 0% /dev/shmtmpfs 5120 0 5120 0% /run/locktmpfs 1900508 0 1900508 0% /sys/fs/cgroup $ sudo ./emsdk install sdk-incoming-64bit binaryen-master-64bit
改めて実行していく
???
err.log[ 91%] Linking CXX executable ../../../../bin/clangcollect2: error: ld terminated with signal 9 [Killed]tools/clang/tools/driver/CMakeFiles/clang.dir/build.make:222: recipe for target 'bin/clang-3.9' failedmake[2]: *** [bin/clang-3.9] Error 1make[2]: *** Deleting file 'bin/clang-3.9'CMakeFiles/Makefile2:10809: recipe for target 'tools/clang/tools/driver/CMakeFiles/clang.dir/all' failedmake[1]: *** [tools/clang/tools/driver/CMakeFiles/clang.dir/all] Error 2Makefile:149: recipe for target 'all' failedmake: *** [all] Error 2Build failed due to exception!Working directory: /home/daiki/emsdk/clang/fastcomp/build_incoming_64Command '['make', '-j1']' returned non-zero exit status 2Installation failed! メモリが足りないらしい???
8GBに増設
free.log$ free total used free shared buffers cachedMem: 7679820 157468 7522352 8408 10856 45592-/+ buffers/cache: 101020 7578800Swap: 0 0 0 $ sudo ./emsdk install sdk-incoming-64bit binaryen-master-64bit
改めて実行していく
???
err.logScanning dependencies of target llc[ 93%] Building CXX object tools/llc/CMakeFiles/llc.dir/llc.cpp.o[ 93%] Linking CXX executable ../../bin/llccollect2: error: ld returned 1 exit statustools/llc/CMakeFiles/llc.dir/build.make:141: recipe for target 'bin/llc' failedmake[2]: *** [bin/llc] Error 1CMakeFiles/Makefile2:12629: recipe for target 'tools/llc/CMakeFiles/llc.dir/all' failedmake[1]: *** [tools/llc/CMakeFiles/llc.dir/all] Error 2Makefile:149: recipe for target 'all' failedmake: *** [all] Error 2Build failed due to exception!Working directory: /home/daiki/emsdk/clang/fastcomp/build_incoming_64Command '['make', '-j1']' returned non-zero exit status 2Installation failed! シェルに再ログインしたところ,
No space left on device と出ていた. → え,ディスク20GB でも足りないの??
df.log$ dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda1 20509288 20438540 0 100% /udev 10240 0 10240 0% /devtmpfs 1535964 8404 1527560 1% /runtmpfs 3839908 0 3839908 0% /dev/shmtmpfs 5120 0 5120 0% /run/locktmpfs 3839908 0 3839908 0% /sys/fs/cgroup 30GBにした
$ sudo ./emsdk install sdk-incoming-64bit binaryen-master-64bit
改めて実行していく
log.log[100%] Linking CXX executable ../../bin/llvm-link[100%] Built target llvm-linkDone installing tool 'clang-incoming-64bit'.log.log[100%] Linking CXX executable bin/wasm-shell[100%] Built target wasm-shellDone installing tool 'binaryen-master-64bit'.次のステップ.
$ sudo ./emsdk activate sdk-incoming-64bit binaryen-master-64bit
log.logWriting .emscripten configuration file to user home directory /root/The Emscripten configuration file /root/.emscripten has been rewritten with the following contents:import osLLVM_ROOT='/home/daiki/emsdk/clang/fastcomp/build_incoming_64/bin'NODE_JS='/home/daiki/emsdk/node/4.1.1_64bit/bin/node'EMSCRIPTEN_ROOT='/home/daiki/emsdk/emscripten/incoming'EMSCRIPTEN_NATIVE_OPTIMIZER='/home/daiki/emsdk/emscripten/incoming_64bit_optimizer/optimizer'BINARYEN_ROOT='/home/daiki/emsdk/binaryen/master_64bit_binaryen'SPIDERMONKEY_ENGINE = ''V8_ENGINE = ''TEMP_DIR = '/tmp'COMPILER_ENGINE = NODE_JSJS_ENGINES = [NODE_JS]To conveniently access the selected set of tools from the command line, consider adding the following directories to PATH, or call 'source ./emsdk_env.sh' to do this for you. /home/daiki/emsdk:/home/daiki/emsdk/clang/fastcomp/build_incoming_64/bin:/home/daiki/emsdk/node/4.1.1_64bit/bin:/home/daiki/emsdk/emscripten/incoming:/home/daiki/emsdk/binaryen/masterそして
$ source ./emsdk_env.sh
logAdding directories to PATH:PATH += /home/daiki/emsdkSetting environment variables:EMSDK = /home/daiki/emsdkEM_CONFIG = /home/daiki/.emscripten$ /home/daiki/emsdk/emscripten/incoming/emcc
log/home/daiki/emsdk/emscripten/incoming/emcc --version==============================================================================Welcome to Emscripten!This is the first time any of the Emscripten tools has been run.A settings file has been copied to ~/.emscripten, at absolute path: /home/daiki/.emscriptenIt contains our best guesses for the important paths, which are: LLVM_ROOT = /usr/bin NODE_JS = node EMSCRIPTEN_ROOT = /home/daiki/emsdk/emscripten/incomingPlease edit the file if any of those are incorrect.This command will now exit. When you are done editing those paths, re-run it.==============================================================================$ sudo /home/daiki/emsdk/emscripten/incoming/emcc hello.c -s WASM=1 -o hello.html
あとでパス通す
デフォルトで通らなかったのか
1分くらい待った
logINFO:root:generating system asset: is_vanilla.txt... (this will be cached in "/root/.emscripten_cache/is_vanilla.txt" for subsequent builds)INFO:root: - okINFO:root:(Emscripten: Running sanity checks)WARNING:root:java does not seem to exist, required for closure compiler, which is optional (define JAVA in /root/.emscripten if you want it)WARNING:root:closure compiler will not be availableINFO:root:generating system library: libc.bc... (this will be cached in "/root/.emscripten_cache/asmjs/libc.bc" for subsequent builds)INFO:root: - okINFO:root:generating system library: dlmalloc.bc... (this will be cached in "/root/.emscripten_cache/asmjs/dlmalloc.bc" for subsequent builds)INFO:root: - okINFO:root:generating system library: wasm-libc.bc... (this will be cached in "/root/.emscripten_cache/asmjs/wasm-libc.bc" for subsequent builds)INFO:root: - oklsすると,このようなファイル達ができていた
なんでこんなに色々と
hello.asm.js hello.c hello.html hello.js hello.wasm ひとまずOKそう
メモリ 8GB 高いので 4GB に下げたけど動くか?
余裕でいけた
ビルド時はメモリがたくさん必要