Something went wrong. Try again.
An experimental port of NetBSD, FreeBSD, OpenBSD, and XNU to unkernel unkernel.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677// SPDX-License-Identifier: MIT// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>// The SDK from source (the page is built with it, not with the published// dist/), with the page's own kernel (virtual:unkernel-kernel, vite.config.ts;// web/scripts/kernel.ts pageSource() picks it when the dev server starts or// the page is built): the base bundle unkernel.wasm, which boot.ts starts// with a distro image (createKernel({ distro })), a hashed Vite asset in a// build. js/web.ts is not imported, so the SDK's own bundled kernel (the// symlink into vendor/) is not part of the page.import { createKernelOn, type CreateKernelOptions, type KernelHandle, type KernelInstance, type WorkerOption } from "../../js/core/instance.ts";import type { WorkerKernel } from "../../js/core/worker-host.ts";import { webPlatform } from "../../js/web/platform.ts";import { glUrl, kernelSmpUrl, kernelUrl, vkShaderUrl } from "virtual:unkernel-kernel";
export * from "../../js/core/index.ts";export { DEFAULT_MEMORY_FALLBACK_MIB, autoMemoryMiB } from "../../js/web/memory.ts";export { DATA_DISK_NAME, DataDiskSpaceError, dataDiskInfo, fenceDataDisk, importDataDisk, openDataDisk, openDistroDisk, resetDataDisk } from "../../js/web/disk.ts";export type { DataDiskBackend, DataDiskInfo } from "../../js/web/disk.ts";export { opfsAvailable, opfsBlocker } from "../../js/web/opfs.ts";export { createAudioOut } from "../../js/web/audio.ts";export { createAudioIn } from "../../js/web/audio-in.ts";export { createCamera } from "../../js/web/camera.ts";export type { CameraColour } from "../../js/web/camera-encoder.ts";export { webCpuBlocker } from "../../js/web/cpu.ts";export { serveWasiPrograms } from "../../js/web/wasi.ts";export { WebSerialBackend, serialPortLabel, webSerial, webSerialBackend, webSerialBlocker } from "../../js/web/serial.ts";export type { WebSerialPort } from "../../js/web/serial.ts";export { WEB_BLUETOOTH_BLOCKLIST, WebBluetoothCentral, webBluetooth, webBluetoothAvailable, webBluetoothBlocker } from "../../js/web/bluetooth.ts";export { WebUsbBackend, webUsb, webUsbBackend, webUsbBlocker } from "../../js/web/usb.ts";export type { WebUsbDevice } from "../../js/web/usb.ts";
/** * The kernel the page runs on one CPU: the base bundle (vmlinux32.wasm + * the base initramfs, kernel/tools/bundle.mjs) without its SMP patch * (web/scripts/kernel.ts baseSplit()). And the SMP kernel of the same * bundle, its own hashed asset, or null when the bundle has no SMP patch: * fetched only when the page boots on more than one CPU (?cpus=N, config.ts; * boot.ts). */export { kernelSmpUrl, kernelUrl };
/** * The guest GL renderer (virgl.mjs, with virgl.wasm next to it), or null * when the page's build has none: imported by the SDK only for * createKernel({ gl }) (the GL option, config.ts). */export { glUrl };
/** * The guest Vulkan renderer's SPIR-V to WGSL translator (kwvk-naga.wasm), or * null when the page's build has none: with createKernel({ vk }) (the Vulkan * option, config.ts) the SDK fetches it, and imports the renderer's modules * (chunks of their own), only at the guest's first Vulkan instance. */export { vkShaderUrl };
const platform = webPlatform(kernelUrl, glUrl ?? undefined, vkShaderUrl ? { shaderWasm: vkShaderUrl, load: async () => { const [host, shader] = await Promise.all([import("../../js/core/vk-host.ts"), import("../../js/core/vk-shader.ts")]); return { VkRenderer: host.VkRenderer, loadVkShader: shader.loadVkShader as (wasm: never) => Promise<unknown> }; },} : undefined);
/** * js/web.ts's createKernel(), with the page's kernel as the default; with * `worker: true` (?worker=1) on a Web Worker (js/web/worker.ts, which Vite * bundles as a worker), which starts an SMP kernel's other CPUs as nested * workers (js/web/cpu.ts) when `cpus` asks for them. */export function createKernel(opts: CreateKernelOptions & { worker: true }): Promise<WorkerKernel>;export function createKernel(opts?: CreateKernelOptions & { worker?: false }): Promise<KernelInstance>;export function createKernel(opts?: CreateKernelOptions & WorkerOption): Promise<KernelHandle>;export function createKernel(opts: CreateKernelOptions & WorkerOption = {}): Promise<KernelHandle> { return createKernelOn(platform, opts);}