Skip to content

Commit 63aabc0

Browse files
Merge pull request #22 from anutosh491/fixing_wasm
Attempt to fix wasm build
2 parents 7c7d42d + 5a5aca5 commit 63aabc0

File tree

8 files changed

+88
-122
lines changed

8 files changed

+88
-122
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
9090
mkdir -p bld
9191
cd bld
92-
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DXEUS_BUILD_TESTS=ON -DDEPENDENCY_SEARCH_PREFIX="%CONDA_PREFIX%\Library" -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%"
92+
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DXEUS_BUILD_TESTS=ON -DDEPENDENCY_SEARCH_PREFIX="%CONDA_PREFIX%\Library" -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%"
9393
9494
- name: build
9595
shell: cmd
@@ -99,111 +99,14 @@ jobs:
9999
set CL=/MP
100100
nmake install
101101
102-
- name: test
103-
shell: cmd
104-
run: |
105-
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
106-
cd test
107-
pytest . --reruns 5
108-
109-
emscripten_wasm_docker:
110-
runs-on: ubuntu-20.04
111-
112-
strategy:
113-
fail-fast: false
114-
matrix:
115-
container: ["emscripten/emsdk:2.0.34", "emscripten/emsdk:3.1.3", "emscripten/emsdk:latest"]
116-
117-
118-
container: ${{ matrix.container}}
119-
120-
steps:
121-
- uses: actions/checkout@v2
122-
123-
- name: Verify emscripten
124-
run: emcc -v
125-
126-
- name: "install xtl"
127-
run: |
128-
mkdir -p /opt/xtl/build
129-
git clone https://github.com/xtensor-stack/xtl.git /opt/xtl/src
130-
cd /opt/xtl/src
131-
git checkout 0.7.2
132-
cd /opt/xtl/build
133-
emcmake cmake ../src/ -DCMAKE_INSTALL_PREFIX=/custom_sysroot
134-
emmake make -j2 install
135-
136-
- name: "install nlohmann-json"
137-
run: |
138-
mkdir -p /opt/nlohmannjson/build
139-
git clone https://github.com/nlohmann/json.git /opt/nlohmannjson/src
140-
cd /opt/nlohmannjson/src
141-
git checkout v3.9.0
142-
cd /opt/nlohmannjson/build
143-
emcmake cmake ../src/ -DJSON_BuildTests=OFF -DCMAKE_INSTALL_PREFIX=/custom_sysroot
144-
emmake make -j2 install
145-
146-
- name: "install xeus"
147-
run: |
148-
mkdir -p /opt/xeus/build
149-
git clone https://github.com/jupyter-xeus/xeus.git /opt/xeus/src
150-
cd /opt/xeus/build
151-
emcmake cmake ../src \
152-
-DXEUS_EMSCRIPTEN_WASM_BUILD=ON \
153-
-DCMAKE_INSTALL_PREFIX=/custom_sysroot\
154-
-Dxtl_DIR=/custom_sysroot/share/cmake/xtl \
155-
-Dnlohmann_json_DIR=/custom_sysroot/lib/cmake/nlohmann_json
156-
157-
emmake make -j2
158-
emmake make -j2 install
159-
160-
- name: "install xeus-lite"
161-
run: |
162-
mkdir -p /opt/xeus-lite/build
163-
git clone https://github.com/jupyter-xeus/xeus-lite.git /opt/xeus-lite/src
164-
cd /opt/xeus-lite/build
165-
emcmake cmake ../src \
166-
-DXEUS_EMSCRIPTEN_WASM_BUILD=ON \
167-
-DCMAKE_INSTALL_PREFIX=/custom_sysroot \
168-
-Dxtl_DIR=/custom_sysroot/share/cmake/xtl \
169-
-Dnlohmann_json_DIR=/custom_sysroot/lib/cmake/nlohmann_json \
170-
-Dxeus_DIR=/custom_sysroot/lib/cmake/xeus
171-
emmake make -j2
172-
emmake make -j2 install
173-
174-
- name: cmake configure rendered project
175-
shell: bash -l {0}
176-
run: |
177-
mkdir -p bld
178-
cd bld
179-
emcmake cmake .. \
180-
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
181-
-Dxtl_DIR=/custom_sysroot/share/cmake/xtl \
182-
-Dnlohmann_json_DIR=/custom_sysroot/lib/cmake/nlohmann_json \
183-
-Dxeus_DIR=/custom_sysroot/lib/cmake/xeus \
184-
-Dxeus-lite_DIR=/custom_sysroot/lib/cmake/xeus-lite \
185-
-DCMAKE_INSTALL_PREFIX=/custom_sysroot
186-
187-
- name: build rendered project
188-
shell: bash -l {0}
189-
run: |
190-
cd bld
191-
emmake make -j2
192-
193-
- name: install rendered project
194-
shell: bash -l {0}
195-
run: |
196-
cd bld
197-
make install
198-
199102
emscripten_wasm:
200103

201104
runs-on: ubuntu-latest
202105

203106
strategy:
204107
fail-fast: false
205108
matrix:
206-
emsdk_ver: ["2.0.34", "3.1.3"]
109+
emsdk_ver: ["3.1.45"]
207110

208111
steps:
209112
- uses: actions/checkout@v2
@@ -224,7 +127,7 @@ jobs:
224127
run: |
225128
emsdk activate ${{matrix.emsdk_ver}}
226129
source $CONDA_EMSDK_DIR/emsdk_env.sh
227-
micromamba create -f environment-wasm-host.yml --platform=emscripten-32
130+
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32
228131
229132
mkdir build
230133
pushd build
@@ -241,4 +144,4 @@ jobs:
241144
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
242145
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
243146
..
244-
make -j5
147+
EMCC_CFLAGS='-sERROR_ON_UNDEFINED_SYMBOLS=0' emmake make -j5

CMakeLists.txt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ OPTION(XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON)
5050
OPTION(XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instead of the static library)" ON)
5151
OPTION(XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON)
5252

53-
OPTION(XEUS_CPP_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF)
5453

55-
if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
54+
55+
if(EMSCRIPTEN)
5656
add_compile_definitions(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
5757
message("Build with emscripten")
5858
SET(XEUS_CPP_BUILD_STATIC ON)
@@ -90,7 +90,7 @@ else()
9090
endif ()
9191

9292
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
93-
if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
93+
if(NOT EMSCRIPTEN)
9494
add_compile_options(-Wunused-parameter -Wextra -Wreorder)
9595
endif()
9696

@@ -103,7 +103,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
103103
endif ()
104104
endif ()
105105

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

134+
if(EMSCRIPTEN)
135+
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
136+
endif()
137+
134138
set(XEUS_CPP_MAIN_SRC
135139
src/main.cpp
136140
)
@@ -192,7 +196,7 @@ macro(xeus_cpp_set_kernel_options target_name)
192196
target_link_libraries(${target_name} PRIVATE xeus-cpp-static)
193197
endif()
194198

195-
if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
199+
if(NOT EMSCRIPTEN)
196200
find_package(Threads)
197201
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
198202
endif()
@@ -238,7 +242,7 @@ macro(xeus_cpp_create_target target_name linkage output_name)
238242
elseif (APPLE)
239243
target_link_libraries(${target_name} PRIVATE "-undefined dynamic_lookup")
240244
endif ()
241-
if(NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
245+
if(NOT EMSCRIPTEN)
242246
find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
243247
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
244248
endif()
@@ -291,14 +295,14 @@ if (XEUS_CPP_BUILD_EXECUTABLE)
291295
target_link_libraries(xcpp PRIVATE xeus-zmq)
292296
endif()
293297

294-
if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
298+
if(EMSCRIPTEN)
295299
include(WasmBuildOptions)
296300
find_package(xeus-lite REQUIRED)
297-
add_executable(xcpp_wasm src/main_emscripten_kernel.cpp )
298-
target_link_libraries(xcpp_wasm PRIVATE xeus-cpp-static xeus-lite)
299-
XEUS_CPP_set_kernel_options(xcpp_wasm)
300-
xeus_wasm_compile_options(xcpp_wasm)
301-
xeus_wasm_link_options(xcpp_wasm "web,worker")
301+
add_executable(xcpp src/main_emscripten_kernel.cpp )
302+
target_link_libraries(xcpp PRIVATE xeus-lite)
303+
xeus_cpp_set_kernel_options(xcpp)
304+
xeus_wasm_compile_options(xcpp)
305+
xeus_wasm_link_options(xcpp "web,worker")
302306
endif()
303307

304308
# Installation
@@ -325,7 +329,9 @@ endif ()
325329
if (XEUS_CPP_BUILD_EXECUTABLE)
326330
install(TARGETS xcpp
327331
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
332+
endif()
328333

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

@@ -391,13 +397,13 @@ if (XEUS_CPP_BUILD_SHARED)
391397
DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR})
392398
endif ()
393399

394-
if(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
395-
install(TARGETS xcpp_wasm
400+
if(EMSCRIPTEN)
401+
install(TARGETS xcpp
396402
ARCHIVE DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR})
397403

398404
install(FILES
399-
"$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm.js"
400-
"$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm.wasm"
405+
"$<TARGET_FILE_DIR:xcpp>/xcpp.js"
406+
"$<TARGET_FILE_DIR:xcpp>/xcpp.wasm"
401407
DESTINATION ${CMAKE_INSTALL_BINDIR})
402408
endif ()
403409

environment-wasm-host.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ dependencies:
77
- xeus-lite
88
- xeus >=3.0.5,<4.0
99
- xtl >=0.7,<0.8
10+
- llvm =16.0.6
11+
- cpp-argparse
12+
- pugixml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/************************************************************************************
2+
* Copyright (c) 2023, xeus-cpp contributors *
3+
* Copyright (c) 2023, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht *
4+
* *
5+
* Distributed under the terms of the BSD 3-Clause License. *
6+
* *
7+
* The full license is in the file LICENSE, distributed with this software. *
8+
************************************************************************************/
9+
10+
11+
#ifndef XEUS_CPP_INTERPRETER_WASM_HPP
12+
#define XEUS_CPP_INTERPRETER_WASM_HPP
13+
14+
#include "xinterpreter.hpp"
15+
#include "xeus_cpp_config.hpp"
16+
17+
namespace xcpp
18+
{
19+
class XEUS_CPP_API wasm_interpreter : public interpreter
20+
{
21+
public:
22+
23+
wasm_interpreter();
24+
virtual ~wasm_interpreter() = default;
25+
26+
};
27+
}
28+
29+
#endif

include/xeus-cpp/xmagics.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ namespace xcpp
2626

2727
struct xmagic_line
2828
{
29+
virtual ~xmagic_line() = default;
2930
virtual void operator()(const std::string& line) = 0;
3031
};
3132

3233
struct xmagic_cell
3334
{
35+
virtual ~xmagic_cell() = default;
3436
virtual void operator()(const std::string& line, const std::string& cell) = 0;
3537
};
3638

src/main_emscripten_kernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
#include <xeus/xembind.hpp>
1515

16-
#include "xeus-cpp/xinterpreter.hpp"
16+
#include "xeus-cpp/xinterpreter_wasm.hpp"
1717

1818
EMSCRIPTEN_BINDINGS(my_module)
1919
{
2020
xeus::export_core();
21-
using interpreter_type = xcpp::interpreter;
21+
using interpreter_type = xcpp::wasm_interpreter;
2222
xeus::export_kernel<interpreter_type>("xkernel");
2323
}

src/xinterpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ process_code(clang::Interpreter& Interp, const std::string& code, llvm::raw_stri
9090
auto Addr = Interp.getSymbolAddress(clang::GlobalDecl(VD));
9191
if (!Addr)
9292
{
93-
llvm::logAllUnhandledErrors(std::move(Addr.takeError()), error_stream, "error: ");
93+
llvm::logAllUnhandledErrors(Addr.takeError(), error_stream, "error: ");
9494
return true;
9595
}
9696
}
@@ -106,7 +106,7 @@ process_code(clang::Interpreter& Interp, const std::string& code, llvm::raw_stri
106106
auto Addr = Interp.getSymbolAddress(clang::GlobalDecl(VD));
107107
if (!Addr)
108108
{
109-
llvm::logAllUnhandledErrors(std::move(Addr.takeError()), error_stream, "error: ");
109+
llvm::logAllUnhandledErrors(Addr.takeError(), error_stream, "error: ");
110110
return true;
111111
}
112112
}
@@ -261,7 +261,7 @@ namespace xcpp
261261
}
262262

263263
interpreter::interpreter(int argc, const char* const* argv)
264-
: m_interpreter(std::move(create_interpreter(Args() /*argv + 1, argv + argc)*/, DiagPrinter.get())))
264+
: m_interpreter(create_interpreter(Args() /*argv + 1, argv + argc)*/, DiagPrinter.get()))
265265
, m_version(get_stdopt(argc, argv))
266266
, // Extract C++ language standard version from command-line option
267267
xmagics()

src/xinterpreter_wasm.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/************************************************************************************
2+
* Copyright (c) 2023, xeus-cpp contributors *
3+
* Copyright (c) 2023, Martin Vassilev *
4+
* *
5+
* Distributed under the terms of the BSD 3-Clause License. *
6+
* *
7+
* The full license is in the file LICENSE, distributed with this software. *
8+
************************************************************************************/
9+
10+
#include "xeus/xinterpreter.hpp"
11+
#include "xeus/xsystem.hpp"
12+
13+
#include "xeus-cpp/xinterpreter.hpp"
14+
#include "xeus-cpp/xinterpreter_wasm.hpp"
15+
16+
namespace xcpp
17+
{
18+
19+
wasm_interpreter::wasm_interpreter()
20+
: interpreter(0, nullptr)
21+
{
22+
}
23+
}

0 commit comments

Comments
 (0)