|
| 1 | +# Building and testing git2cpp in WebAssembly |
| 2 | + |
| 3 | +This directory contains everything needed to build the local `git2cpp` source code as an |
| 4 | +WebAssembly [Emscripten-forge](https://emscripten-forge.org/) package, create local |
| 5 | +[cockle](https://github.com/jupyterlite/cockle) and |
| 6 | +[JupyterLite terminal](https://github.com/jupyterlite/terminal) deployments that run in a browser, |
| 7 | +and test the WebAssembly build. |
| 8 | + |
| 9 | +It works on Linux and macOS but not Windows. |
| 10 | + |
| 11 | +There are 5 sub-directories: |
| 12 | + |
| 13 | +- `recipe`: build local `git2cpp` source code into an Emscripten-forge package. |
| 14 | +- `cockle-deploy`: create a `cockle` deployment in the `serve` directory. |
| 15 | +- `lite-deploy`: create a JupyterLite `terminal` deployment in the `serve` directory. |
| 16 | +- `serve`: where the two deployments are served from. |
| 17 | +- `test`: test the WebAssembly build. |
| 18 | + |
| 19 | +## Build and deploy |
| 20 | + |
| 21 | +The build, deploy and test process uses a separate `micromamba` environment defined in |
| 22 | +`wasm-environment.yml`. To set this up use from within this directory: |
| 23 | + |
| 24 | +```bash |
| 25 | +micromamba create -f wasm-environment.yml |
| 26 | +micromamba activate git2cpp-wasm |
| 27 | +``` |
| 28 | + |
| 29 | +Then to build the WebAssembly package, both deployments and the testing resources use: |
| 30 | + |
| 31 | +```bash |
| 32 | +cmake . |
| 33 | +make |
| 34 | +``` |
| 35 | + |
| 36 | +The built emscripten-forge package will be file named something like `git2cpp-0.0.5-h7223423_1.tar.bz2` |
| 37 | +in the directory `recipe/em-force-recipes/output/emscripten-wasm32`. |
| 38 | + |
| 39 | +The local deployments in the `serve` directory can be manually checked using: |
| 40 | + |
| 41 | +```bash |
| 42 | +make serve |
| 43 | +``` |
| 44 | + |
| 45 | +and open a web browser at http://localhost:8080/. Confirm that the local build of `git2cpp` is being |
| 46 | +used in the two deployments by running `cockle-config package` at the command line, the output |
| 47 | +should be something like: |
| 48 | + |
| 49 | +<img alt="cockle-config output" src="cockle-config.png"> |
| 50 | + |
| 51 | +Note that the `source` for the `git2cpp` package is the local filesystem rather than from |
| 52 | +`prefix.dev`. The version number of `git2cpp` in this table is not necessarily correct as it is the |
| 53 | +version number of the current Emscripten-forge recipe rather than the version of the local `git2cpp` |
| 54 | +source code which can be checked using `git2cpp -v` at the `cockle`/`terminal` command line. |
| 55 | + |
| 56 | +## Test |
| 57 | + |
| 58 | +To test the WebAssembly build use: |
| 59 | + |
| 60 | +```bash |
| 61 | +make test |
| 62 | +``` |
| 63 | + |
| 64 | +This runs (some of) the tests in the top-level `test` directory with various monkey patching so that |
| 65 | +`git2cpp` commands are executed in the browser. If there are problems running the tests then ensure |
| 66 | +you have the latest `playwright` browser installed: |
| 67 | + |
| 68 | + |
| 69 | +```bash |
| 70 | +playwright install chromium |
| 71 | +``` |
| 72 | + |
| 73 | +## Rebuild |
| 74 | + |
| 75 | +After making changes to the local `git2cpp` source code you can rebuild the WebAssembly package, |
| 76 | +both deployments and test code using: |
| 77 | + |
| 78 | +```bash |
| 79 | +make rebuild |
| 80 | +``` |
0 commit comments