Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 34 additions & 3 deletions packages/xeus-core/src/worker.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import type {
} from '@emscripten-forge/mambajs-core';
import { waitRunDependencies, parse } from '@emscripten-forge/mambajs-core';

declare namespace WebAssembly {
type ValueType = 'i32' | 'i64' | 'f32' | 'f64' | 'externref' | 'funcref';

interface ITagDescriptor {
parameters?: ValueType[];
}

class Tag {
constructor(descriptor: ITagDescriptor);
}

class Exception {
readonly tag: Tag;
getArg(tag: Tag, arg: number): any;
is(tag: Tag): boolean;
}
}

declare function createXeusModule(options: any): any;

const STREAM = { log: 'stdout', warn: 'stdout', error: 'stderr' };
Expand Down Expand Up @@ -131,6 +149,8 @@ export abstract class XeusRemoteKernelBase {
}
}

abstract get emscriptenMajorVersion(): number;

protected get Module() {
return globalThis.Module;
}
Expand Down Expand Up @@ -165,11 +185,18 @@ export abstract class XeusRemoteKernelBase {
await this.initializeInterpreter(options);
this.initializeStdin(baseUrl, browsingContextId);

try {
// If Emscripten 4.x +, we cannot fallback to instanciate the Module a second time
// So from that version all kernels must take argv
if (this.emscriptenMajorVersion < 4) {
try {
this.xkernel = new this.Module.xkernel(kernelSpec.argv);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the try catch in any case.
We always export both constructors. Therefore lets just use the one with args.

https://github.com/jupyter-xeus/xeus-lite/blob/main/include/xeus-lite/xembind.hpp#L86-L87

If the kernel does not support this, the args will just be ignored:

https://github.com/jupyter-xeus/xeus-lite/blob/main/include/xeus-lite/xembind.hpp#L49

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok! @anutosh491 didn't we test old kernels and they were not instanciating if passing argv while they don't accept it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinRenou I assume that was at a time where not all kernels have been build after the change has been made.
I am not 100% sure that all kernels have been rebuild at that time, but 90% sure ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall that's actually for old kernel builds support we kept that. Maybe we should keep the try/catch just in case?

} catch (e) {
this.xkernel = new this.Module.xkernel();
}
} else {
this.xkernel = new this.Module.xkernel(kernelSpec.argv);
} catch (e) {
this.xkernel = new this.Module.xkernel();
}

this.xserver = this.xkernel.get_server();
if (!this.xserver) {
this.logger.error('Failed to start kernel!');
Expand All @@ -180,6 +207,10 @@ export abstract class XeusRemoteKernelBase {
const msg = this.Module.get_exception_message(e);
this.logger.error(msg);
throw new Error(msg);
} else if (e instanceof WebAssembly.Exception) {
const msg = this.Module.getExceptionMessage(e);
this.logger.error(msg);
throw new Error(msg);
} else {
this.logger.error(e);
throw e;
Expand Down
50 changes: 37 additions & 13 deletions packages/xeus/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,33 @@ export abstract class EmpackedXeusRemoteKernel extends XeusRemoteKernelBase {
});
}

// Load shared libs
await loadSharedLibs({
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});
// Load shared libs only for old emscripten versions
if (this.emscriptenMajorVersion < 4) {
await loadSharedLibs({
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});
}
}

get emscriptenMajorVersion(): number {
if (this._emscriptenVersion) {
return this._emscriptenVersion;
}

for (const pkg of Object.values(this._lock.packages)) {
if (pkg.name === 'emscripten-abi') {
this._emscriptenVersion = Number.parseInt(pkg.version.split('.')[0]);
}
}

if (!this._emscriptenVersion) {
throw new Error('Failed to detect emscripten version');
}

return this._emscriptenVersion;
}

/**
Expand Down Expand Up @@ -262,16 +282,20 @@ export abstract class EmpackedXeusRemoteKernel extends XeusRemoteKernelBase {
);
}

await loadSharedLibs({
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});
// Load shared libs only for old emscripten versions
if (this.emscriptenMajorVersion < 4) {
await loadSharedLibs({
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});
}

this._lock = newLock;
}

private _emscriptenVersion: number | undefined = undefined;
private _pythonVersion: number[] | undefined;
private _prefix = '';

Expand Down
116 changes: 58 additions & 58 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ __metadata:
linkType: hard

"@codemirror/autocomplete@npm:^6.0.0, @codemirror/autocomplete@npm:^6.18.6, @codemirror/autocomplete@npm:^6.3.2, @codemirror/autocomplete@npm:^6.7.1":
version: 6.19.1
resolution: "@codemirror/autocomplete@npm:6.19.1"
version: 6.20.0
resolution: "@codemirror/autocomplete@npm:6.20.0"
dependencies:
"@codemirror/language": ^6.0.0
"@codemirror/state": ^6.0.0
"@codemirror/view": ^6.17.0
"@lezer/common": ^1.0.0
checksum: 1012cff08a3db2bd840d2d9dd002f254140a4b5962d4a87cf9eb5a122ecb02e77686f846ca318a58c97cab6e81617d6d34ce8bada0a416291943248abde3dea4
checksum: 0defd46302ab2763d10f3a51ef8f2b607dd7268843aaeec76a272e84723fe17f8a5ee5a7ad06e649066b69d9dad2a81d6a6cfdf7593290bd52b711b96c46518b
languageName: node
linkType: hard

Expand Down Expand Up @@ -675,16 +675,16 @@ __metadata:
linkType: hard

"@jupyter/ydoc@npm:^3.1.0":
version: 3.2.1
resolution: "@jupyter/ydoc@npm:3.2.1"
version: 3.3.1
resolution: "@jupyter/ydoc@npm:3.3.1"
dependencies:
"@jupyterlab/nbformat": ^3.0.0 || ^4.0.0-alpha.21 || ^4.0.0
"@lumino/coreutils": ^1.11.0 || ^2.0.0
"@lumino/disposable": ^1.10.0 || ^2.0.0
"@lumino/signaling": ^1.10.0 || ^2.0.0
y-protocols: ^1.0.5
yjs: ^13.5.40
checksum: e576f146f2aa83b9e9f4859405efd87ee16335e6e151c0cc2440c825afe9a92f629f9e7df532e7fded50c1325efe0a50ed25fae7e8cd72784a39e98753729cac
checksum: 05f4235104a682663b71929a0dd481a6bb16e745b9ea7357282caf562d617a8b4117e6d076b9e12f7c7fbfcbd82a8cdbba9b2157055cc0539c3fd015a9e1bbda
languageName: node
linkType: hard

Expand Down Expand Up @@ -2227,8 +2227,8 @@ __metadata:
linkType: hard

"@nx/devkit@npm:>=17.1.2 < 21":
version: 20.8.2
resolution: "@nx/devkit@npm:20.8.2"
version: 20.8.3
resolution: "@nx/devkit@npm:20.8.3"
dependencies:
ejs: ^3.1.7
enquirer: ~2.3.6
Expand All @@ -2240,76 +2240,76 @@ __metadata:
yargs-parser: 21.1.1
peerDependencies:
nx: ">= 19 <= 21"
checksum: 2005419435593fcf763b89e0e025eb154a48a11331247e2bbc59ee23456f1a1a8dab24f420f69a3c87e6ff5a8a7bde8ff8f297cab1767f1bd9529a322cd9222b
checksum: 73f376e6a18dfb1fe3079727a33e0a30ee87cc3770e5ee5c85e9f6c5fb3c6218108a982a5ddb796fcca63ffd7b3ca72a50ffe354858b9435cec7e47a3d22445e
languageName: node
linkType: hard

"@nx/nx-darwin-arm64@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-darwin-arm64@npm:20.8.2"
"@nx/nx-darwin-arm64@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-darwin-arm64@npm:20.8.3"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@nx/nx-darwin-x64@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-darwin-x64@npm:20.8.2"
"@nx/nx-darwin-x64@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-darwin-x64@npm:20.8.3"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@nx/nx-freebsd-x64@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-freebsd-x64@npm:20.8.2"
"@nx/nx-freebsd-x64@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-freebsd-x64@npm:20.8.3"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard

"@nx/nx-linux-arm-gnueabihf@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-linux-arm-gnueabihf@npm:20.8.2"
"@nx/nx-linux-arm-gnueabihf@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-linux-arm-gnueabihf@npm:20.8.3"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard

"@nx/nx-linux-arm64-gnu@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-linux-arm64-gnu@npm:20.8.2"
"@nx/nx-linux-arm64-gnu@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-linux-arm64-gnu@npm:20.8.3"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"@nx/nx-linux-arm64-musl@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-linux-arm64-musl@npm:20.8.2"
"@nx/nx-linux-arm64-musl@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-linux-arm64-musl@npm:20.8.3"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"@nx/nx-linux-x64-gnu@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-linux-x64-gnu@npm:20.8.2"
"@nx/nx-linux-x64-gnu@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-linux-x64-gnu@npm:20.8.3"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"@nx/nx-linux-x64-musl@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-linux-x64-musl@npm:20.8.2"
"@nx/nx-linux-x64-musl@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-linux-x64-musl@npm:20.8.3"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"@nx/nx-win32-arm64-msvc@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-win32-arm64-msvc@npm:20.8.2"
"@nx/nx-win32-arm64-msvc@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-win32-arm64-msvc@npm:20.8.3"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@nx/nx-win32-x64-msvc@npm:20.8.2":
version: 20.8.2
resolution: "@nx/nx-win32-x64-msvc@npm:20.8.2"
"@nx/nx-win32-x64-msvc@npm:20.8.3":
version: 20.8.3
resolution: "@nx/nx-win32-x64-msvc@npm:20.8.3"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
Expand Down Expand Up @@ -3862,11 +3862,11 @@ __metadata:
linkType: hard

"baseline-browser-mapping@npm:^2.8.25":
version: 2.8.29
resolution: "baseline-browser-mapping@npm:2.8.29"
version: 2.8.30
resolution: "baseline-browser-mapping@npm:2.8.30"
bin:
baseline-browser-mapping: dist/cli.js
checksum: 36aac32abcb13f5ec24cf00b3cde7469bda560fa8bf82d0e4f23b2ddf5a78ba182cf15fa51e4c76e597bfbaf1f71b78330030674f89b4fd20444730faff2c5c2
checksum: d10303cea329afc702e6d7cba4ecae234a6c056352c20dbbb23658fa93c233474193d98e10e9d0cc98c171ee465660e93d9bf3374b2e17fdbb3a0be801792a32
languageName: node
linkType: hard

Expand Down Expand Up @@ -5446,9 +5446,9 @@ __metadata:
linkType: hard

"electron-to-chromium@npm:^1.5.249":
version: 1.5.258
resolution: "electron-to-chromium@npm:1.5.258"
checksum: 8972b375791f5642b15cafd3d89e97b208324e43460e39827088d4db6a78f3c4694274748663f2a234ef73eee7105c401eb3702647f0d9b46b3d4ab22625a443
version: 1.5.259
resolution: "electron-to-chromium@npm:1.5.259"
checksum: 8711e642257f83d3f17b15917389e95a4da047f680976c48fb00eb6a6868e55f2d300eb6359be745a93ef0fe7720e93a72302f199284039bc453bcb1684772e6
languageName: node
linkType: hard

Expand Down Expand Up @@ -8941,20 +8941,20 @@ __metadata:
linkType: hard

"nx@npm:>=17.1.2 < 21":
version: 20.8.2
resolution: "nx@npm:20.8.2"
version: 20.8.3
resolution: "nx@npm:20.8.3"
dependencies:
"@napi-rs/wasm-runtime": 0.2.4
"@nx/nx-darwin-arm64": 20.8.2
"@nx/nx-darwin-x64": 20.8.2
"@nx/nx-freebsd-x64": 20.8.2
"@nx/nx-linux-arm-gnueabihf": 20.8.2
"@nx/nx-linux-arm64-gnu": 20.8.2
"@nx/nx-linux-arm64-musl": 20.8.2
"@nx/nx-linux-x64-gnu": 20.8.2
"@nx/nx-linux-x64-musl": 20.8.2
"@nx/nx-win32-arm64-msvc": 20.8.2
"@nx/nx-win32-x64-msvc": 20.8.2
"@nx/nx-darwin-arm64": 20.8.3
"@nx/nx-darwin-x64": 20.8.3
"@nx/nx-freebsd-x64": 20.8.3
"@nx/nx-linux-arm-gnueabihf": 20.8.3
"@nx/nx-linux-arm64-gnu": 20.8.3
"@nx/nx-linux-arm64-musl": 20.8.3
"@nx/nx-linux-x64-gnu": 20.8.3
"@nx/nx-linux-x64-musl": 20.8.3
"@nx/nx-win32-arm64-msvc": 20.8.3
"@nx/nx-win32-x64-msvc": 20.8.3
"@yarnpkg/lockfile": ^1.1.0
"@yarnpkg/parsers": 3.0.2
"@zkochan/js-yaml": 0.0.7
Expand Down Expand Up @@ -9020,7 +9020,7 @@ __metadata:
bin:
nx: bin/nx.js
nx-cloud: bin/nx-cloud.js
checksum: fbc063f8dc7cd55b56164d636c5151d8da8c5fd6e22d15e7b141c5b75dda5f84d0bc7c381f1eb52791bd1916651110b851448c5a64a82413d9dd3784c8c54aca
checksum: 5efbd0268498bf09e48b45efa7dd1d4387e2aa8107afc175c8e0faf690fa415d59a2f540f38e3404f3e698a2c8c6217f299160b7149df9e4295de58c5d5cb31a
languageName: node
linkType: hard

Expand Down
Loading