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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ name as the package unless otherwise specified:
- `tree`
- `vim`

## Version compatibility

The filesystem used in `cockle` is built using a specific version of Emscripten, and for maximum
compatibility the WebAssembly commands used in `cockle` should be built using the same version of
Emscripten. WebAssembly commands built on Emscripten-forge are hosted on different
[prefix.dev](https://prefix.dev/channels) channels depending on the Emscripten version.

| `cockle` version | `emscripten` version | `prefix.dev` channel |
| ------------------- | -------------------- | ---------------------- |
| >= 1.3.0 | 4.0.9 | `emscripten-forge-4x` |
| >= 0.1.14, <= 1.2.0 | 3.1.73 | `emscripten-forge-dev` |

## Build

```bash
Expand Down
2 changes: 1 addition & 1 deletion src/tools/prepare_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const zod = require('zod');

const ENV_NAME = 'cockle_wasm_env';
const PLATFORM = 'emscripten-wasm32';
const CHANNELS = ['https://repo.prefix.dev/emscripten-forge-dev', 'conda-forge'];
const CHANNELS = ['https://repo.prefix.dev/emscripten-forge-4x', 'conda-forge'];

if (process.argv.length !== 4 || (process.argv[2] !== '--list' && process.argv[2] !== '--copy')) {
console.log('Usage: prepare_wasm --list list-filename');
Expand Down
62 changes: 29 additions & 33 deletions src/types/wasm_module.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This file is created by the emscripten build process of the cockle_fs package so that it
* matches the version of emscripten (3.1.73) that is used for WebAssembly command packages.
* matches the version of emscripten (4.0.9) that is used for WebAssembly command packages.
*
* Modified to add extra optional functions and properties to WasmModule such as ENV and
* getEnvStrings, and to add IWebAssemblyModule.
Expand All @@ -18,19 +18,24 @@ declare namespace RuntimeExports {
export let currentPath: string;
export let initialized: boolean;
export let ignorePermissions: boolean;
export { ErrnoError };
export let filesystems: any;
export let syncFSRequests: number;
export let readFiles: {};
export { ErrnoError };
export { FSStream };
export { FSNode };
export function lookupPath(
path: any,
opts?: {}
): {
path: string;
node: any;
};
):
| {
path: string;
node?: undefined;
}
| {
path: string;
node: any;
};
export function getPath(node: any): any;
export function hashName(parentid: any, name: any): number;
export function hashAddNode(node: any): void;
Expand All @@ -53,13 +58,15 @@ declare namespace RuntimeExports {
export function mayCreate(dir: any, name: any): any;
export function mayDelete(dir: any, name: any, isdir: any): any;
export function mayOpen(node: any, flags: any): any;
export function checkOpExists(op: any, err: any): any;
export let MAX_OPEN_FDS: number;
export function nextfd(): number;
export function getStreamChecked(fd: any): any;
export function getStream(fd: any): any;
export function createStream(stream: any, fd?: number): any;
export function closeStream(fd: any): void;
export function dupStream(origStream: any, fd?: number): any;
export function doSetAttr(stream: any, node: any, attr: any): void;
export namespace chrdev_stream_ops {
function open(stream: any): void;
function llseek(): never;
Expand All @@ -75,7 +82,9 @@ declare namespace RuntimeExports {
export function unmount(mountpoint: any): void;
export function lookup(parent: any, name: any): any;
export function mknod(path: any, mode: any, dev: any): any;
export function statfs(path: any): {
export function statfs(path: any): any;
export function statfsStream(stream: any): any;
export function statfsNode(node: any): {
bsize: number;
frsize: number;
blocks: number;
Expand All @@ -98,13 +107,17 @@ declare namespace RuntimeExports {
export function unlink(path: any): void;
export function readlink(path: any): any;
export function stat(path: any, dontFollow: any): any;
export function fstat(fd: any): any;
export function lstat(path: any): any;
export function doChmod(stream: any, node: any, mode: any, dontFollow: any): void;
export function chmod(path: any, mode: any, dontFollow: any): void;
export function lchmod(path: any, mode: any): void;
export function fchmod(fd: any, mode: any): void;
export function doChown(stream: any, node: any, dontFollow: any): void;
export function chown(path: any, uid: any, gid: any, dontFollow: any): void;
export function lchown(path: any, uid: any, gid: any): void;
export function fchown(fd: any, uid: any, gid: any): void;
export function doTruncate(stream: any, node: any, len: any): void;
export function truncate(path: any, len: any): void;
export function ftruncate(fd: any, len: any): void;
export function utime(path: any, atime: any, mtime: any): void;
Expand All @@ -121,7 +134,6 @@ declare namespace RuntimeExports {
position: any,
canOwn: any
): any;
export function allocate(stream: any, offset: any, length: any): void;
export function mmap(stream: any, length: any, position: any, prot: any, flags: any): any;
export function msync(stream: any, buffer: any, offset: any, length: any, mmapFlags: any): any;
export function ioctl(stream: any, cmd: any, arg: any): any;
Expand Down Expand Up @@ -354,26 +366,8 @@ declare namespace RuntimeExports {
function llseek(stream: any, offset: any, whence: any): any;
}
}
let HEAPF32: any;
let HEAPF64: any;
let HEAP_DATA_VIEW: any;
let HEAP8: any;
let HEAPU8: any;
let HEAP16: any;
let HEAPU16: any;
let HEAP32: any;
let HEAPU32: any;
let HEAP64: any;
let HEAPU64: any;
let FS_createPath: any;
function FS_createDataFile(
parent: any,
name: any,
fileData: any,
canRead: any,
canWrite: any,
canOwn: any
): void;
function FS_createPath(...args: any[]): any;
function FS_createDataFile(...args: any[]): any;
function FS_createPreloadedFile(
parent: any,
name: any,
Expand All @@ -386,9 +380,9 @@ declare namespace RuntimeExports {
canOwn: any,
preFinish: any
): void;
function FS_unlink(path: any): any;
let FS_createLazyFile: any;
let FS_createDevice: any;
function FS_unlink(...args: any[]): any;
function FS_createLazyFile(...args: any[]): any;
function FS_createDevice(...args: any[]): any;
let addRunDependency: any;
let removeRunDependency: any;
}
Expand Down Expand Up @@ -423,6 +417,9 @@ declare class FSNode {
name: any;
mode: any;
rdev: any;
atime: number;
mtime: number;
ctime: number;
set read(val: boolean);
get read(): boolean;
set write(val: boolean);
Expand All @@ -437,6 +434,5 @@ interface WasmModule {
}

export type MainModule = WasmModule & typeof RuntimeExports;
export default function MainModuleFactory(options?: unknown): Promise<MainModule>;

export type IWebAssemblyModule = typeof MainModuleFactory;
export default function MainModuleFactory(options?: unknown): Promise<MainModule>;
4 changes: 2 additions & 2 deletions test/integration-tests/command/cockle-config-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ test.describe('cockle-config command', () => {
const lines = output.split('\r\n');
expect(lines.length).toBe(7);
expect(lines[2]).toEqual(
'│ package │ type │ version │ build string │ source │'
'│ package │ type │ version │ build string │ source │'
);
expect(lines[4]).toMatch(
'│ grep │ wasm │ 3.12 │ h4e94343_0 │ https://repo.prefix.dev/emscripten-forge-dev │'
'│ grep │ wasm │ 3.12 │ h8b79025_0 │ https://repo.prefix.dev/emscripten-forge-4x │'
);

const output1 = await shellLineSimple(page, 'cockle-config package xyz123');
Expand Down
2 changes: 1 addition & 1 deletion test/integration-tests/command/nano.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { shellLineSimple, test } from '../utils';
test.describe('nano command', () => {
test('should output version', async ({ page }) => {
const output = await shellLineSimple(page, 'nano --version');
expect(output).toMatch(/^nano --version\r\n GNU nano, version 8.2\r\n/);
expect(output).toMatch(/^nano --version\r\n GNU nano, version 8.6\r\n/);
});

const stdinOptions = ['sab', 'sw'];
Expand Down
2 changes: 1 addition & 1 deletion test/integration-tests/command/tee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe('tee command', () => {
await shell.inputLine('tee -x');
return [output.text, await shell.exitCode()];
});
expect(output[0]).toMatch("tee -x\r\ntee: invalid option -- 'x'\r\n");
expect(output[0]).toMatch('tee -x\r\ntee: unrecognized option: x\r\n');
expect(output[1]).toEqual(1);
});
});
9 changes: 9 additions & 0 deletions test/integration-tests/command/wasm-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,13 @@ test.describe('wasm-test', () => {
const lines = output.split('\r\n');
expect(lines[1]).toMatch(/^ABCDEFGHIJKLMNOPQRSTUVWXYZ/);
});

test('should write emscripten version', async ({ page }) => {
const output = await page.evaluate(async () => {
const { shell, output } = await globalThis.cockle.shellSetupEmpty();
await shell.inputLine('wasm-test emscripten');
return output.text;
});
expect(output).toMatch('\r\nEmscripten version: 4.0.9\r\n');
});
});
4 changes: 2 additions & 2 deletions test/util-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ the C files will need to be recompiled. The recommended process to recompile is
[emsdk docker image](https://hub.docker.com/r/emscripten/emsdk) as follows:

```bash
docker pull emscripten/emsdk:3.1.73
docker pull emscripten/emsdk:4.0.9
```

then from this directory:

```bash
docker run -v $PWD:/src -it emscripten/emsdk:3.1.73 bash
docker run -v $PWD:/src -it emscripten/emsdk:4.0.9 bash
```

In the docker image:
Expand Down
5 changes: 5 additions & 0 deletions test/util-wasm/wasm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <emscripten/version.h>

int argsInclude(int argc, char** argv, char* check) {
for (int i = 1; i < argc; i++) {
Expand Down Expand Up @@ -89,6 +90,10 @@ int main(int argc, char** argv) {
fclose(fp);
}

if (argsInclude(argc, argv, "emscripten")) {
printf("Emscripten version: %d.%d.%d\n", __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__);
}

if (argsInclude(argc, argv, "exitCode")) {
return 1;
}
Expand Down
13 changes: 7 additions & 6 deletions test/util-wasm/wasm/check_termios.js

Large diffs are not rendered by default.

Binary file modified test/util-wasm/wasm/check_termios.wasm
Binary file not shown.
13 changes: 7 additions & 6 deletions test/util-wasm/wasm/wasm-test.js

Large diffs are not rendered by default.

Binary file modified test/util-wasm/wasm/wasm-test.wasm
Binary file not shown.
Loading