Skip to content

Commit

Permalink
Wasm (#1)
Browse files Browse the repository at this point in the history
* make compatible with most recent lite requirements

* use same binary names

* added missing destructors

* remove superflous moves

* actually compiling wasm interpreter..
  • Loading branch information
DerThorsten authored Jan 3, 2024
1 parent bff4fb1 commit 5a5aca5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
38 changes: 22 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ OPTION(XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON)
OPTION(XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instead of the static library)" ON)
OPTION(XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON)

OPTION(XEUS_CPP_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF)

if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)

if(EMSCRIPTEN)
add_compile_definitions(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
message("Build with emscripten")
SET(XEUS_CPP_BUILD_STATIC ON)
Expand Down Expand Up @@ -90,7 +90,7 @@ else()
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
if(NOT EMSCRIPTEN)
add_compile_options(-Wunused-parameter -Wextra -Wreorder)
endif()

Expand All @@ -103,7 +103,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
endif ()
endif ()

if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[ENV']\"")
endif()
Expand Down Expand Up @@ -131,6 +131,10 @@ set(XEUS_CPP_SRC
src/xparser.cpp
)

if(EMSCRIPTEN)
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
endif()

set(XEUS_CPP_MAIN_SRC
src/main.cpp
)
Expand Down Expand Up @@ -192,7 +196,7 @@ macro(xeus_cpp_set_kernel_options target_name)
target_link_libraries(${target_name} PRIVATE xeus-cpp-static)
endif()

if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
if(NOT EMSCRIPTEN)
find_package(Threads)
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
endif()
Expand Down Expand Up @@ -238,7 +242,7 @@ macro(xeus_cpp_create_target target_name linkage output_name)
elseif (APPLE)
target_link_libraries(${target_name} PRIVATE "-undefined dynamic_lookup")
endif ()
if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
if(NOT EMSCRIPTEN)
find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
endif()
Expand Down Expand Up @@ -291,14 +295,14 @@ if (XEUS_CPP_BUILD_EXECUTABLE)
target_link_libraries(xcpp PRIVATE xeus-zmq)
endif()

if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
include(WasmBuildOptions)
find_package(xeus-lite REQUIRED)
add_executable(xcpp_wasm src/main_emscripten_kernel.cpp )
target_link_libraries(xcpp_wasm PRIVATE xeus-lite)
xeus_cpp_set_kernel_options(xcpp_wasm)
xeus_wasm_compile_options(xcpp_wasm)
xeus_wasm_link_options(xcpp_wasm "web,worker")
add_executable(xcpp src/main_emscripten_kernel.cpp )
target_link_libraries(xcpp PRIVATE xeus-lite)
xeus_cpp_set_kernel_options(xcpp)
xeus_wasm_compile_options(xcpp)
xeus_wasm_link_options(xcpp "web,worker")
endif()

# Installation
Expand All @@ -325,7 +329,9 @@ endif ()
if (XEUS_CPP_BUILD_EXECUTABLE)
install(TARGETS xcpp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

if(XEUS_CPP_BUILD_EXECUTABLE OR EMSCRIPTEN)
# Configuration and data directories for jupyter and xeus-cpp
set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory")

Expand Down Expand Up @@ -391,13 +397,13 @@ if (XEUS_CPP_BUILD_SHARED)
DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR})
endif ()

if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
install(TARGETS xcpp_wasm
if(EMSCRIPTEN)
install(TARGETS xcpp
ARCHIVE DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR})

install(FILES
"$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm.js"
"$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm.wasm"
"$<TARGET_FILE_DIR:xcpp>/xcpp.js"
"$<TARGET_FILE_DIR:xcpp>/xcpp.wasm"
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif ()

Expand Down
5 changes: 1 addition & 4 deletions include/xeus-cpp/xinterpreter_wasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ namespace xcpp
public:

wasm_interpreter();
virtual ~wasm_interpreter();
virtual ~wasm_interpreter() = default;

private:

void configure_impl() override;
};
}

Expand Down
2 changes: 2 additions & 0 deletions include/xeus-cpp/xmagics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ namespace xcpp

struct xmagic_line
{
virtual ~xmagic_line() = default;
virtual void operator()(const std::string& line) = 0;
};

struct xmagic_cell
{
virtual ~xmagic_cell() = default;
virtual void operator()(const std::string& line, const std::string& cell) = 0;
};

Expand Down
6 changes: 3 additions & 3 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ process_code(clang::Interpreter& Interp, const std::string& code, llvm::raw_stri
auto Addr = Interp.getSymbolAddress(clang::GlobalDecl(VD));
if (!Addr)
{
llvm::logAllUnhandledErrors(std::move(Addr.takeError()), error_stream, "error: ");
llvm::logAllUnhandledErrors(Addr.takeError(), error_stream, "error: ");
return true;
}
}
Expand All @@ -106,7 +106,7 @@ process_code(clang::Interpreter& Interp, const std::string& code, llvm::raw_stri
auto Addr = Interp.getSymbolAddress(clang::GlobalDecl(VD));
if (!Addr)
{
llvm::logAllUnhandledErrors(std::move(Addr.takeError()), error_stream, "error: ");
llvm::logAllUnhandledErrors(Addr.takeError(), error_stream, "error: ");
return true;
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace xcpp
}

interpreter::interpreter(int argc, const char* const* argv)
: m_interpreter(std::move(create_interpreter(Args() /*argv + 1, argv + argc)*/, DiagPrinter.get())))
: m_interpreter(create_interpreter(Args() /*argv + 1, argv + argc)*/, DiagPrinter.get()))
, m_version(get_stdopt(argc, argv))
, // Extract C++ language standard version from command-line option
xmagics()
Expand Down
7 changes: 0 additions & 7 deletions src/xinterpreter_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ namespace xcpp

wasm_interpreter::wasm_interpreter()
: interpreter(0, nullptr)

wasm_interpreter::~wasm_interpreter()
{
}

void wasm_interpreter::configure_impl()
{
interpreter::configure_impl();
}
}

0 comments on commit 5a5aca5

Please sign in to comment.