Skip to content
Merged
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
64 changes: 64 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,67 @@ jobs:
- name: Run all script for (${{ matrix.project.name }})
run: |
pnpm --filter '${{ matrix.project.workspace }}' run all

test-extended:
runs-on: ${{ matrix.os }}
needs:
- build
permissions:
contents: read
strategy:
matrix:
os:
- ubuntu-latest
node:
- latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
persist-credentials: false

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ matrix.node }}

- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
with:
version: 11

- uses: taiki-e/cache-cargo-install-action@417450f3c33ee20393705369577571770643d4c7 # v3.0.7
with:
tool: wasm-tools
- uses: taiki-e/cache-cargo-install-action@417450f3c33ee20393705369577571770643d4c7 # v3.0.7
with:
tool: wit-bindgen-cli
- uses: taiki-e/cache-cargo-install-action@417450f3c33ee20393705369577571770643d4c7 # v3.0.7
with:
tool: wac-cli
- uses: taiki-e/cache-cargo-install-action@417450f3c33ee20393705369577571770643d4c7 # v3.0.7
with:
tool: just
- uses: taiki-e/cache-cargo-install-action@417450f3c33ee20393705369577571770643d4c7 # v3.0.7
with:
tool: wkg

- id: wasi-sdk
uses: bytecodealliance/setup-wasi-sdk-action@b2de090b44eb70013ee96b393727d473b35e1728

- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

- run: pnpm install

- name: Restore jco build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: build
path: packages/jco/obj

- name: Build extended component tree
working-directory: test/components
env:
WASI_SDK: ${{ steps.wasi-sdk.outputs.wasi-sdk-path }}
run: just build

- name: Run extended component tests
run: |
pnpm --filter '@bytecodealliance/jco' run test:extended
1 change: 1 addition & 0 deletions packages/jco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"lint:fix": "oxlint --fix",
"test": "vitest run -c test/vitest.ts",
"test:lts": "vitest run -c test/vitest.lts.ts",
"test:extended": "vitest run -c test/vitest.extended.ts",
"prepack": "cargo xtask build release"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/jco/test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const P3_COMPONENT_FIXTURES_DIR = join(COMPONENT_FIXTURES_DIR, "p3");
/** Path to built custom rust components (i.e. output of `cargo xtask build-test-components`) */
export const LOCAL_TEST_COMPONENTS_DIR = join(COMPONENT_FIXTURES_DIR, "../../output/rust-test-components");

/** Path to built extended test components (i.e. output of `just build` run in `jco/test/components`) */
export const EXTENDED_TEST_COMPONENTS_DIR = fileURLToPath(new URL("../../../test/components/output", import.meta.url));

/**
* Retrieve a list of all component fixtures
*
Expand Down
18 changes: 18 additions & 0 deletions packages/jco/test/extended/jco-issue-1380.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { join } from "node:path";

import { suite, test, assert } from "vitest";

import { exec, jcoPath, fileExists } from "../helpers.js";
import { EXTENDED_TEST_COMPONENTS_DIR } from "../common.js";

suite("jco-issue-1380", () => {
test("composed component runs", async () => {
const combinedComponentPath = join(EXTENDED_TEST_COMPONENTS_DIR, "jco-issue-1380/composed.wasm");
assert(await fileExists(combinedComponentPath), "built composed component must be in place");

const { stdout, stderr } = await exec(jcoPath, "run", combinedComponentPath);

assert.strictEqual(stdout, "");
assert.strictEqual(stderr, "");
});
});
6 changes: 6 additions & 0 deletions packages/jco/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,9 @@ export async function getCurrentWitComponentVersion() {
CURRENT_WIT_COMPONENT_VERSION = version;
return CURRENT_WIT_COMPONENT_VERSION;
}

export async function fileExists(p) {
return stat(p)
.then((f) => f.isFile())
.catch(() => false);
}
30 changes: 30 additions & 0 deletions packages/jco/test/vitest.extended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { availableParallelism } from "node:os";

import { defineConfig } from "vitest/config";

const DEFAULT_TIMEOUT_MS = 1000 * 60 * 1; // 60s
const CI_DEFAULT_TIMEOUT_MS = 1000 * 60 * 3; // 1m

const REPORTERS = process.env.GITHUB_ACTIONS ? ["verbose", "github-actions"] : ["verbose"];
const JSPI_EXEC_ARGV = "Suspending" in WebAssembly ? [] : ["--experimental-wasm-jspi"];

export default defineConfig({
test: {
reporters: REPORTERS,
maxConcurrency: Math.max(availableParallelism() / 2, 5),
disableConsoleIntercept: true,
printConsoleTrace: true,
passWithNoTests: false,
setupFiles: ["test/meta-resolve-stub.ts"],
include: ["test/extended/**/*.js"],
testTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
hookTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
teardownTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
pool: "forks",
poolOptions: {
forks: {
execArgv: [...JSPI_EXEC_ARGV, "--stack-trace-limit=100"],
},
},
},
});
1 change: 1 addition & 0 deletions packages/jco/test/vitest.lts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig({
setupFiles: ["test/meta-resolve-stub.ts"],
include: ["test/*.js"],
exclude: [
"test/extended/*",
"test/output/*",
"test/fixtures/*",
"test/common.js",
Expand Down
1 change: 1 addition & 0 deletions packages/jco/test/vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
setupFiles: ["test/meta-resolve-stub.ts"],
include: ["test/**/*.js"],
exclude: [
"test/extended/*",
"test/output/*",
"test/fixtures/*",
"test/common.js",
Expand Down
5 changes: 5 additions & 0 deletions test/components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# while the output folder is present, we should ignore all it's contents
output/*

# wasm files should not be checked in, generally
*.wasm
60 changes: 60 additions & 0 deletions test/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Test Components

This folder contains components used for tests, written in various programming languages.

While these tests are not required for local Jco builds, they are part of an extended
regression suite (mostly built from submitted bug reports) to ensure coverage for relatively
niche or rare cases.

To run the tests that use these files, you will need to run the "extended" test suite:

```console
pnpm --filter '@bytetcodealliance/jco' test:extended
```

# Building individual components

## General dependencies

Most components are built via the `justfile`s included in their code directories. Generally you
may need the following software to build any individual component:

| Software | Description |
|------------------------------|---------------------------------------------------------------------|
| [`just`][just] | General task runner |
| [`wkg`][wkg] | Package manager for WebAssembly components |
| [`wit-bindgen`][wit-bindgen] | Bindings generator for WebAssembly that supports multiple languages |
| [`wac`][wac] | Component composition tool |

You may list the `just` targets available at the top level (the `justfile` in this folder) via the command below:

```console
just
```

Most components are buildable from the top level `justfile`. For example, the below command
will build all components related to the `jco-issue-1380` subproject:

```
just build jco-issue-1380
```

[just]: https://github.com/casey/just
[wkg]: https://github.com/bytecodealliance/wasm-pkg-tools
[wit-bindgen]: https://github.com/bytecodealliance/wit-bindgen
[wac]: https://github.com/bytecodealliance/wac

## Per-ecosystem dependencies

Each langauge ecosystem may require separate build systems and local dependencies. A
useful but likely incomplete list is below:

| Language | Dependency | Description |
|----------------------|--------------------------------------|------------------------------------------------------------------------------|
| [C++ (`cpp`)](./cpp) | [`wasi-sdk`][wasi-sdk] | Bytecode Alliance maintained toolin for building C/C++ components |
| [Python](./python) | [`uv`][uv] | Python package manager |
| | [`componentize-py`][componentize-py] | Bytecode Alliance maintained tooling for building Python projects components |

[wasi-sdk]: https://github.com/WebAssembly/wasi-sdk
[uv]: https://github.com/astral-sh/uv
[componentize-py]: https://github.com/bytecodealliance/componentize-py/
2 changes: 2 additions & 0 deletions test/components/cpp/jco-issue-1380/caller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bindings
component.wasm
10 changes: 10 additions & 0 deletions test/components/cpp/jco-issue-1380/caller/component.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "bindings/consumer_cpp.h"

#include <expected>
#include <iostream>

std::expected<void, wit::Void> exports::wasi::cli::run::Run() {
auto h = ::test::jco_bug::iface::OpenTemp();
h.Append("|x|");
return {};
}
35 changes: 35 additions & 0 deletions test/components/cpp/jco-issue-1380/caller/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
wkg := env_var_or_default("WKG", "wkg")
just := env_var_or_default("JUST", just_executable())
wit_bindgen := env_var_or_default("WIT_BINDGEN", "wit-bindgen")

# Required base dir to installation of wasi-sdk
# see: https://github.com/WebAssembly/wasi-sdk
wasi_sdk_base_dir := env_var_or_default("WASI_SDK", "/opt/wasi-sdk")

@_default:
{{just}} --list

# Fetch required WIT (i.e. wasi)
wit-fetch:
{{wkg}} wit fetch

# NOTE: you will need a recent version of wit-bindgen
#
# Generate WIT bindings
gen-bindings: wit-fetch
{{wit_bindgen}} cpp wit --world consumer --out-dir bindings

# Build python wasm component
build: gen-bindings
@if [ ! -d "{{wasi_sdk_base_dir}}" ]; then \
echo '[error] failed to find wasi-sdk dir [{{wasi_sdk_base_dir}}]'; \
echo ' is wasi-sdk installed? (at /opt/wasi-sdk, or specified via WASI_SDK env var)'; \
exit -1; \
fi
{{wasi_sdk_base_dir}}/bin/wasm32-wasip2-clang++ \
-std=c++23 \
-mexec-model=reactor \
-o component.wasm \
component.cpp \
bindings/consumer.cpp \
bindings/consumer_component_type.o
16 changes: 16 additions & 0 deletions test/components/cpp/jco-issue-1380/caller/wit/component.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test:jco-bug;

interface iface {
resource handle {
constructor(path: string);
append: func(data: string);
}

open-temp: func() -> own<handle>;
}

world consumer {
include wasi:cli/imports@0.2.0;
import iface;
export wasi:cli/run@0.2.0;
}
Loading
Loading