File
Blob: src/pyodide/types/emscripten.d.ts
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | interface ENV { |
| 6 | HOME: string; |
| 7 | [k: string]: string; |
| 8 | } |
| 9 | |
| 10 | interface PyodideConfig { |
| 11 | env: ENV; |
| 12 | jsglobals: typeof globalThis; |
| 13 | resolveLockFilePromise?: (lockfile: PackageLock) => void; |
| 14 | indexURL?: string; |
| 15 | _makeSnapshot?: boolean; |
| 16 | lockFileURL: ''; |
| 17 | enableRunUntilComplete: boolean; |
| 18 | } |
| 19 | |
| 20 | type SerializedHiwireValue = { path: string[] } | { serialized: any } | null; |
| 21 | |
| 22 | type SnapshotConfig = { |
| 23 | hiwireKeys: SerializedHiwireValue[]; |
| 24 | immortalKeys: string[]; |
| 25 | }; |
| 26 | |
| 27 | interface API { |
| 28 | config: PyodideConfig; |
| 29 | finalizeBootstrap: ( |
| 30 | fromSnapshot?: SnapshotConfig, |
| 31 | snapshotDeserializer?: (obj: any) => any |
| 32 | ) => void; |
| 33 | public_api: Pyodide; |
| 34 | rawRun: (code: string) => [status: number, err: string]; |
| 35 | initializeStreams: ( |
| 36 | stdin?: any, |
| 37 | stdout?: (a: string) => void, |
| 38 | stderr?: (a: string) => void |
| 39 | ) => void; |
| 40 | version: '0.26.0a2' | '0.28.2'; |
| 41 | pyodide_base: { |
| 42 | pyimport_impl: PyCallable; |
| 43 | }; |
| 44 | serializeHiwireState(serializer: (obj: any) => any): SnapshotConfig; |
| 45 | pyVersionTuple: [number, number, number]; |
| 46 | scheduleCallback: (callback: () => void, timeout: number) => void; |
| 47 | // Callback invoked when Pyodide encounters a fatal error. Setting this allows |
| 48 | // the runtime to handle fatal errors (e.g., by condemning the isolate). |
| 49 | on_fatal?: (error: any) => void; |
| 50 | } |
| 51 | |
| 52 | interface LDSO { |
| 53 | loadedLibsByHandle: { |
| 54 | [handle: number]: DSO; |
| 55 | }; |
| 56 | loadedLibsByName: { |
| 57 | [name: string]: DSO; |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | interface DSO { |
| 62 | name: string; |
| 63 | refcount: number; |
| 64 | global: boolean; |
| 65 | exports: WebAssembly.Exports; |
| 66 | } |
| 67 | |
| 68 | // https://github.com/emscripten-core/emscripten/blob/main/src/lib/libpath.js |
| 69 | interface PATH { |
| 70 | normalizeArray: (parts: string[], allowAboveRoot: boolean) => string[]; |
| 71 | } |
| 72 | |
| 73 | type PreRunHook = (mod: Module) => void; |
| 74 | |
| 75 | interface EmscriptenSettings { |
| 76 | preRun: PreRunHook[]; |
| 77 | instantiateWasm: ( |
| 78 | wasmImports: WebAssembly.Imports, |
| 79 | successCallback: ( |
| 80 | inst: WebAssembly.Instance, |
| 81 | mod: WebAssembly.Module |
| 82 | ) => void |
| 83 | ) => WebAssembly.Exports; |
| 84 | reportUndefinedSymbolsNoOp: () => void; |
| 85 | noInitialRun?: boolean; |
| 86 | API: Pick<API, 'config'>; |
| 87 | readyPromise: Promise<Module>; |
| 88 | rejectReadyPromise: (e: any) => void; |
| 89 | } |
| 90 | |
| 91 | interface Module { |
| 92 | HEAP8: Uint8Array; |
| 93 | HEAPU32: Uint32Array; |
| 94 | _dump_traceback: () => void; |
| 95 | FS: FS; |
| 96 | API: API; |
| 97 | ENV: ENV; |
| 98 | LDSO: LDSO; |
| 99 | PATH: PATH; |
| 100 | newDSO: (path: string, opt: object | undefined, handle: string) => DSO; |
| 101 | _Py_Version: number; |
| 102 | _py_version_major?: () => number; |
| 103 | _py_version_minor: () => number; |
| 104 | _py_version_micro: () => number; |
| 105 | loadWebAssemblyModule: ( |
| 106 | mod: WebAssembly.Module, |
| 107 | opt: object, |
| 108 | path: string, |
| 109 | localScope: object |
| 110 | ) => WebAssembly.Exports; |
| 111 | growMemory(newSize: number): void; |
| 112 | addRunDependency(x: string): void; |
| 113 | removeRunDependency(x: string): void; |
| 114 | noInitialRun: boolean; |
| 115 | setGetRandomValues( |
| 116 | func: typeof import('pyodide-internal:topLevelEntropy/lib').getRandomValues |
| 117 | ): void; |
| 118 | setSetTimeout( |
| 119 | st: typeof setTimeout, |
| 120 | ct: typeof clearTimeout, |
| 121 | si: typeof setInterval, |
| 122 | ci: typeof clearInterval |
| 123 | ): void; |
| 124 | getMemory(size: number): number; |
| 125 | getMemoryPatched( |
| 126 | Module: Module, |
| 127 | libName: string, |
| 128 | handle: number, |
| 129 | size: number |
| 130 | ): number; |
| 131 | promise: Promise<void>; |
| 132 | reportUndefinedSymbols(): void; |
| 133 | wasmTable: WebAssembly.Table; |
| 134 | // Set snapshotDebug to true to print relocation information when loading dynamic libraries. If |
| 135 | // there are crashes involving snapshots this information can be compared between when creating |
| 136 | // and using the snapshot and any discrepancy explains the crash. |
| 137 | snapshotDebug?: boolean; |
| 138 | getEmptyTableSlot(): number; |
| 139 | freeTableIndexes: number[]; |
| 140 | LD_LIBRARY_PATH: string; |
| 141 | Py_EmscriptenSignalBuffer: Uint8Array; |
| 142 | _Py_EMSCRIPTEN_SIGNAL_HANDLING: number; |
| 143 | ___memory_base: WebAssembly.Global<'i32'>; |
| 144 | compileModuleFromReadOnlyFS: ( |
| 145 | Module: Module, |
| 146 | path: string |
| 147 | ) => WebAssembly.Module; |
| 148 | findLibraryFS: (libName: string, rpath: any) => string; |
| 149 | } |