Skip to content

Commit

Permalink
WASM support
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Oct 29, 2024
1 parent ce163e7 commit 29024cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ file(GLOB_RECURSE
)

# Build and install Entity library
add_library(LangulusEntity ${LANGULUS_LIBRARY_TYPE}
add_langulus_library(LangulusEntity
$<TARGET_OBJECTS:LangulusLogger>
$<TARGET_OBJECTS:LangulusRTTI>
$<$<BOOL:${LANGULUS_FEATURE_MANAGED_MEMORY}>:$<TARGET_OBJECTS:LangulusFractalloc>>
Expand Down
26 changes: 10 additions & 16 deletions source/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <Windows.h>
#endif

#if LANGULUS_OS(LINUX)
#if LANGULUS_OS(LINUX) or LANGULUS_COMPILER(WASM)
#include <dlfcn.h>
#endif

Expand Down Expand Up @@ -64,12 +64,10 @@ namespace Langulus::Entity
void UnloadSharedLibrary(HMODULE library) {
FreeLibrary(library);
}
#elif LANGULUS_OS(LINUX)
#else
void UnloadSharedLibrary(void* library) {
dlclose(library);
}
#else
#error Unsupported OS
#endif

/// Runtime construction
Expand Down Expand Up @@ -356,6 +354,8 @@ namespace Langulus::Entity
path += ".dll";
#elif LANGULUS_OS(LINUX)
path += ".so";
#elif LANGULUS_COMPILER(WASM)
path += ".wasm";
#else
#error Unsupported OS
#endif
Expand All @@ -366,10 +366,8 @@ namespace Langulus::Entity
// Load the library
#if LANGULUS_OS(WINDOWS)
const auto dll = LoadLibraryA(path.GetRaw());
#elif LANGULUS_OS(LINUX)
#else
const auto dll = dlopen(path.GetRaw(), RTLD_NOW);
#else
#error Unsupported OS
#endif

if (not dll) {
Expand All @@ -395,35 +393,33 @@ namespace Langulus::Entity
GetProcAddress(dll, LANGULUS_MODULE_CREATE_TOKEN()));
library.mInfo = reinterpret_cast<A::Module::InfoFunction>(
GetProcAddress(dll, LANGULUS_MODULE_INFO_TOKEN()));
#elif LANGULUS_OS(LINUX)
#else
library.mEntry = reinterpret_cast<A::Module::EntryFunction>(
dlsym(dll, LANGULUS_MODULE_ENTRY_TOKEN()));
library.mCreator = reinterpret_cast<A::Module::CreateFunction>(
dlsym(dll, LANGULUS_MODULE_CREATE_TOKEN()));
library.mInfo = reinterpret_cast<A::Module::InfoFunction>(
dlsym(dll, LANGULUS_MODULE_INFO_TOKEN()));
#else
#error Unsupported OS
#endif

if (not library.mEntry) {
Logger::Error("Module `", path, "` has no valid entry point - ",
"the function " LANGULUS_MODULE_ENTRY_TOKEN() " is missing");
(void)UnloadSharedLibrary(library);
(void) UnloadSharedLibrary(library);
return {};
}

if (not library.mCreator) {
Logger::Error("Module `", path, "` has no valid instantiation point - ",
"the function " LANGULUS_MODULE_CREATE_TOKEN() " is missing");
(void)UnloadSharedLibrary(library);
(void) UnloadSharedLibrary(library);
return {};
}

if (not library.mInfo) {
Logger::Error("Module `", path, "` has no valid information point - ",
"the function " LANGULUS_MODULE_INFO_TOKEN() " is missing");
(void)UnloadSharedLibrary(library);
(void) UnloadSharedLibrary(library);
return {};
}

Expand Down Expand Up @@ -568,11 +564,9 @@ namespace Langulus::Entity
#if LANGULUS_OS(WINDOWS)
Entity::UnloadSharedLibrary(
reinterpret_cast<HMODULE>(library.mHandle));
#elif LANGULUS_OS(LINUX)
#else
Entity::UnloadSharedLibrary(
reinterpret_cast<void*>(library.mHandle));
#else
#error Unsupported OS
#endif
return true;
}
Expand Down

0 comments on commit 29024cf

Please sign in to comment.