Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Working setup
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed May 16, 2022
1 parent fa52cf5 commit bacb984
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 0 additions & 2 deletions jupyterlite_xeus_python/env_build_addon.py
Expand Up @@ -54,8 +54,6 @@ def output_extensions(self):

def pre_build(self, manager):
"""yield a doit task to create the emscripten-32 env and grab anything we need from it"""
print("-- XeusPythonEnvBuildAddon.pre-build")

# Bail early if there is nothing to do
if not self.packages:
return []
Expand Down
26 changes: 15 additions & 11 deletions src/worker.ts
Expand Up @@ -2,22 +2,14 @@
// Copyright (c) JupyterLite Contributors
// Distributed under the terms of the Modified BSD License.

declare namespace globalThis {
let Module: any;
}
globalThis.Module = {};

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import createXeusModule from './xpython_wasm.js';

// We alias self to ctx and give it our newly created type
const ctx: Worker = self as any;
let raw_xkernel: any;
let raw_xserver: any;

async function waitRunDependency() {
const promise = new Promise((r: any) => {
// @ts-ignore
globalThis.Module.monitorRunDependencies = (n: number) => {
if (n === 0) {
console.log('all `RunDependencies` loaded');
Expand All @@ -28,7 +20,9 @@ async function waitRunDependency() {
// If there are no pending dependencies left, monitorRunDependencies will
// never be called. Since we can't check the number of dependencies,
// manually trigger a call.
// @ts-ignore
globalThis.Module.addRunDependency('dummy');
// @ts-ignore
globalThis.Module.removeRunDependency('dummy');
return promise;
}
Expand All @@ -50,19 +44,29 @@ let resolveInputReply: any;

async function loadCppModule(moduleFactory: any): Promise<any> {
const options: any = {};
// @ts-ignore
globalThis.Module = await moduleFactory(options);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await require('./python_data');
importScripts(require('./python_data'));

await waitRunDependency();
// @ts-ignore
raw_xkernel = new globalThis.Module.xkernel();
raw_xserver = raw_xkernel.get_server();
raw_xkernel!.start();
}

const loadCppModulePromise = loadCppModule(createXeusModule);
async function load() {
// @ts-ignore
let xpython = importScripts(require('./xpython_wasm.js'));

// @ts-ignore
return loadCppModule(createXeusModule);
}

const loadCppModulePromise = load();

ctx.onmessage = async (event: MessageEvent): Promise<void> => {
await loadCppModulePromise;
Expand Down
26 changes: 18 additions & 8 deletions webpack.config.js
@@ -1,21 +1,31 @@
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
module: {
rules: [
{
test: /python_data\.js/,
type: 'asset',
generator : {
filename : 'python_data.js',
}
},
{
test: /xpython_wasm\.js/,
type: 'asset',
generator : {
filename : 'xpython_wasm.js',
}
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: 'src/xpython_wasm.js',
to: '.'
},
{
from: 'src/xpython_wasm.wasm',
to: '.'
},
{
from: 'src/python_data.js',
to: '.'
},
{
from: 'src/python_data.data',
to: '.'
Expand Down

0 comments on commit bacb984

Please sign in to comment.