From 936fe8c0adcde83746ab4d9a9916295e8519251a Mon Sep 17 00:00:00 2001 From: Alex Kerr Date: Mon, 24 Jan 2022 21:43:57 +0000 Subject: [PATCH] Not-quite-working WASM --- Romulus-M/CMakeLists.txt | 13 +++++++++++-- Romulus-M/export.h | 5 ++++- Romulus-M/main.c | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Romulus-M/main.c diff --git a/Romulus-M/CMakeLists.txt b/Romulus-M/CMakeLists.txt index 613b402..2f3c033 100644 --- a/Romulus-M/CMakeLists.txt +++ b/Romulus-M/CMakeLists.txt @@ -5,5 +5,14 @@ set(SRC skinny_reference.c ) -add_library(romulus-m SHARED ${SRC}) -install(TARGETS romulus-m) \ No newline at end of file +if(EMSCRIPTEN) + # WASM requires an executable, so we use a dummy target that doesn't do anything + # and link our library into it. + add_library(romulus-m STATIC ${SRC}) + add_executable(romulus-m-wasm "main.c") + target_link_libraries(romulus-m-wasm PRIVATE romulus-m) + target_link_options(romulus-m-wasm PRIVATE -s EXPORTED_FUNCTIONS=['_main', '_crypto_aead_encrypt', '_crypto_aead_decrypt']) +else() + add_library(romulus-m SHARED ${SRC}) + install(TARGETS romulus-m) +endif() diff --git a/Romulus-M/export.h b/Romulus-M/export.h index 92fa7ab..3776f2f 100644 --- a/Romulus-M/export.h +++ b/Romulus-M/export.h @@ -8,6 +8,9 @@ #ifdef _WIN32 #define EXPORT __declspec(dllexport) -#else +#elif __linux__ #define EXPORT __attribute__((visibility("default"))) +#elif __EMSCRIPTEN__ +#include +#define EXPORT EMSCRIPTEN_KEEPALIVE #endif diff --git a/Romulus-M/main.c b/Romulus-M/main.c new file mode 100644 index 0000000..982ce50 --- /dev/null +++ b/Romulus-M/main.c @@ -0,0 +1,10 @@ +/** + * BUTLERSAURUS 2022 addition + * + * This file exists to create a fake dummy executable target, which is required + * when compiling for WASM. + */ +int main(void) +{ + return 0; +}