UNPKG

2.63 kBMarkdownView Raw
1# How to (re)build the Javascript from the C sources
2
3You will *not* need to do this for a fresh checkout, since the project
4policy is to include the generated javascript as a checked-in file.
5
6## Ingredients
7
8 - Python 2.x
9 - Docker, or a recent Emscripten SDK
10 - Node.js and npm to run the [mocha](http://visionmedia.github.io/mocha/)-based tests
11
12Recently, I have had trouble getting a stable Emscripten setup on my
13machines, so I now primarily use a
14[Dockerized Emscripten](https://hub.docker.com/r/trzeci/emscripten/)
15courtesy of Docker user `trzeci`.
16
17Within the `js-nacl` directory,
18
19 - [`nacl_cooked.js`](nacl_cooked.js) is the high-level Javascript
20 interface to the low-level code.
21
22 - [`nacl_cooked_prefix.js`](nacl_cooked_prefix.js) and
23 [`nacl_cooked_suffix.js`](nacl_cooked_suffix.js) are wrapped
24 around `nacl_cooked.js` and `libsodium.js` to create
25 `lib/nacl_factory.js`.
26
27 - [`test/runner.html`](test/runner.html) runs the Mocha tests in the browser.
28
29 - [`test/tests.js`](test/tests.js) is the source code for the test cases themselves.
30
31 - [`benchmark.html`](benchmark.html) and
32 [`benchmark.js`](benchmark.js) are trivial speed measurements for
33 running in the browser.
34
35## Method
36
37The `js-nacl` Makefile assumes the use of Docker Emscripten.
38
39To rebuild everything:
40
41 make veryclean all
42
43This will completely remove any compilation products, and recompile
44everything.
45
46Other Makefile targets:
47
48 - `make` or `make test`: builds the library if necessary and then
49 runs the test suite using node.js.
50
51 - `make clean`: removes generated Javascript, but does not remove the
52 unpacked and pre-processed `libsodium` tarball contents.
53
54 - `make veryclean`: as `make clean`, but also removes the contents of
55 the `libsodium` tarball.
56
57 - `make all`: performs all the build steps.
58
59### Using the Emscripten SDK instead of Docker
60
61If you are not using the Docker Emscripten image, follow the
62instructions from the
63[Emscripten tutorial](http://emscripten.org/Tutorial) to get
64Emscripten ready to run.
65
66Once `emcc` is on your `$PATH` somewhere, build the `libsodium.js`
67file by unpacking the libsodium sources, applying patches as necessary
68(see the Makefile), changing to the `dist-build` directory in the
69unpacked sources, and running `./emscripten.sh --sumo`.
70
71If you for some reason need to use a different python than `python`,
72set the `PYTHON` makefile variable; for example,
73
74 make PYTHON=python2.7
75
76Similarly, set `EMCC` to the path to your `emcc` binary if it's not on
77your `$PATH`.
78
79## Serves three
80
81The build products, Javascript for use in the browser and in node.js,
82will be in `lib/*`.