Skip to content
Open
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
15 changes: 11 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "rules_go", version = "0.59.0")

# MoonBit language support for WebAssembly components
# Required for moonbit_wasm_cli and moonbit_wasm_binary rules
# Note: rules_moonbit is not yet in BCR - uses git_override
bazel_dep(name = "rules_moonbit", version = "0.1.0")
# Dev dependency: rules_moonbit is not yet in BCR. Downstream users who want
# MoonBit support must add their own bazel_dep + git_override for rules_moonbit.
# The moonbit/ rules are available but only resolve when rules_moonbit is present.
bazel_dep(name = "rules_moonbit", version = "0.1.0", dev_dependency = True)
git_override(
module_name = "rules_moonbit",
remote = "https://github.com/pulseengine/rules_moonbit.git",
commit = "b5bbfe8ef1f87b42c77f168640817f67ed8758a3",
commit = "e95c912e55094b90b6c02a6052c0a284b142e6b8", # includes chmod + bundle + dev_dependency fix
)

# OCI image signing capabilities
Expand Down Expand Up @@ -241,6 +242,12 @@ use_repo(componentize_py, "componentize_py_toolchain")

register_toolchains("@componentize_py_toolchain//:componentize_py_toolchain")

# MoonBit hermetic toolchain for WebAssembly component builds (dev only)
moonbit = use_extension("@rules_moonbit//moonbit:extensions.bzl", "moonbit_toolchain_extension", dev_dependency = True)
use_repo(moonbit, "moonbit_toolchain")

register_toolchains("@moonbit_toolchain//:moonbit_toolchain", dev_dependency = True)

# File Operations Component toolchain for universal file handling
register_toolchains("//toolchains:file_ops_toolchain_target")

Expand Down
2 changes: 2 additions & 0 deletions cpp/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Example usage:
)
"""

load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//providers:providers.bzl", "WasmComponentInfo")
load("//rust:transitions.bzl", "wasm_transition")
load("//tools/bazel_helpers:file_ops_actions.bzl", "setup_cpp_workspace_action")
Expand Down
1 change: 1 addition & 0 deletions cpp/private/cpp_wasm_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Example usage:
# Run with: wasmtime run bazel-bin/examples/hello.wasm
"""

load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//providers:providers.bzl", "WasmComponentInfo")
load("//rust:transitions.bzl", "wasm_transition")
load("//tools/bazel_helpers:file_ops_actions.bzl", "setup_cpp_workspace_action")
Expand Down
13 changes: 11 additions & 2 deletions moonbit/private/moonbit_wasm_component.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _moonbit_wasm_component_impl(ctx):

moonbit_toolchain = ctx.toolchains["@rules_moonbit//moonbit:moonbit_toolchain_type"]
moon = moonbit_toolchain.moonbit.moon_executable
moonbit_all_files = moonbit_toolchain.moonbit.all_files

wit_file = ctx.file.wit
srcs = ctx.files.srcs
Expand All @@ -70,6 +71,12 @@ WIT_FILE="$(pwd)/{wit_file}"
OUTPUT="$(pwd)/{output}"
ORIG_DIR="$(pwd)"

# Set MOON_HOME so moon build can find the core library
# MOON path: /path/to/external/moonbit_toolchain/bin/moon
# MOON_HOME: /path/to/external/moonbit_toolchain/.moon
TOOLCHAIN_ROOT=$(dirname $(dirname "$MOON"))
export MOON_HOME="$TOOLCHAIN_ROOT/.moon"

# Create temporary project directory
PROJECT_DIR=$(mktemp -d)
cleanup() {{ rm -rf "$PROJECT_DIR"; }}
Expand All @@ -94,7 +101,7 @@ if [ -d "$STUB_DIR" ]; then
fi

# Step 3: Compile with MoonBit
"$MOON" build --target wasm --release 2>&1 || {{
"$MOON" build --target wasm 2>&1 || {{
echo "MoonBit compilation failed" >&2
exit 1
}}
Expand All @@ -107,7 +114,9 @@ if [ -z "$CORE_WASM" ]; then
fi

# Step 4: Embed WIT metadata
# Use --encoding utf16 for MoonBit string encoding
"$WASM_TOOLS" component embed \\
--encoding utf16 \\
--world {world} \\
"$WIT_FILE" \\
"$CORE_WASM" \\
Expand Down Expand Up @@ -135,7 +144,7 @@ echo "Created component: $OUTPUT"

ctx.actions.run_shell(
command = script,
inputs = [wit_file, wit_bindgen, moon, wasm_tools] + srcs,
inputs = [wit_file, wit_bindgen, moon, wasm_tools] + srcs + moonbit_all_files.to_list(),
outputs = [component_wasm],
mnemonic = "MoonbitWasmComponent",
progress_message = "Building MoonBit WASM component %s" % ctx.label,
Expand Down
1 change: 1 addition & 0 deletions rust/private/rust_wasm_component_bindgen.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Rust WASM component with WIT bindgen integration"""

load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_rust//rust:defs.bzl", "rust_common", "rust_library")
load("//wit:defs.bzl", "symmetric_wit_bindgen", "wit_bindgen")
load("//toolchains:tool_versions.bzl", "get_tool_version")
Expand Down
1 change: 1 addition & 0 deletions test/cpp/cpp_component_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This module provides comprehensive testing for WASI SDK + clang integration:
"""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_wasm_component//providers:providers.bzl", "WasmComponentInfo")

def _cpp_component_analysis_test_impl(ctx):
Expand Down
4 changes: 3 additions & 1 deletion toolchains/wasi_sdk_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ alias(
# Create cc_toolchain_config.bzl with proper path resolution
cc_config_content = '''
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
)
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")

def _wasm_cc_toolchain_config_impl(ctx):
"""C++ toolchain config for WASM using WASI SDK"""
Expand Down
4 changes: 3 additions & 1 deletion toolchains/wasm_cc_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Minimal C++ toolchain for WASM builds"""

load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
"env_entry",
"env_set",
"feature",
"flag_group",
"flag_set",
"tool_path",
)
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")

def _wasm_cc_toolchain_config_impl(ctx):
"""C++ toolchain config for WASM using WASI SDK"""
Expand Down
Loading