| 1 |
Installation |
| 2 |
============ |
| 3 |
|
| 4 |
Prebuilt binaries are available for Linux (amd64), MacOS (amd64 & arm64) and Windows (amd64) and attached to `the releases <https://github.com/Syndace/libxeddsa/releases>`_. They can also be found in the build artifacts of the `Build & Test workflow <https://github.com/Syndace/libxeddsa/actions/workflows/build-and-test.yml>`_. To use libxeddsa, `libsodium <https://download.libsodium.org/doc/>`_ has to be installed on the system. |
| 5 |
|
| 6 |
The library can be built with `CMake <https://cmake.org/>`_ and was tested to build successfully on Linux, MacOS and Windows. |
| 7 |
|
| 8 |
Linux |
| 9 |
----- |
| 10 |
|
| 11 |
To build the library from source on Linux, ``cmake`` and ``make`` are required next to a C compiler and libsodium + development headers. On apt-based systems (Debian, Ubuntu, Mint) these are usually available in packages called ``cmake``, ``build-essential``, ``libsodium-dev`` and ``libsodiumxx``, where ``xx`` is a two-digit number that differs between systems and versions (e.g. 23 on the latest Debian and Ubuntu). |
| 12 |
|
| 13 |
With everything installed, run the following steps to build the library and to run the tests:: |
| 14 |
|
| 15 |
$ mkdir build/ |
| 16 |
$ cd build/ |
| 17 |
$ cmake .. |
| 18 |
$ make |
| 19 |
$ ctest .. |
| 20 |
|
| 21 |
The static and dynamic libraries will be located in ``bin/`` after the build, together with the test executables. |
| 22 |
|
| 23 |
MacOS |
| 24 |
----- |
| 25 |
|
| 26 |
To build the library from source on MacOS, ``cmake`` and ``make`` are required next to a C compiler and libsodium. CMake, make and libsodium can be installed from `Homebrew <https://brew.sh/>`_ and are available in packages called ``cmake``, ``make`` and ``libsodium``. |
| 27 |
|
| 28 |
With everything installed, run the following steps to build the library and to run the tests:: |
| 29 |
|
| 30 |
$ mkdir build/ |
| 31 |
$ cd build/ |
| 32 |
$ cmake .. |
| 33 |
$ make |
| 34 |
$ ctest .. |
| 35 |
|
| 36 |
The static and dynamic libraries will be located in ``bin/`` after the build, together with the test executables. |
| 37 |
|
| 38 |
Windows |
| 39 |
------- |
| 40 |
|
| 41 |
To build the library from source on Windows, ``cmake``, libsodium and a build environment like MinGW, MSYS or Visual Studio are required. CMake can be installed using the `binary installer package <https://cmake.org/download/>`_ from CMake's website. libsodium headers and binaries are available on `libsodium's download page <https://download.libsodium.org/libsodium/releases/>`_. The exact build process depends on you build environment. In general, the first step is to use CMake to create the build files for you build environment:: |
| 42 |
|
| 43 |
$ mkdir build/ |
| 44 |
$ cd build/ |
| 45 |
$ cmake -G "YourBuildEnv" .. |
| 46 |
|
| 47 |
where ``YourBuildEnv`` depends on your build environment. ``cmake --help`` lists available build systems you can pass to ``-G``. If CMake has trouble locating libsodium, set the ``sodium_DIR`` environment variable to the directory containing the headers and the files. |
| 48 |
|
| 49 |
The next step is to build the library, which again depends on your build system. With MinGW for example, use ``mingw32-make``. |
| 50 |
|
| 51 |
When the build is done, run ``ctest -C Debug ..`` to run the tests in debug configuration, and ``ctest -C Release ..`` to run them in release configuration. |
| 52 |
|
| 53 |
Emscripten |
| 54 |
---------- |
| 55 |
|
| 56 |
The library can be compiled for the web using `Emscripten <https://emscripten.org/>`_. To so so, `set up emsdk <https://emscripten.org/docs/getting_started/downloads.html>`_ and proceed as follows (instructions for Linux): |
| 57 |
|
| 58 |
Download and build libsodium with Emscripten |
| 59 |
"""""""""""""""""""""""""""""""""""""""""""" |
| 60 |
|
| 61 |
libsodium supports compilation with Emscripten and comes with the scripts required to do so:: |
| 62 |
|
| 63 |
$ mkdir /tmp/libxeddsa-emscripten/ |
| 64 |
$ cd /tmp/libxeddsa-emscripten/ |
| 65 |
$ wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz |
| 66 |
$ tar xzf libsodium-1.0.18-stable.tar.gz |
| 67 |
$ cd libsodium-stable/ |
| 68 |
$ dist-build/emscripten.sh --standard |
| 69 |
|
| 70 |
Download and build libxeddsa with Emscripten |
| 71 |
"""""""""""""""""""""""""""""""""""""""""""" |
| 72 |
|
| 73 |
libxeddsa uses CMake, which is supported by Emscripten:: |
| 74 |
|
| 75 |
$ cd /tmp/libxeddsa-emscripten/ |
| 76 |
$ git clone https://github.com/Syndace/libxeddsa.git |
| 77 |
$ cd libxeddsa/ |
| 78 |
$ mkdir build/ |
| 79 |
$ cd build/ |
| 80 |
$ export sodium_INCLUDE_DIR=/tmp/libxeddsa-emscripten/libsodium-stable/libsodium-js/include |
| 81 |
$ export sodium_LIBRARY=/tmp/libxeddsa-emscripten/libsodium-stable/libsodium-js/lib/libsodium.a |
| 82 |
$ emcmake cmake .. |
| 83 |
$ emmake make |
| 84 |
$ emcmake ctest .. |
| 85 |
|
| 86 |
Link the WebAssembly module |
| 87 |
""""""""""""""""""""""""""" |
| 88 |
|
| 89 |
With libsodium and libxeddsa compiled for Emscripten, the static libraries can be linked together and the relevant symbols exported:: |
| 90 |
|
| 91 |
$ cd /tmp/libxeddsa-emscripten/libxeddsa/bin/ |
| 92 |
$ emcc --no-entry -o libxeddsa.js -O3 \ |
| 93 |
-I ../include/ -I ../ref10/include/ -I $sodium_INCLUDE_DIR \ |
| 94 |
-L . -L $(dirname $sodium_LIBRARY) -l sodium -l combined_static \ |
| 95 |
-s EXPORTED_FUNCTIONS=$(cat ../emscripten/exported_functions.txt | tr -d "\n") \ |
| 96 |
-s EXPORTED_RUNTIME_METHODS=ccall,cwrap |
| 97 |
|
| 98 |
This creates the two files ``libxeddsa.js`` and ``libxeddsa.wasm``, which can now be embedded in a JavaScript application. The file ``emscripten/libxeddsa-wrapper.js`` can be loaded after the module is fully intialized (see `Emscripten's "Module.onRuntimeInitialized" <https://emscripten.org/docs/api_reference/module.html#Module.onRuntimeInitialized>`_) to create simple wrappers of the exported functions for direct use from JavaScript. |