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
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ jobs:

- name: Build All Targets
run: |
# Build core working targets, exclude incomplete/problematic examples
# Using explicit inclusions to avoid JavaScript component issues
# Build core working targets including JavaScript components
bazel build --keep_going -- \
//examples/go_component/... \
//examples/basic/... \
//examples/simple_module/... \
//examples/cli_tool_example/... \
//examples/cpp_component/... \
//examples/js_component:simple_js_component \
//examples/js_component:hello_js_component \
//examples/js_component:calc_js_component \
//rust/... \
//go/... \
//cpp/... \
//js/... \
//wasm/... \
//wit/... \
//tools/... \
Expand All @@ -122,14 +125,11 @@ jobs:
//test/integration/... \
//docs-site/... \
-//examples/cpp_component/multi_component_system:analytics_service \
-//examples/cli_tool_example:file_processor_cli_wasm_lib_release_host \
-//tools/checksum_updater_wasm/... \
-//tools/ssh_keygen:ssh_keygen_test \
-//test/integration:wasi_component_wasm_lib_release_host \
-//test/integration:service_b_component_wasm_lib_release_host \

- name: Run Tests
run: bazel test --test_output=errors -- //test/integration:basic_component_build_test //test/integration:basic_component_validation //test/unit:unit_tests //test/wkg/unit:smoke
run: bazel test --test_output=errors -- //test/integration:basic_component_build_test //test/integration:basic_component_validation //test/unit:unit_tests //test/wkg/unit:smoke //test/js:test_hello_js_component_provides_info //test/js:test_calc_js_component_provides_info //test/js:test_npm_dependencies_installation

- name: Run Clippy
run: echo "Skipping clippy for now due to target triple issues"
Expand Down Expand Up @@ -197,9 +197,13 @@ jobs:
//examples/simple_module/... \
//examples/cli_tool_example/... \
//examples/cpp_component/... \
//examples/js_component:simple_js_component \
//examples/js_component:hello_js_component \
//examples/js_component:calc_js_component \
//rust/... \
//go/... \
//cpp/... \
//js/... \
//wasm/... \
//wit/... \
//tools/... \
Expand All @@ -220,7 +224,7 @@ jobs:
-//test/integration:service_b_component_wasm_lib_release_host \

- name: Run Tests
run: bazel test --test_output=errors -- //test/integration:basic_component_build_test //test/integration:basic_component_validation //test/unit:unit_tests
run: bazel test --test_output=errors -- //test/integration:basic_component_build_test //test/integration:basic_component_validation //test/unit:unit_tests //test/js:test_hello_js_component_provides_info //test/js:test_calc_js_component_provides_info //test/js:test_npm_dependencies_installation

- name: Run Clippy
run: echo "Skipping clippy for now due to target triple issues"
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ repos:
- id: docs-build-check
name: Documentation Build Check
description: Validate documentation builds successfully
entry: bash -c 'cd docs-site && npm ci --silent && npm run generate:docs && npm run check'
entry: bash -c 'cd docs-site && npm run check'
language: system
files: '^docs-site/.*\.(js|ts|astro|mdx|md|json)$'
pass_filenames: false
Expand Down
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_go", version = "0.55.1")

# OCI image signing capabilities
bazel_dep(name = "rules_oci", version = "1.8.0")

# Hermetic toolchain management with pre-built binaries

# Development dependencies
Expand Down
685 changes: 684 additions & 1 deletion MODULE.bazel.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Modern Bazel rules for building WebAssembly components across multiple languages
## Why Use This?

- **Multi-language**: Build components from Rust, Go, C++, JavaScript
- **Production Ready**: OCI publishing, signing, composition, optimization
- **Production Ready**: OCI publishing, signing, composition, optimization
- **Bazel Native**: Hermetic builds, caching, cross-platform support

## Installation
Expand All @@ -21,7 +21,7 @@ bazel_dep(name = "rules_wasm_component", version = "1.0.0")
```starlark
# Build a component from Rust
rust_wasm_component_bindgen(
name = "hello_component",
name = "hello_component",
srcs = ["src/lib.rs"],
wit = ":hello_interfaces",
)
Expand All @@ -32,7 +32,7 @@ rust_wasm_component_bindgen(
📚 **[Complete Documentation →](https://github.com/pulseengine/rules_wasm_component/tree/main/docs-site)**

- **[Zero to Component in 2 Minutes](/docs-site/src/content/docs/zero-to-component.mdx)** - Fastest way to get started
- **[Language Guides](/docs-site/src/content/docs/languages/)** - Rust, Go, C++, JavaScript tutorials
- **[Language Guides](/docs-site/src/content/docs/languages/)** - Rust, Go, C++, JavaScript tutorials
- **[Production Deployment](/docs-site/src/content/docs/production/)** - OCI publishing, signing, optimization
- **[Examples](examples/)** - Working examples from basic to advanced

Expand Down
40 changes: 24 additions & 16 deletions cpp/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,20 @@ def _cpp_component_impl(ctx):
dep_includes = []

for dep in ctx.attr.deps:
if CcInfo in dep:
# Use proper CcInfo provider for header and library information
cc_info = dep[CcInfo]
dep_headers.extend(cc_info.compilation_context.headers.to_list())
dep_includes.extend(cc_info.compilation_context.includes.to_list())

# Extract static libraries from linking context
for linker_input in cc_info.linking_context.linker_inputs.to_list():
for library in linker_input.libraries:
if library.static_library:
dep_libraries.append(library.static_library)
elif DefaultInfo in dep:
# Fallback for non-CcInfo dependencies (e.g., legacy rules)
# Always check DefaultInfo first for direct file access (simpler and more reliable)
if DefaultInfo in dep:
for file in dep[DefaultInfo].files.to_list():
if file.extension in ["h", "hpp", "hh", "hxx"]:
dep_headers.append(file)
elif file.extension == "a":
dep_libraries.append(file)

# Also extract headers and includes from CcInfo for proper transitive dependencies
if CcInfo in dep:
cc_info = dep[CcInfo]
dep_headers.extend(cc_info.compilation_context.headers.to_list())
dep_includes.extend(cc_info.compilation_context.includes.to_list())

# Generate bindings directory
bindings_dir = ctx.actions.declare_directory(ctx.attr.name + "_bindings")

Expand Down Expand Up @@ -191,7 +186,7 @@ def _cpp_component_impl(ctx):
ctx.actions.run(
executable = clang,
arguments = [compile_args],
inputs = [work_dir] + sysroot_files.files.to_list() + dep_libraries,
inputs = [work_dir] + sysroot_files.files.to_list() + dep_libraries + dep_headers,
outputs = [wasm_binary],
mnemonic = "CompileCppWasm",
progress_message = "Compiling C/C++ to WASM for %s" % ctx.label,
Expand Down Expand Up @@ -467,6 +462,7 @@ def _cc_component_library_impl(ctx):
# Optimization
if ctx.attr.optimize:
compile_args.add("-O3")
compile_args.add("-flto") # Enable LTO for compatibility with cpp_component
else:
compile_args.add("-O0")
compile_args.add("-g")
Expand Down Expand Up @@ -563,10 +559,22 @@ def _cc_component_library_impl(ctx):
includes = depset([h.dirname for h in ctx.files.hdrs] + ctx.attr.includes, transitive = [depset(transitive_includes)]),
)

# Create CcInfo provider with compilation context only
# Note: We don't create linking context since we're using custom WASM toolchain
# Create linking context for the static library
# For cross-package linking, we need to provide the library through the linking context
# Use a simpler approach that works with our custom WASM toolchain
linker_input = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = [library.path], # Pass library as link flag
)

linking_context = cc_common.create_linking_context(
linker_inputs = depset([linker_input], transitive = transitive_libraries),
)

# Create CcInfo provider with both compilation and linking contexts
cc_info = CcInfo(
compilation_context = compilation_context,
linking_context = linking_context,
)

return [
Expand Down
20 changes: 7 additions & 13 deletions docs-site/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This BUILD file demonstrates the same hermetic approach used for JavaScript comp
"""

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load(":docs_build.bzl", "docs_build")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -205,22 +206,14 @@ test_suite(
],
)

# Production deployment bundle with full Astro site
genrule(
# Production deployment bundle with full Astro site - using Bazel Skylib copy_file for cross-platform compatibility
copy_file(
name = "deployment_bundle",
srcs = [
":docs_site",
":docs_validation",
],
outs = ["docs_deployment.tar.gz"],
cmd = """
# The docs_site is already a tar.gz archive, so just copy it
cp $(location :docs_site) $@
""",
message = "Creating production documentation deployment bundle",
src = ":docs_site",
out = "docs_deployment.tar.gz",
)

# Fallback deployment (for testing without full toolchain)
# Fallback deployment (for testing without full toolchain) - cross-platform compatible
genrule(
name = "fallback_deployment",
srcs = [
Expand All @@ -229,6 +222,7 @@ genrule(
],
outs = ["docs_fallback.tar.gz"],
cmd = """
# Create cross-platform tar archive without GNU-specific transforms
mkdir -p fallback_dist
cp $(location :placeholder_fallback) fallback_dist/index.html
tar -czf $@ fallback_dist/
Expand Down
28 changes: 23 additions & 5 deletions docs-site/CONTENT_HIERARCHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ This document defines the clear content hierarchy for the docs-site to prevent d
### 1. Installation & Setup (Canonical Sources)

**Primary owner:** `/installation.md`

- Complete installation instructions for all platforms
- All language-specific setup (Rust, Go, C++, JavaScript)
- Toolchain configuration details
- Troubleshooting installation issues

**Secondary references:**

- `/getting-started.mdx` - Quick reference with link to full installation
- `/first-component.md` - Minimal setup with reference to installation guide
- Language-specific guides - Link to installation for setup details
Expand All @@ -24,58 +26,68 @@ This document defines the clear content hierarchy for the docs-site to prevent d
### 2. Tutorial Progression (Learning Path)

**Ultra-fast (2 min):** `/zero-to-component.mdx`

- Immediate success using existing examples
- Minimal explanation, maximum speed
- References detailed tutorials for understanding

**Quick hands-on (10 min):** `/first-component.md`
**Quick hands-on (10 min):** `/first-component.md`

- Build from scratch step-by-step
- Focused on practical implementation
- References installation and detailed tutorials

**Complete understanding (30 min):** `/tutorials/rust-guided-walkthrough.mdx`

- Deep explanations of concepts and pipeline
- Line-by-line code analysis with diagrams
- Complete mental model building

**Technical reference:** `/tutorials/code-explained.mdx`

- Visual diagrams of component building process
- Progressive complexity with Mermaid diagrams
- Technical deep-dive into each file

### 3. Code Examples (Canonical Patterns)

**BUILD.bazel patterns:**

- **Owner:** `/examples/basic/` - Canonical Rust component pattern
- **Owner:** `/examples/calculator/` - Error handling pattern
- **Owner:** Language-specific examples - Language-specific patterns

**References:**

- Tutorial pages link to examples instead of duplicating BUILD.bazel code
- Rule reference shows usage patterns, examples show complete implementations

**WIT interface examples:**

- **Owner:** `/tutorials/code-explained.mdx` - Detailed WIT explanations
- **References:** Other pages link to detailed explanations rather than re-explaining

### 4. Advanced Topics (Specialized Ownership)

**Component Composition:**

- **Owner:** `/composition/wac/` - Complete WAC composition guide
- **References:** Getting started mentions composition, links to dedicated guide

**Performance Optimization:**

- **Owner:** `/production/performance/` - Wizer and optimization techniques
- **References:** Other pages mention performance, link to dedicated guide

**Security & Signing:**

- **Owner:** `/security/component-signing.mdx` - Complete security guide
- **References:** Brief mentions in other pages, links for details

### 5. Language-Specific Content

**Rust:** `/languages/rust/`
**Go:** `/languages/go/`
**Go:** `/languages/go/`
**C++:** `/languages/cpp/`
**JavaScript:** `/languages/javascript/`

Expand All @@ -84,10 +96,12 @@ This document defines the clear content hierarchy for the docs-site to prevent d
### 6. Reference Documentation

**Rule Reference:** `/reference/rules.mdx`

- **Owner:** Complete API documentation for all rules
- **Pattern:** Examples show usage, reference shows complete API

**Troubleshooting:** `/troubleshooting/common-issues.mdx`

- **Owner:** All error messages and solutions
- **Pattern:** Other pages reference troubleshooting for specific issues

Expand All @@ -96,14 +110,16 @@ This document defines the clear content hierarchy for the docs-site to prevent d
### ✅ Good Patterns

1. **Provide minimal context + link to canonical source**

```markdown
For complete installation instructions, see the [Installation Guide](/installation/).

Quick setup for Rust:
[minimal code example]
```

2. **Use approach grids for different learning paths**

```html
<div class="approach-grid">
<div class="approach-card">
Expand All @@ -115,6 +131,7 @@ This document defines the clear content hierarchy for the docs-site to prevent d
```

3. **Reference examples instead of duplicating BUILD.bazel**

```markdown
For the complete BUILD.bazel pattern, see the [basic example](/examples/basic/).
```
Expand All @@ -126,7 +143,7 @@ This document defines the clear content hierarchy for the docs-site to prevent d
- ✅ Provide minimal setup + link to installation guide

2. **Re-explaining WIT syntax**
- ❌ Explain WIT syntax on every tutorial page
- ❌ Explain WIT syntax on every tutorial page
- ✅ Link to detailed explanation in code-explained tutorial

3. **Duplicating BUILD.bazel examples**
Expand Down Expand Up @@ -165,6 +182,7 @@ Before publishing content changes:
## Maintenance

This hierarchy should be reviewed quarterly to:

- Identify new duplication that has crept in
- Update reference patterns as content evolves
- Ensure learning paths remain clear and progressive
Expand All @@ -177,4 +195,4 @@ This hierarchy should be reviewed quarterly to:
- **Fast answers** - Users can quickly find what they need
- **Cross-references work** - Links lead to the right level of detail

This hierarchy ensures our documentation grows systematically while remaining maintainable and user-friendly.
This hierarchy ensures our documentation grows systematically while remaining maintainable and user-friendly.
4 changes: 1 addition & 3 deletions docs-site/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export default defineConfig({
description: 'Modern Bazel rules for building and composing WebAssembly components',
expressiveCode: {
themes: ['github-dark', 'github-light'],
// Map languages for better syntax highlighting
langs: ['python', 'rust', 'go', 'javascript', 'typescript', 'bash', 'yaml', 'json', 'dockerfile'],
// Use Python grammar for Starlark since Starlark syntax is a subset of Python
shiki: {
langAlias: {
Expand Down Expand Up @@ -82,7 +80,7 @@ export default defineConfig({
{
label: 'Guides',
items: [
{ label: 'Native vs Guest Bindings', slug: 'guides/host-vs-wasm-bindings' },
{ label: 'Guest vs Native-Guest Bindings', slug: 'guides/guest-vs-native-guest-bindings' },
{ label: 'Advanced Features', slug: 'guides/advanced-features' },
{ label: 'Migration Guide', slug: 'guides/migration' },
{ label: 'Toolchain Configuration', slug: 'guides/toolchain-configuration' },
Expand Down
Loading
Loading