From 3fc5c7a8f583e10361ac641a37dec9948c4762d9 Mon Sep 17 00:00:00 2001 From: Ralf Anton Beier Date: Sun, 11 Jan 2026 17:53:57 +0100 Subject: [PATCH] feat: add C/C++ CLI hello world examples Add runnable WASI CLI components for C and C++ using cpp_wasm_binary rule: - c/src/main.c -> hello_c_cli.wasm - cpp/src/main.cpp -> hello_cpp_cli.wasm These can be executed directly with `wasmtime run`, unlike the existing library components (hello_c_debug/release, hello_cpp_debug/release) which export interfaces for composition. Also bumps version to 0.2.0 and updates release notes. --- .github/workflows/release.yml | 14 ++++++++++---- MODULE.bazel | 2 +- c/BUILD.bazel | 10 +++++++++- c/src/main.c | 12 ++++++++++++ cpp/BUILD.bazel | 10 +++++++++- cpp/src/main.cpp | 12 ++++++++++++ 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 c/src/main.c create mode 100644 cpp/src/main.cpp diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7bf207f..b5d85b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -193,12 +193,14 @@ jobs: ### Components Included **C Components:** - - `hello_c_debug.wasm` - Debug build - - `hello_c_release.wasm` - Release build (optimized) + - `hello_c_cli.wasm` - CLI executable (runs with wasmtime) + - `hello_c_debug.wasm` - Library component (debug) + - `hello_c_release.wasm` - Library component (release) **C++ Components:** - - `hello_cpp_debug.wasm` - Debug build - - `hello_cpp_release.wasm` - Release build (optimized) + - `hello_cpp_cli.wasm` - CLI executable (runs with wasmtime) + - `hello_cpp_debug.wasm` - Library component (debug) + - `hello_cpp_release.wasm` - Library component (release) **Rust Components:** - `hello_rust.wasm` - Hello World CLI @@ -220,6 +222,10 @@ jobs: # Install wasmtime curl https://wasmtime.dev/install.sh -sSf | bash + # Run C/C++ CLI examples + wasmtime run hello_c_cli.wasm + wasmtime run hello_cpp_cli.wasm + # Run Rust CLI examples wasmtime run hello_rust.wasm wasmtime run calculator.wasm 8 + 8 diff --git a/MODULE.bazel b/MODULE.bazel index 367fd18..e762a04 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,7 +6,7 @@ pulseengine/rules_wasm_component. module( name = "hello_wasm_components", - version = "0.1.0", + version = "0.2.0", ) # Core dependency - WebAssembly Component Model rules diff --git a/c/BUILD.bazel b/c/BUILD.bazel index 95fb2b5..ee6cddc 100644 --- a/c/BUILD.bazel +++ b/c/BUILD.bazel @@ -3,7 +3,7 @@ Demonstrates building a C WASI component with debug and release variants. """ -load("@rules_wasm_component//cpp:defs.bzl", "cpp_component") +load("@rules_wasm_component//cpp:defs.bzl", "cpp_component", "cpp_wasm_binary") load("@rules_wasm_component//wit:defs.bzl", "wit_library") package(default_visibility = ["//visibility:public"]) @@ -44,10 +44,18 @@ alias( actual = ":hello_c_release", ) +# CLI binary (runs directly with wasmtime) +cpp_wasm_binary( + name = "hello_c_cli", + srcs = ["src/main.c"], + language = "c", +) + # All variants filegroup( name = "all", srcs = [ + ":hello_c_cli", ":hello_c_debug", ":hello_c_release", ], diff --git a/c/src/main.c b/c/src/main.c new file mode 100644 index 0000000..1b95807 --- /dev/null +++ b/c/src/main.c @@ -0,0 +1,12 @@ +/** + * Hello World WASI CLI in C + * + * Simple main() that prints to stdout - runs directly with wasmtime. + */ + +#include + +int main(void) { + printf("Hello wasm component world from C!\n"); + return 0; +} diff --git a/cpp/BUILD.bazel b/cpp/BUILD.bazel index b603e8e..89e6fe8 100644 --- a/cpp/BUILD.bazel +++ b/cpp/BUILD.bazel @@ -3,7 +3,7 @@ Demonstrates building a C++ WASI component with debug and release variants. """ -load("@rules_wasm_component//cpp:defs.bzl", "cpp_component") +load("@rules_wasm_component//cpp:defs.bzl", "cpp_component", "cpp_wasm_binary") load("@rules_wasm_component//wit:defs.bzl", "wit_library") package(default_visibility = ["//visibility:public"]) @@ -50,10 +50,18 @@ alias( actual = ":hello_cpp_release", ) +# CLI binary (runs directly with wasmtime) +cpp_wasm_binary( + name = "hello_cpp_cli", + srcs = ["src/main.cpp"], + language = "cpp", +) + # All variants filegroup( name = "all", srcs = [ + ":hello_cpp_cli", ":hello_cpp_debug", ":hello_cpp_release", ], diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp new file mode 100644 index 0000000..625d70f --- /dev/null +++ b/cpp/src/main.cpp @@ -0,0 +1,12 @@ +/** + * Hello World WASI CLI in C++ + * + * Simple main() that prints to stdout - runs directly with wasmtime. + */ + +#include + +int main() { + printf("Hello wasm component world from C++!\n"); + return 0; +}