Skip to content

Commit 6be8347

Browse files
committed
feat: fix Go component WIT world limitations and add TinyGo documentation
- Fixed GO111MODULE=on for proper Go module resolution in TinyGo compilation - Integrated wit-bindgen-go tool installation in TinyGo toolchain setup - Added calculator_simple_binding.go example demonstrating WIT interface usage - Updated WIT file path resolution to preserve original filenames - Created GitHub issue #80 documenting TinyGo WIT world limitations - Applied pre-commit formatting fixes across codebase - Identified TinyGo PR #4934 as upstream solution for custom WIT worlds Key technical changes: - go/defs.bzl: Changed GO111MODULE from "off" to "on" - toolchains/tinygo_toolchain.bzl: Added wit-bindgen-go installation - tools/bazel_helpers/file_ops_actions.bzl: Fixed WIT file copying - examples/go_component/: Added simple WIT binding example Root cause: TinyGo hardcodes wasi:cli/command world, ignoring custom WIT interfaces. Solution pending: TinyGo PR #4934 will add custom WIT world support.
1 parent a45db76 commit 6be8347

39 files changed

+507
-414
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def _cpp_component_impl(ctx):
175175
# Standard library control
176176
if ctx.attr.nostdlib:
177177
compile_args.add("-nostdlib")
178+
178179
# When using nostdlib, we need to be more selective about what we link
179180
compile_args.add("-Wl,--no-entry") # Don't expect a main function
180181

@@ -290,7 +291,7 @@ def _cpp_component_impl(ctx):
290291
else:
291292
binding_compile_args.add("-O0")
292293
binding_compile_args.add("-g")
293-
294+
294295
# Exception handling for binding compilation (if C++ exceptions are enabled)
295296
if ctx.attr.language == "cpp" and ctx.attr.enable_exceptions:
296297
binding_compile_args.add("-fexceptions")
@@ -325,7 +326,7 @@ def _cpp_component_impl(ctx):
325326
if ctx.attr.language == "cpp" and not ctx.attr.nostdlib:
326327
compile_args.add("-lc++")
327328
compile_args.add("-lc++abi")
328-
329+
329330
# Add exception handling support if enabled
330331
# Note: Exception handling symbols are typically in libc++abi which we already link
331332

@@ -385,7 +386,7 @@ def _cpp_component_impl(ctx):
385386
"$1" validate --features component-model "$2" >> "$3" 2>&1
386387
exit 1
387388
fi
388-
389+
389390
# Extract WIT interface for documentation
390391
echo "=== COMPONENT VALIDATION PASSED ===" > "$3"
391392
echo "Component is valid WebAssembly with component model" >> "$3"
@@ -397,7 +398,7 @@ def _cpp_component_impl(ctx):
397398
inputs = [component_wasm],
398399
outputs = [validation_log],
399400
tools = [wasm_tools],
400-
mnemonic = "ValidateWasmComponent",
401+
mnemonic = "ValidateWasmComponent",
401402
progress_message = "Validating WebAssembly component for %s" % ctx.label,
402403
)
403404

docs-site/src/content/docs/examples/wit-bindgen-with-mappings.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ wit_bindgen(
3636

3737
# Enhanced wit-bindgen with advanced features
3838
wit_bindgen(
39-
name = "advanced_bindings",
39+
name = "advanced_bindings",
4040
language = "rust",
4141
wit = ":api_interfaces",
4242
ownership = "borrowing", # Memory optimization
@@ -54,12 +54,12 @@ The example demonstrates different interface mapping strategies:
5454
wit_bindgen(
5555
name = "wasi_mapped_bindings",
5656
language = "rust",
57-
wit = ":wasi_demo_interfaces",
57+
wit = ":wasi_demo_interfaces",
5858
with_mappings = {
5959
# Map WASI interfaces to existing ecosystem crates
6060
"wasi:io/streams": "wasi::io::streams",
6161
"wasi:io/poll": "wasi::io::poll",
62-
62+
6363
# Generate custom interfaces fresh
6464
"example:wasi-demo/file-processor": "generate",
6565
},
@@ -88,7 +88,7 @@ wit_bindgen(
8888
**Development-Friendly Service:**
8989
```starlark
9090
wit_bindgen(
91-
name = "service_bindings",
91+
name = "service_bindings",
9292
ownership = "borrowing-duplicate-if-necessary", # Balanced approach
9393
additional_derives = ["Clone", "Debug", "PartialEq"], # Full debugging
9494
format_code = True,
@@ -168,19 +168,19 @@ package example:[email protected];
168168
world wasi-demo {
169169
import wasi:io/[email protected];
170170
import wasi:io/[email protected];
171-
171+
172172
export file-processor;
173173
}
174174
175175
interface file-processor {
176176
use wasi:io/streams.{input-stream, output-stream};
177177
use wasi:io/poll.{pollable};
178-
178+
179179
process-stream: func(
180180
input: borrow<input-stream>,
181181
output: borrow<output-stream>
182182
) -> result<u64, string>;
183-
183+
184184
wait-for-ready: func(pollable: borrow<pollable>) -> bool;
185185
get-processor-version: func() -> string;
186186
}
@@ -256,10 +256,10 @@ fn test_custom_derives_available() {
256256

257257
// Test Clone derive
258258
let config2 = config1.clone();
259-
259+
260260
// Test PartialEq derive
261261
assert_eq!(config1, config2);
262-
262+
263263
// Test Debug derive
264264
let debug_output = format!("{:?}", config1);
265265
assert!(debug_output.contains("ApiConfig"));
@@ -280,7 +280,7 @@ fn test_borrowing_ownership() {
280280

281281
// This should work with borrowing ownership model
282282
let _connection = Connection::new(&config);
283-
283+
284284
// We can still use config after borrowing it
285285
assert_eq!(config.endpoint, "test");
286286
}
@@ -433,7 +433,7 @@ wit_bindgen(
433433
name = "existing_bindings",
434434
language = "rust",
435435
wit = ":existing_interfaces",
436-
436+
437437
# Add basic debugging support
438438
additional_derives = ["Debug"],
439439
format_code = True,
@@ -447,7 +447,7 @@ wit_bindgen(
447447
name = "optimized_bindings",
448448
language = "rust",
449449
wit = ":interfaces",
450-
450+
451451
# Add performance optimization
452452
ownership = "borrowing-duplicate-if-necessary",
453453
additional_derives = ["Debug", "Clone"],
@@ -462,7 +462,7 @@ wit_bindgen(
462462
name = "mapped_bindings",
463463
language = "rust",
464464
wit = ":interfaces",
465-
465+
466466
with_mappings = {
467467
"wasi:io/streams": "wasi::io::streams", # Start with one mapping
468468
"my:custom/api": "generate",
@@ -480,4 +480,4 @@ This comprehensive example demonstrates how the enhanced `wit_bindgen` rule enab
480480

481481
- **[WIT Bindgen Interface Mapping](/guides/wit-bindgen-interface-mapping)**: Detailed guide on interface mapping concepts and strategies
482482
- **[WIT Bindgen Advanced Concepts](/guides/wit-bindgen-advanced-concepts)**: Language-specific implications and architectural patterns
483-
- **[WIT Bindgen Troubleshooting](/guides/wit-bindgen-troubleshooting)**: Common issues and debugging techniques
483+
- **[WIT Bindgen Troubleshooting](/guides/wit-bindgen-troubleshooting)**: Common issues and debugging techniques

0 commit comments

Comments
 (0)