Skip to content

Commit 6f4cbfc

Browse files
committed
docs: comprehensive documentation site improvements
- Remove orphaned template files (guides/example.md, reference/example.md) - Add missing production pages: publishing.mdx, performance.mdx - Add comprehensive example pages: calculator.mdx, http-service.mdx, multi-language.mdx - Update sidebar configuration with all new pages - Fix Starlark syntax highlighting using Python grammar alias - Resolve all broken internal links and references All documentation pages now exist and build successfully with proper syntax highlighting.
1 parent 7868a31 commit 6f4cbfc

File tree

14 files changed

+1411
-44
lines changed

14 files changed

+1411
-44
lines changed

MODULE.bazel.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp/defs.bzl

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ def _cpp_component_impl(ctx):
2525
headers = ctx.files.hdrs
2626
wit_file = ctx.file.wit
2727

28-
# Collect dependency headers
28+
# Collect dependency headers and libraries using CcInfo provider
2929
dep_headers = []
3030
dep_libraries = []
31+
dep_includes = []
32+
3133
for dep in ctx.attr.deps:
32-
if DefaultInfo in dep:
34+
if CcInfo in dep:
35+
# Use proper CcInfo provider for header and library information
36+
cc_info = dep[CcInfo]
37+
dep_headers.extend(cc_info.compilation_context.headers.to_list())
38+
dep_includes.extend(cc_info.compilation_context.includes.to_list())
39+
# Extract static libraries from linking context
40+
for linker_input in cc_info.linking_context.linker_inputs.to_list():
41+
for library in linker_input.libraries:
42+
if library.static_library:
43+
dep_libraries.append(library.static_library)
44+
elif DefaultInfo in dep:
45+
# Fallback for non-CcInfo dependencies (e.g., legacy rules)
3346
for file in dep[DefaultInfo].files.to_list():
3447
if file.extension in ["h", "hpp", "hh", "hxx"]:
3548
dep_headers.append(file)
@@ -74,7 +87,17 @@ def _cpp_component_impl(ctx):
7487

7588
# Basic compiler flags for Preview2
7689
compile_args.add("--target=wasm32-wasip2")
77-
compile_args.add("--sysroot=" + sysroot)
90+
# Compute sysroot path from sysroot_files for external repository compatibility
91+
if sysroot_files and sysroot_files.files:
92+
# Use the directory containing the sysroot files as the sysroot path
93+
sysroot_file = sysroot_files.files.to_list()[0]
94+
# Extract the repository-relative sysroot path
95+
sysroot_path = sysroot_file.path.split("/sysroot/")[0] + "/sysroot"
96+
else:
97+
# Fallback to configured path
98+
sysroot_path = sysroot
99+
100+
compile_args.add("--sysroot=" + sysroot_path)
78101

79102
# Component model definitions
80103
compile_args.add("-D_WASI_EMULATED_PROCESS_CLOCKS")
@@ -112,16 +135,21 @@ def _cpp_component_impl(ctx):
112135

113136
# Add C++ standard library paths for wasm32-wasip2 target
114137
if ctx.attr.language == "cpp":
115-
compile_args.add("-I" + sysroot + "/include/wasm32-wasip2/c++/v1")
116-
compile_args.add("-I" + sysroot + "/include/c++/v1")
138+
compile_args.add("-I" + sysroot_path + "/include/wasm32-wasip2/c++/v1")
139+
compile_args.add("-I" + sysroot_path + "/include/c++/v1")
117140

118141
for include in ctx.attr.includes:
119142
compile_args.add("-I" + include)
120143

121-
# Add dependency header directories
144+
# Add dependency include directories from CcInfo
145+
for include_dir in dep_includes:
146+
if include_dir not in [work_dir.path] + ctx.attr.includes:
147+
compile_args.add("-I" + include_dir)
148+
149+
# Add dependency header directories (fallback for non-CcInfo deps)
122150
for dep_hdr in dep_headers:
123151
include_dir = dep_hdr.dirname
124-
if include_dir not in [work_dir.path] + ctx.attr.includes:
152+
if include_dir not in [work_dir.path] + ctx.attr.includes + dep_includes:
125153
compile_args.add("-I" + include_dir)
126154

127155
# Defines
@@ -400,7 +428,9 @@ def _cc_component_library_impl(ctx):
400428
# Compile arguments
401429
compile_args = ctx.actions.args()
402430
compile_args.add("--target=wasm32-wasip2")
403-
compile_args.add("--sysroot=" + sysroot)
431+
# Resolve sysroot path dynamically for external repository compatibility
432+
sysroot_dir = sysroot_files.files.to_list()[0].dirname if sysroot_files.files else sysroot
433+
compile_args.add("--sysroot=" + sysroot_dir)
404434
compile_args.add("-c") # Compile only, don't link
405435

406436
# Component model definitions
@@ -480,8 +510,33 @@ def _cc_component_library_impl(ctx):
480510
progress_message = "Creating component library %s" % ctx.label,
481511
)
482512

513+
# Collect transitive headers and libraries from dependencies
514+
transitive_headers = []
515+
transitive_libraries = []
516+
transitive_includes = []
517+
518+
for dep in ctx.attr.deps:
519+
if CcInfo in dep:
520+
cc_info = dep[CcInfo]
521+
transitive_headers.append(cc_info.compilation_context.headers)
522+
transitive_includes.extend(cc_info.compilation_context.includes.to_list())
523+
transitive_libraries.append(cc_info.linking_context.linker_inputs)
524+
525+
# Create compilation context with current headers and transitive headers
526+
compilation_context = cc_common.create_compilation_context(
527+
headers = depset(ctx.files.hdrs, transitive = transitive_headers),
528+
includes = depset([h.dirname for h in ctx.files.hdrs] + ctx.attr.includes, transitive = [depset(transitive_includes)]),
529+
)
530+
531+
# Create CcInfo provider with compilation context only
532+
# Note: We don't create linking context since we're using custom WASM toolchain
533+
cc_info = CcInfo(
534+
compilation_context = compilation_context,
535+
)
536+
483537
return [
484538
DefaultInfo(files = depset([library] + ctx.files.hdrs)),
539+
cc_info,
485540
OutputGroupInfo(
486541
library = depset([library]),
487542
objects = depset(object_files),

docs-site/astro.config.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ export default defineConfig({
2323
expressiveCode: {
2424
themes: ['github-dark', 'github-light'],
2525
// Map languages for better syntax highlighting
26-
langs: ['python', 'rust', 'go', 'javascript', 'typescript', 'bash', 'yaml', 'json', 'dockerfile', 'starlark']
26+
langs: ['python', 'rust', 'go', 'javascript', 'typescript', 'bash', 'yaml', 'json', 'dockerfile'],
27+
// Use Python grammar for Starlark since Starlark syntax is a subset of Python
28+
shiki: {
29+
langAlias: {
30+
'starlark': 'python',
31+
'star': 'python',
32+
'bzl': 'python',
33+
'bazel': 'python'
34+
}
35+
}
2736
},
2837
social: [
2938
{
@@ -79,6 +88,9 @@ export default defineConfig({
7988
label: 'Examples',
8089
items: [
8190
{ label: 'Basic Component', slug: 'examples/basic' },
91+
{ label: 'Calculator (C++)', slug: 'examples/calculator' },
92+
{ label: 'HTTP Service (Go)', slug: 'examples/http-service' },
93+
{ label: 'Multi-Language System', slug: 'examples/multi-language' },
8294
],
8395
},
8496
{
@@ -98,6 +110,8 @@ export default defineConfig({
98110
label: 'Production',
99111
items: [
100112
{ label: 'Deployment Guide', slug: 'production/deployment-guide' },
113+
{ label: 'OCI Publishing', slug: 'production/publishing' },
114+
{ label: 'Performance Optimization', slug: 'production/performance' },
101115
],
102116
},
103117
{

docs-site/docs_dev.bzl

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""Bazel rule for running documentation development server with live reload"""
2+
3+
def _docs_dev_server_impl(ctx):
4+
"""Implementation of docs_dev_server rule for local development"""
5+
6+
# Get jco toolchain for hermetic Node.js access
7+
jco_toolchain = ctx.toolchains["@rules_wasm_component//toolchains:jco_toolchain_type"]
8+
node = jco_toolchain.node
9+
npm = jco_toolchain.npm
10+
11+
# Create runner script
12+
runner = ctx.actions.declare_file(ctx.attr.name + "_runner.sh")
13+
14+
# Input source files and package.json
15+
source_files = ctx.files.srcs
16+
package_json = ctx.file.package_json
17+
18+
# Prepare source file list
19+
source_paths = []
20+
for src in source_files:
21+
if src.path.startswith("docs-site/"):
22+
source_paths.append(src.path)
23+
24+
ctx.actions.write(
25+
output = runner,
26+
content = """#!/bin/bash
27+
set -euo pipefail
28+
29+
# Store paths
30+
EXEC_ROOT="$(pwd)"
31+
PACKAGE_JSON="{package_json}"
32+
NODE="{node}"
33+
NPM="{npm}"
34+
35+
# Create temporary workspace
36+
WORK_DIR="$(mktemp -d)"
37+
echo "🚀 Setting up documentation development server in: $WORK_DIR"
38+
39+
# Cleanup on exit
40+
trap "echo '🛑 Shutting down dev server...'; rm -rf $WORK_DIR" EXIT
41+
42+
# Copy package.json
43+
cp "$PACKAGE_JSON" "$WORK_DIR/package.json"
44+
45+
# Copy all source files
46+
echo "📦 Copying source files..."
47+
{copy_commands}
48+
49+
# Change to workspace
50+
cd "$WORK_DIR"
51+
52+
# Install dependencies
53+
echo "📥 Installing dependencies..."
54+
$NPM install --no-audit --no-fund
55+
56+
# Start development server
57+
echo "🌐 Starting Astro development server..."
58+
echo "📍 Documentation will be available at: http://localhost:4321"
59+
echo ""
60+
echo "Press Ctrl+C to stop the server"
61+
echo ""
62+
63+
# Run dev server
64+
$NPM run dev
65+
""".format(
66+
package_json = package_json.path,
67+
node = node.path,
68+
npm = npm.path,
69+
copy_commands = "\n".join([
70+
'if [[ "{src}" == docs-site/* ]]; then\n' +
71+
' rel_path="${{src#docs-site/}}"\n'.format(src=src) +
72+
' dest_file="$WORK_DIR/$rel_path"\n' +
73+
' dest_dir="$(dirname "$dest_file")"\n' +
74+
' mkdir -p "$dest_dir"\n' +
75+
' cp "{src}" "$dest_file"\n'.format(src=src) +
76+
'fi'
77+
for src in source_paths
78+
])
79+
),
80+
is_executable = True,
81+
)
82+
83+
return [
84+
DefaultInfo(
85+
files = depset([runner]),
86+
runfiles = ctx.runfiles(
87+
files = source_files + [package_json, node, npm],
88+
),
89+
executable = runner,
90+
),
91+
]
92+
93+
docs_dev_server = rule(
94+
implementation = _docs_dev_server_impl,
95+
attrs = {
96+
"srcs": attr.label_list(
97+
allow_files = True,
98+
mandatory = True,
99+
doc = "Documentation source files",
100+
),
101+
"package_json": attr.label(
102+
allow_single_file = ["package.json"],
103+
mandatory = True,
104+
doc = "package.json file with dependencies",
105+
),
106+
},
107+
toolchains = ["@rules_wasm_component//toolchains:jco_toolchain_type"],
108+
executable = True,
109+
doc = """
110+
Runs a development server for the documentation site with live reload.
111+
112+
This rule starts an Astro dev server on http://localhost:4321 with hot module
113+
replacement for rapid documentation development.
114+
115+
Example:
116+
docs_dev_server(
117+
name = "docs_dev",
118+
srcs = glob(["src/**/*", "public/**/*", "*.json", "*.mjs"]),
119+
package_json = "package.json",
120+
)
121+
122+
Run with:
123+
bazel run //docs-site:docs_dev
124+
""",
125+
)

0 commit comments

Comments
 (0)