Skip to content

Commit

Permalink
Merge pull request #3 from martinRenou/using-mambajs
Browse files Browse the repository at this point in the history
Make use of mambajs
  • Loading branch information
AnastasiaSliusar authored Dec 13, 2024
2 parents b075da0 + 77546cd commit 2f1d015
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 15 deletions.
35 changes: 35 additions & 0 deletions packages/xeus-extension/lab.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');

const wasmPath = [
__dirname,
'..',
'..',
'node_modules',
'@emscripten-forge',
'mambajs',
'lib',
'*.wasm'
];
const staticPath = [
__dirname,
'..',
'..',
'jupyterlite_xeus',
'labextension',
'static',
'[name].wasm'
];

module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(...wasmPath),
to: path.join(...staticPath)
}
]
})
]
};
2 changes: 2 additions & 0 deletions packages/xeus-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
"@types/react-addons-linked-state-mixin": "^0.14.22",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.7.1",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.1",
Expand All @@ -65,6 +66,7 @@
"jupyterlab": {
"extension": true,
"outputDir": "../../jupyterlite_xeus/labextension",
"webpackConfig": "lab.webpack.config.js",
"sharedPackages": {
"@jupyterlite/kernel": {
"bundled": false,
Expand Down
45 changes: 33 additions & 12 deletions packages/xeus/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { URLExt } from '@jupyterlab/coreutils';

import { IXeusWorkerKernel } from './interfaces';

import { bootstrapFromEmpackPackedEnvironment, IPackagesInfo} from "@emscripten-forge/mambajs"
globalThis.Module = {};

// when a toplevel cell uses an await, the cell is implicitly
Expand Down Expand Up @@ -80,6 +80,7 @@ export class XeusRemoteKernel {
}

async processMessage(event: any): Promise<void> {
console.log('???processMessage??');
const msg_type = event.msg.header.msg_type;

await globalThis.ready;
Expand All @@ -95,8 +96,10 @@ export class XeusRemoteKernel {
}

if (msg_type === 'input_reply') {
console.log('msg_type',msg_type)
resolveInputReply(event.msg);
} else {
console.log('notify_listener');
rawXServer.notify_listener(event.msg);
}
}
Expand All @@ -118,28 +121,45 @@ export class XeusRemoteKernel {
});
try {
await waitRunDependency();

if (globalThis.Module.FS !== undefined) {
// each kernel can have a `async_init` function
// which can do kernel specific **async** initialization
// This function is usually implemented in the pre/post.js
// in the emscripten build of that kernel
if (globalThis.Module['async_init'] !== undefined) {
const kernel_root_url = empackEnvMetaLink

const kernel_root_url = empackEnvMetaLink
? empackEnvMetaLink
: URLExt.join(baseUrl, `xeus/kernels/${kernelSpec.dir}`);
const pkg_root_url = URLExt.join(baseUrl, 'xeus/kernel_packages');
const verbose = true;
await globalThis.Module['async_init'](
kernel_root_url,
pkg_root_url,
verbose
);
}
const verbose = true;

//if the kernel is not xeus-python than we have to avoid using pyjs

const packagesJsonUrl = `${kernel_root_url}/empack_env_meta.json`;
const pkgRootUrl = URLExt.join(baseUrl, 'xeus/kernel_packages');

let packageData: IPackagesInfo = {};
try{
packageData = await bootstrapFromEmpackPackedEnvironment(packagesJsonUrl, verbose, false, globalThis.Module, pkgRootUrl);
} catch(error: any) {

throw new Error(error.message);
}
if (kernelSpec.name === 'xpython') {
if (Object.keys(packageData).length) {
let {pythonVersion, prefix} = packageData;
if (pythonVersion) {
globalThis.Module.init_phase_2(prefix, pythonVersion, verbose);
}
}
}
}

await waitRunDependency();

rawXKernel = new globalThis.Module.xkernel();
console.log('rawXKernel',rawXKernel);
rawXServer = rawXKernel.get_server();
console.log('rawXServer',rawXServer);
if (!rawXServer) {
console.error('Failed to start kernel!');
}
Expand All @@ -163,6 +183,7 @@ export class XeusRemoteKernel {
* @param callback the callback to register
*/
registerCallback(callback: (msg: any) => void): void {
console.log('registerCallback');
this._sendWorkerMessage = callback;
}

Expand Down
84 changes: 81 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ __metadata:
"@types/json-schema": ^7.0.11
"@types/react": ^18.0.26
"@types/react-addons-linked-state-mixin": ^0.14.22
copy-webpack-plugin: ^12.0.2
css-loader: ^6.7.1
npm-run-all: ^4.1.5
rimraf: ^5.0.1
Expand Down Expand Up @@ -1342,6 +1343,13 @@ __metadata:
languageName: node
linkType: hard

"@sindresorhus/merge-streams@npm:^2.1.0":
version: 2.3.0
resolution: "@sindresorhus/merge-streams@npm:2.3.0"
checksum: e989d53dee68d7e49b4ac02ae49178d561c461144cea83f66fa91ff012d981ad0ad2340cbd13f2fdb57989197f5c987ca22a74eb56478626f04e79df84291159
languageName: node
linkType: hard

"@tufjs/canonical-json@npm:2.0.0":
version: 2.0.0
resolution: "@tufjs/canonical-json@npm:2.0.0"
Expand Down Expand Up @@ -2790,6 +2798,22 @@ __metadata:
languageName: node
linkType: hard

"copy-webpack-plugin@npm:^12.0.2":
version: 12.0.2
resolution: "copy-webpack-plugin@npm:12.0.2"
dependencies:
fast-glob: ^3.3.2
glob-parent: ^6.0.1
globby: ^14.0.0
normalize-path: ^3.0.0
schema-utils: ^4.2.0
serialize-javascript: ^6.0.2
peerDependencies:
webpack: ^5.1.0
checksum: 98127735336c6db5924688486d3a1854a41835963d0c0b81695b2e3d58c6675164be7d23dee7090b84a56d3c9923175d3d0863ac1942bcc3317d2efc1962b927
languageName: node
linkType: hard

"core-util-is@npm:~1.0.0":
version: 1.0.3
resolution: "core-util-is@npm:1.0.3"
Expand Down Expand Up @@ -3604,7 +3628,7 @@ __metadata:
languageName: node
linkType: hard

"fast-glob@npm:^3.2.9":
"fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.2":
version: 3.3.2
resolution: "fast-glob@npm:3.3.2"
dependencies:
Expand Down Expand Up @@ -4018,7 +4042,7 @@ __metadata:
languageName: node
linkType: hard

"glob-parent@npm:6.0.2, glob-parent@npm:^6.0.2":
"glob-parent@npm:6.0.2, glob-parent@npm:^6.0.1, glob-parent@npm:^6.0.2":
version: 6.0.2
resolution: "glob-parent@npm:6.0.2"
dependencies:
Expand Down Expand Up @@ -4133,6 +4157,20 @@ __metadata:
languageName: node
linkType: hard

"globby@npm:^14.0.0":
version: 14.0.2
resolution: "globby@npm:14.0.2"
dependencies:
"@sindresorhus/merge-streams": ^2.1.0
fast-glob: ^3.3.2
ignore: ^5.2.4
path-type: ^5.0.0
slash: ^5.1.0
unicorn-magic: ^0.1.0
checksum: 2cee79efefca4383a825fc2fcbdb37e5706728f2d39d4b63851927c128fff62e6334ef7d4d467949d411409ad62767dc2d214e0f837a0f6d4b7290b6711d485c
languageName: node
linkType: hard

"gopd@npm:^1.0.1":
version: 1.0.1
resolution: "gopd@npm:1.0.1"
Expand Down Expand Up @@ -5957,6 +5995,13 @@ __metadata:
languageName: node
linkType: hard

"normalize-path@npm:^3.0.0":
version: 3.0.0
resolution: "normalize-path@npm:3.0.0"
checksum: 88eeb4da891e10b1318c4b2476b6e2ecbeb5ff97d946815ffea7794c31a89017c70d7f34b3c2ebf23ef4e9fc9fb99f7dffe36da22011b5b5c6ffa34f4873ec20
languageName: node
linkType: hard

"npm-bundled@npm:^3.0.0":
version: 3.0.1
resolution: "npm-bundled@npm:3.0.1"
Expand Down Expand Up @@ -6567,6 +6612,13 @@ __metadata:
languageName: node
linkType: hard

"path-type@npm:^5.0.0":
version: 5.0.0
resolution: "path-type@npm:5.0.0"
checksum: 15ec24050e8932c2c98d085b72cfa0d6b4eeb4cbde151a0a05726d8afae85784fc5544f733d8dfc68536587d5143d29c0bd793623fad03d7e61cc00067291cd5
languageName: node
linkType: hard

"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1":
version: 1.0.1
resolution: "picocolors@npm:1.0.1"
Expand Down Expand Up @@ -7242,6 +7294,18 @@ __metadata:
languageName: node
linkType: hard

"schema-utils@npm:^4.2.0":
version: 4.3.0
resolution: "schema-utils@npm:4.3.0"
dependencies:
"@types/json-schema": ^7.0.9
ajv: ^8.9.0
ajv-formats: ^2.1.1
ajv-keywords: ^5.1.0
checksum: 3dbd9056727c871818eaf3cabeeb5c9e173ae2b17bbf2a9c7a2e49c220fa1a580e44df651c876aea3b4926cecf080730a39e28202cb63f2b68d99872b49cd37a
languageName: node
linkType: hard

"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.4.1, semver@npm:^5.5.0, semver@npm:^5.6.0":
version: 5.7.2
resolution: "semver@npm:5.7.2"
Expand Down Expand Up @@ -7269,7 +7333,7 @@ __metadata:
languageName: node
linkType: hard

"serialize-javascript@npm:^6.0.1":
"serialize-javascript@npm:^6.0.1, serialize-javascript@npm:^6.0.2":
version: 6.0.2
resolution: "serialize-javascript@npm:6.0.2"
dependencies:
Expand Down Expand Up @@ -7406,6 +7470,13 @@ __metadata:
languageName: node
linkType: hard

"slash@npm:^5.1.0":
version: 5.1.0
resolution: "slash@npm:5.1.0"
checksum: 70434b34c50eb21b741d37d455110258c42d2cf18c01e6518aeb7299f3c6e626330c889c0c552b5ca2ef54a8f5a74213ab48895f0640717cacefeef6830a1ba4
languageName: node
linkType: hard

"smart-buffer@npm:^4.2.0":
version: 4.2.0
resolution: "smart-buffer@npm:4.2.0"
Expand Down Expand Up @@ -8180,6 +8251,13 @@ __metadata:
languageName: node
linkType: hard

"unicorn-magic@npm:^0.1.0":
version: 0.1.0
resolution: "unicorn-magic@npm:0.1.0"
checksum: 48c5882ca3378f380318c0b4eb1d73b7e3c5b728859b060276e0a490051d4180966beeb48962d850fd0c6816543bcdfc28629dcd030bb62a286a2ae2acb5acb6
languageName: node
linkType: hard

"unique-filename@npm:^3.0.0":
version: 3.0.0
resolution: "unique-filename@npm:3.0.0"
Expand Down

0 comments on commit 2f1d015

Please sign in to comment.