jedisct1 / libhydrogen

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.
https://libhydrogen.org
Other
631 stars 94 forks source link

Support for wasm32-freestanding #96

Closed creationix closed 4 years ago

creationix commented 4 years ago

I see there appears to be some support for wasm in the codebase. I believe it was tested with emscripten. I would love to use libhydrogen in a wasm based project, but I'm having a very hard time compiling it for the freestanding target using vanilla clang or zig cc. Most the issues revolve around usage of libc headers and the random sources.

Looking at the supported platforms, I believe it should be possible to support wasm without emscripten's supporting libraries or even needing the wasi runtime.

Am I correct in this assumption?

jedisct1 commented 4 years ago

Current support is for WASI (it was probably the first library supporting WASI :) ), and it should still compile out of the box using clang with a WASI sysroot.

No emscripten needed.

jedisct1 commented 4 years ago

wasm32-wasi-toolchain.cmake should have what it takes to compile to wasm32-wasi using cmake, but even without cmake, using clang with the correct sysroot and --target=wasm32-wasi should build the library.

libhyodrogen doesn't use much of WASI, so it should be possible to even avoid it, but considering the fact that everything is eventually statically linked, it shouldn't make much of a difference.