Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WASM build #530

Merged
merged 12 commits into from
May 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restructure repo
martinRenou committed May 10, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5976be16658d1a23ec1679ee2de236447fe564d7
52 changes: 31 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ jobs:

test-wasm:

runs-on: ubuntu
runs-on: ubuntu-latest

strategy:
fail-fast: false
@@ -148,14 +148,10 @@ jobs:

- name: Install mamba
uses: mamba-org/provision-with-micromamba@main

- name: Create micromamba wasm env
run: |
micromamba create -n xeus-python-wasm \
--platform=emscripten-32 --yes \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
pip python ipython pybind11 jedi xtl nlohmann_json pybind11_json numpy xeus xeus-python-shell>=0.3.0
with:
environment-file: environment-dev-wasm.yml
environment-name: xeus-python-wasm
micromamba-version: "0.22.0"

- name: Setup emsdk (TODO Install from conda-forge when available)
run: |
@@ -176,21 +172,35 @@ jobs:
pushd emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source emsdk_env.sh
export FILE_PACKAGER=$(cwd)/upstream/emscripten/tools/file_packager.py
export FILE_PACKAGER=$(pwd)/upstream/emscripten/tools/file_packager.py
popd

export CMAKE_PREFIX_PATH=$CONDA_PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$CONDA_PREFIX
micromamba create -n xeus-python-build-wasm \
--platform=emscripten-32 \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python ipython pybind11 jedi xtl nlohmann_json pybind11_json numpy xeus "xeus-python-shell>=0.3"

mkdir build
pushd build

export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-build-wasm
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX

emcmake cmake \
-DCMAKE_BUILD_TYPE=Release\
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_PROJECT_INCLUDE=overwriteProp.cmake \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
..
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_PROJECT_INCLUDE=cmake/overwriteProp.cmake \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
..

make -j ${{ steps.cpu-cores.outputs.count }}
make -j5

emboa pack python core $CONDA_PREFIX --version=3.10
emboa pack python core $MAMBA_ROOT_PREFIX/envs/xeus-python-build-wasm --version=3.10

popd

# TODO Add test with node?
# Patch output
python wasm_patches/patch_it.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -51,3 +51,6 @@ build/

# Jupyter artefacts
.ipynb_checkpoints/

# JS artifacts
node_modules/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ OPTION(XPYT_BUILD_TESTS "xeus-python test suite" OFF)
OPTION(XPYT_DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)

if(XPYT_EMSCRIPTEN_WASM_BUILD)
configure_file(post.js ${CMAKE_CURRENT_BINARY_DIR}/post.js COPYONLY)
configure_file(wasm_patches/post.js ${CMAKE_CURRENT_BINARY_DIR}/post.js COPYONLY)

add_compile_definitions(XPYT_EMSCRIPTEN_WASM_BUILD)

39 changes: 0 additions & 39 deletions build_all.sh

This file was deleted.

File renamed without changes.
9 changes: 9 additions & 0 deletions environment-dev-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: xeus-python-wasm
channels:
- conda-forge
dependencies:
- cmake
- pip
- python=3.10
- yarn
- click
6 changes: 5 additions & 1 deletion include/xeus-python/xinterpreter.hpp
Original file line number Diff line number Diff line change
@@ -73,7 +73,6 @@ namespace xpyt
nl::json internal_request_impl(const nl::json& content) override;

void redirect_output();
void instanciate_ipython_shell();

py::object m_ipython_shell_app;
py::object m_ipython_shell;
@@ -95,7 +94,12 @@ namespace xpyt
bool m_release_gil_at_startup = true;
gil_scoped_release_ptr m_release_gil = nullptr;

bool m_redirect_output_enabled;
bool m_redirect_display_enabled;

private:

virtual void instanciate_ipython_shell();
};
}

4 changes: 1 addition & 3 deletions include/xeus-python/xinterpreter_wasm.hpp
Original file line number Diff line number Diff line change
@@ -28,14 +28,12 @@ namespace xpyt
{
public:

using gil_scoped_release_ptr = std::unique_ptr<py::gil_scoped_release>;

wasm_interpreter();
virtual ~wasm_interpreter();

protected:

void instanciate_ipython_shell();
void instanciate_ipython_shell() override;

py::scoped_interpreter m_interpreter;
};
10 changes: 0 additions & 10 deletions patch_it.py

This file was deleted.

11 changes: 6 additions & 5 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
@@ -44,13 +44,9 @@ namespace xpyt
{

interpreter::interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/)
: m_redirect_display_enabled{redirect_display_enabled}
: m_redirect_output_enabled{redirect_output_enabled}, m_redirect_display_enabled{redirect_display_enabled}
{
xeus::register_interpreter(this);
if (redirect_output_enabled)
{
redirect_output();
}
}

interpreter::~interpreter()
@@ -106,6 +102,11 @@ namespace xpyt
// Initializing the compiler
m_ipython_shell.attr("compile").attr("filename_mapper") = traceback_module.attr("register_filename_mapping");
m_ipython_shell.attr("compile").attr("get_filename") = traceback_module.attr("get_filename");

if (m_redirect_output_enabled)
{
redirect_output();
}
}

nl::json interpreter::execute_request_impl(int /*execution_count*/,
9 changes: 9 additions & 0 deletions wasm_patches/patch_it.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with open('./build/xpython_wasm.js', 'r') as f:
content = f.read()


query = 'Module["preloadPlugins"].push(audioPlugin);'
content = content.replace(query, '')

with open('./build/xpython_wasm.js', 'w') as f:
f.write(content)
File renamed without changes.