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

Support wasm target #8

Open
oovm opened this issue Sep 25, 2023 · 2 comments
Open

Support wasm target #8

oovm opened this issue Sep 25, 2023 · 2 comments
Assignees

Comments

@oovm oovm self-assigned this Sep 25, 2023
@oovm
Copy link
Owner Author

oovm commented Sep 27, 2023

Need build following class from wasm

import {JupyterLiteServer, JupyterLiteServerPlugin} from '@jupyterlite/server';
import {IKernel, BaseKernel, IKernelSpecs} from '@jupyterlite/kernel';
import {KernelMessage} from '@jupyterlab/services';

export class EchoKernel extends BaseKernel {
    async kernelInfoRequest(): Promise<KernelMessage.IInfoReplyMsg['content']> {
        const content: KernelMessage.IInfoReply = {
            implementation: 'Text',
            implementation_version: '0.1.0',
            language_info: {
                codemirror_mode: {
                    name: 'text/plain'
                },
                file_extension: '.txt',
                mimetype: 'text/plain',
                name: 'echo',
                nbconvert_exporter: 'text',
                pygments_lexer: 'text',
                version: 'es2017'
            },
            protocol_version: '5.3',
            status: 'ok',
            banner: 'My kernel running in the browser',
            help_links: [
                {
                    text: 'My Kernel',
                    url: 'https://github.com/jupyterlite/my-kernel'
                }
            ]
        };
        return content;
    }

    /**
     * Handle an `execute_request` message
     *
     * @param msg The parent message.
     */
    async executeRequest(
        content: KernelMessage.IExecuteRequestMsg['content']
    ): Promise<KernelMessage.IExecuteReplyMsg['content']> {
        const {code} = content;

        this.publishExecuteResult({
            execution_count: this.executionCount,
            data: {
                'text/plain': code
            },
            metadata: {}
        });

        return {
            status: 'ok',
            execution_count: this.executionCount,
            user_expressions: {}
        };
    }

    /**
     * Handle an complete_request message
     *
     * @param msg The parent message.
     */
    async completeRequest(
        content: KernelMessage.ICompleteRequestMsg['content']
    ): Promise<KernelMessage.ICompleteReplyMsg['content']> {
        throw new Error('Not implemented');
    }

    /**
     * Handle an `inspect_request` message.
     *
     * @param content - The content of the request.
     *
     * @returns A promise that resolves with the response message.
     */
    async inspectRequest(
        content: KernelMessage.IInspectRequestMsg['content']
    ): Promise<KernelMessage.IInspectReplyMsg['content']> {
        throw new Error('Not implemented');
    }

    /**
     * Handle an `is_complete_request` message.
     *
     * @param content - The content of the request.
     *
     * @returns A promise that resolves with the response message.
     */
    async isCompleteRequest(
        content: KernelMessage.IIsCompleteRequestMsg['content']
    ): Promise<KernelMessage.IIsCompleteReplyMsg['content']> {
        throw new Error('Not implemented');
    }

    /**
     * Handle a `comm_info_request` message.
     *
     * @param content - The content of the request.
     *
     * @returns A promise that resolves with the response message.
     */
    async commInfoRequest(
        content: KernelMessage.ICommInfoRequestMsg['content']
    ): Promise<KernelMessage.ICommInfoReplyMsg['content']> {
        throw new Error('Not implemented');
    }

    /**
     * Send an `input_reply` message.
     *
     * @param content - The content of the reply.
     */
    inputReply(content: KernelMessage.IInputReplyMsg['content']): void {
        throw new Error('Not implemented');
    }

    /**
     * Send an `comm_open` message.
     *
     * @param msg - The comm_open message.
     */
    async commOpen(msg: KernelMessage.ICommOpenMsg): Promise<void> {
        throw new Error('Not implemented');
    }

    /**
     * Send an `comm_msg` message.
     *
     * @param msg - The comm_msg message.
     */
    async commMsg(msg: KernelMessage.ICommMsgMsg): Promise<void> {
        throw new Error('Not implemented');
    }

    /**
     * Send an `comm_close` message.
     *
     * @param close - The comm_close message.
     */
    async commClose(msg: KernelMessage.ICommCloseMsg): Promise<void> {
        throw new Error('Not implemented');
    }
}

export const kernel: JupyterLiteServerPlugin<void> = {
    id: '@jupyterlite/my-kernel:kernel',
    autoStart: true,
    requires: [IKernelSpecs],
    activate: (app: JupyterLiteServer, kernelspecs: IKernelSpecs) => {
        kernelspecs.register({
            spec: {
                name: 'echo',
                display_name: 'Echo',
                language: 'text',
                argv: [],
                resources: {
                    'logo-32x32': '',
                    'logo-64x64': ''
                }
            },
            create: async (options: IKernel.IOptions): Promise<IKernel> => {
                return new EchoKernel(options);
            }
        });
    }
};


const plugins: JupyterLiteServerPlugin<any>[] = [kernel];

export default plugins;

@oovm
Copy link
Owner Author

oovm commented Sep 27, 2023

Rust seems unable to export a subtype.

rustwasm/wasm-bindgen#1721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant