GettingEmscriptenToWork.wiki
author Wuzzy
Wed, 02 May 2018 22:48:07 +0100
changeset 1330 d92ed3272533
parent 223 da62b8273c12
permissions -rw-r--r--
LuaLibraries: fix indent
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
222
bce10fea1e6e Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 221
diff changeset
     1
#summary This page is a brief introduction of how to get emscripten to work.
221
xymengxy@gmail.com
parents: 220
diff changeset
     2
#labels emscripten
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     3
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     4
= Introduction =
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     5
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     6
This guide is not targeted to hedgewars currently but meant to help you set up the environment to get emscripten working.
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     7
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     8
= Set Up emscripten =
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
     9
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    10
You can follow the steps here to set up emscripten: https://github.com/kripken/emscripten/wiki/Tutorial
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    11
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    12
Be sure to set up the correct path in ~/.emscripten. The default paths are mostly not suitable for you.
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    13
220
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    14
Building llvm 3.0 from source has one big advantage since you can point the LLVM_ROOT to where you build it, which won't affect your local version (if it is not 3.0).
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    15
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    16
= Potential problems =
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    17
220
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    18
  # Make sure your node.js is the latest version, earlier versions won't work for some reasons;
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    19
  # Make sure the version of your llvm and clang is exactly 3.0. Lower versions won't compile and higher versions may fail in some cases due to the removal of llvm-ld. For Ubuntu users, 11.10 doesn't have pre-built llvm 3.0 packages so you have to build from source files. I haven't tried llvm 3.1 (which should work in theory), but to make it less troublesome, llvm 3.0 is recommended.
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    20
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    21
= How to get llvm and clang 3.0 =
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    22
220
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    23
If you can checkout through svn, follow the official guide (checkout release_30 branch):
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    24
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    25
http://llvm.org/docs/GettingStarted.htm
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    26
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    27
If you cannot checkout through svn for some network issues, you can find git mirrors in github here (which should work for everyone):
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    28
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    29
https://github.com/llvm-mirror/llvm (checkout release_30 branch)
220
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    30
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    31
https://github.com/llvm-mirror/clang (checkout release_30 branch)
220
122b02f4f292 Edited wiki page GettingEmscriptenToWork through web user interface.
xymengxy@gmail.com
parents: 219
diff changeset
    32
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    33
https://github.com/llvm-mirror/compiler-rt (checkout release_30 branch)
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    34
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    35
Follow the official guide to build from source code (http://llvm.org/docs/GettingStarted.html).
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    36
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    37
= Some tests =
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    38
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    39
There are a lot of tests in the tests folder. You can refer to (https://github.com/kripken/emscripten/wiki/Tutorial) for more details.
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    40
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    41
Here I just give some simple examples.
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    42
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    43
(Assume that you are in the emscripten root directory, where you can see the 'emcc' file)
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    44
221
xymengxy@gmail.com
parents: 220
diff changeset
    45
1. *Hello World*
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    46
221
xymengxy@gmail.com
parents: 220
diff changeset
    47
{{{
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    48
./emcc tests/hello_world.cpp
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    49
node a.out.js
221
xymengxy@gmail.com
parents: 220
diff changeset
    50
}}}
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    51
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    52
You should be able to see "hello world!" in the terminal
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    53
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    54
If you want to have it run in browsers, you can type this (as in official tutorial):
221
xymengxy@gmail.com
parents: 220
diff changeset
    55
{{{
xymengxy@gmail.com
parents: 220
diff changeset
    56
./emcc tests/hello_world.cpp -o hello.html
xymengxy@gmail.com
parents: 220
diff changeset
    57
}}}
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    58
221
xymengxy@gmail.com
parents: 220
diff changeset
    59
2. *Get the glgears to work in browsers*
xymengxy@gmail.com
parents: 220
diff changeset
    60
{{{
xymengxy@gmail.com
parents: 220
diff changeset
    61
./emcc tests/hello_world_gles.c -o hello_world_gles.html
xymengxy@gmail.com
parents: 220
diff changeset
    62
}}}
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    63
221
xymengxy@gmail.com
parents: 220
diff changeset
    64
llvm 3.2+ won't compile this demo. The reason is that this demo uses malloc which has to been compiled first from dlmalloc. However emscripten uses llvm-ld as the linker, which has been removed in llvm 3.2+, and the result is that you will encounter some strange error messages saying that "no such file or directory". If you get this message, check your llvm and clang version.
xymengxy@gmail.com
parents: 220
diff changeset
    65
xymengxy@gmail.com
parents: 220
diff changeset
    66
3. *Get the file system to work*
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    67
221
xymengxy@gmail.com
parents: 220
diff changeset
    68
{{{
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    69
./emcc --preload-file hello_world_file.txt tests/hello_world_file.c -o hello_world_file.html
221
xymengxy@gmail.com
parents: 220
diff changeset
    70
}}}
219
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    71
6b25660d5bbf Created wiki page through web user interface.
xymengxy@gmail.com
parents:
diff changeset
    72
Note that you must add "--preload-file hello_world_file.txt" in the command line. This line tells emcc that it should embed the file loading code into the js file. Before the application runs, all files will be loaded first. If you don't do this, it won't find this file.