-
Notifications
You must be signed in to change notification settings - Fork 124
chore: add cpp and python build toolchains #1579
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
Merged
vados-cosmonic
merged 4 commits into
bytecodealliance:main
from
vados-cosmonic:chore=add-cpp-and-python-build-toolchains
Jun 2, 2026
+1,605
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9c7b7a6
test(jco): add machinery for cpp & python component builds
vados-cosmonic 6920b07
test(jco): add extended test suite for niche regression tests
vados-cosmonic 6948b83
feat(ci): run jco extended tests in CI
vados-cosmonic 4e514a6
fix(ci): wasi-sdk path when building
vados-cosmonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, ""); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"], | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| bindings | ||
| component.wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 {}; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
16
test/components/cpp/jco-issue-1380/caller/wit/component.wit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.