| Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 Adblock Plus core | 1 Adblock Plus core | 
| 2 ================= | 2 ================= | 
| 3 | 3 | 
| 4 This repository contains the generic Adblock Plus code that's shared between | 4 This repository contains the generic Adblock Plus code that's shared between | 
| 5 platforms. This repository is not designed to be used directly, but instead to | 5 platforms. This repository is not designed to be used directly, but instead to | 
| 6 serve as a dependency for `adblockplus`, `adblockpluschrome` and | 6 serve as a dependency for `adblockplus`, `adblockpluschrome` and | 
| 7 `libadblockplus`. | 7 `libadblockplus`. | 
| 8 | 8 | 
| 9 Compiling C++ code | 9 Compiling C++ code | 
| 10 ------------------ | 10 ------------------ | 
| 11 | 11 | 
| 12 ### Purpose | 12 ### Purpose | 
| 13 | 13 | 
| 14 In order to improve performance and memory usage, some of the code (located | 14 In order to improve performance and memory usage, some of the code (located | 
| 15 inside the `compiled` directory) is written in C++ and compiled to JavaScript | 15 inside the `compiled` directory) is written in C++ and compiled to JavaScript | 
| 16 via Empscripten. | 16 via Empscripten. | 
| 17 | 17 | 
| 18 ### Requirements | 18 ### Requirements | 
| 19 | 19 | 
| 20 * [Emscripten 1.37.3](https://github.com/kripken/emscripten) | 20 * [Emscripten 1.37.3](https://github.com/kripken/emscripten) | 
| 21 * [Python 2.7](https://www.python.org) | 21 * [Python 2.7](https://www.python.org) | 
| 22 * [meson](https://www.mesonbuild.com) | 22 * [meson 0.40.0+](https://www.mesonbuild.com) | 
| 23 * [ninja](https://www.ninja-build.org) | 23 * [ninja](https://www.ninja-build.org) | 
| 24 | |
| 25 Make sure that meson and ninja are in your PATH. | |
| 24 | 26 | 
| 25 ### Running Emscripten | 27 ### Running Emscripten | 
| 26 | 28 | 
| 27 After installing and configuring Emscripten you can setup the build | 29 After installing and configuring Emscripten you can setup the build | 
| 28 with the following commands: | 30 with the following commands: | 
| 29 | 31 | 
| 30 mkdir build | |
| 
 
Wladimir Palant
2017/10/12 08:46:09
This step is unnecessary, meson will create the di
 
hub
2017/10/12 18:12:10
Done.
 
 | |
| 31 meson build | 32 meson build | 
| 
 
Wladimir Palant
2017/10/12 08:46:09
By default, a debug build will be created. So we s
 
hub
2017/10/12 18:12:11
Done.
 
 | |
| 33 | |
| 34 By default it will create a debug build. Pass `--buildtype release` to | |
| 35 create a release build. | |
| 32 | 36 | 
| 33 Then to build just do: | 37 Then to build just do: | 
| 34 | 38 | 
| 35 cd build | 39 ninja -C build | 
| 36 ninja | 40 | 
| 
 
Wladimir Palant
2017/10/12 08:46:08
We should mention that running meson is normally a
 
hub
2017/10/12 18:12:10
Done.
 
 | |
| 41 This will regenerate the build files as needed. | |
| 37 | 42 | 
| 38 This will produce a `lib/compiled.js` exporting the classes defined in C++ code. | 43 This will produce a `lib/compiled.js` exporting the classes defined in C++ code. | 
| 39 | 44 | 
| 40 ### Technical details | 45 ### Technical details | 
| 41 | 46 | 
| 42 Compilation is currently a two-step process. In the bindings generation step, | 47 Compilation is currently a two-step process. In the bindings generation step, | 
| 43 the source files are compiled into `compiled/bindings.cpp.js` with the | 48 the source files are compiled into `compiled/bindings.cpp.js` with the | 
| 44 `PRINT_BINDINGS` symbol defined. This application is then executed via Node.js | 49 `PRINT_BINDINGS` symbol defined. This application is then executed via Node.js | 
| 45 and will print JavaScript wrappers for the C++ classes to | 50 and will print JavaScript wrappers for the C++ classes to | 
| 46 `build/bindings.js` according to definitions within the `EMSCRIPTEN_BINDINGS` | 51 `build/bindings.js` according to definitions within the `EMSCRIPTEN_BINDINGS` | 
| 47 macro in `compiled/bindings.cpp`. | 52 macro in `compiled/bindings.cpp`. | 
| 48 | 53 | 
| 49 In the actual compilation step the source files are compiled into | 54 In the actual compilation step the source files are compiled into | 
| 50 `build/compiled.js` without the `PRINT_BINDINGS` symbol, so that the | 55 `lib/compiled.js` without the `PRINT_BINDINGS` symbol, so that the | 
| 
 
Wladimir Palant
2017/10/12 08:46:08
It's still lib/compiled.js right now.
We should u
 
hub
2017/10/12 18:12:11
Done.
 
 | |
| 51 `EMSCRIPTEN_BINDINGS` macro ignores its contents and merely emits some generic | 56 `EMSCRIPTEN_BINDINGS` macro ignores its contents and merely emits some generic | 
| 52 functions necessary for the JavaScript bindings to work. The previously | 57 functions necessary for the JavaScript bindings to work. The previously | 
| 53 generated `compiled/bindings.js` file is added to the end of Emscripten output. | 58 generated `compiled/bindings.js` file is added to the end of Emscripten output. | 
| 54 | 59 | 
| 55 The binding generation approach is heavily inspired by | 60 The binding generation approach is heavily inspired by | 
| 56 [embind](http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_an d_javascript/embind.html). | 61 [embind](http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_an d_javascript/embind.html). | 
| 57 However, embind doesn't use a separate build step to produce the bindings, the | 62 However, embind doesn't use a separate build step to produce the bindings, the | 
| 58 bindings are rather generated dynamically at run time. As a side-effect, it | 63 bindings are rather generated dynamically at run time. As a side-effect, it | 
| 59 increases the build size considerably and also imposes a significant performance | 64 increases the build size considerably and also imposes a significant performance | 
| 60 penalty. Also, generating JavaScript code dynamically is discouraged for browser | 65 penalty. Also, generating JavaScript code dynamically is discouraged for browser | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 Linting | 99 Linting | 
| 95 ------- | 100 ------- | 
| 96 | 101 | 
| 97 You can lint the code using [ESLint](http://eslint.org). | 102 You can lint the code using [ESLint](http://eslint.org). | 
| 98 | 103 | 
| 99 eslint *.js chrome lib test | 104 eslint *.js chrome lib test | 
| 100 | 105 | 
| 101 You will need to set up ESLint and our configuration first, see | 106 You will need to set up ESLint and our configuration first, see | 
| 102 [eslint-config-eyeo](https://hg.adblockplus.org/codingtools/file/tip/eslint-conf ig-eyeo) | 107 [eslint-config-eyeo](https://hg.adblockplus.org/codingtools/file/tip/eslint-conf ig-eyeo) | 
| 103 for more information. | 108 for more information. | 
| LEFT | RIGHT |