Skip to content

export\! macro not accessible in rust_wasm_component_bindgen #1

@avrabe

Description

@avrabe

Summary

The export\! macro generated by rust_wasm_component_bindgen is not accessible from user code due to visibility restrictions.

Problem Details

  1. Generated wrapper creates export\! macro as pub(crate):
// In generated wrapper at line 148:
pub(crate) use __export_camera_front_impl as export;
  1. User code cannot access it:
// Error: macro `export` is private
camera_front_ecu_bindings::export\!(Component);
  1. Compilation error:
error[E0603]: macro `export` is private
  --> components/sensors/camera-front/src/lib.rs:17:28

Root Cause

The wrapper file at /rust/rust_wasm_component_bindgen.bzl generates the export macro with pub(crate) visibility, but the bindings are compiled as a separate crate, making the macro inaccessible from user code.

Suggested Fix

In the wrapper generation template, change:

pub(crate) use __export_camera_front_impl as export;

to:

pub use __export_camera_front_impl as export;

Steps to Reproduce

  1. Create a WIT file with a world definition:
package example:component;

world my-world {
    export process: func() -> string;
}
  1. Use rust_wasm_component_bindgen in BUILD.bazel:
rust_wasm_component_bindgen(
    name = "my_component",
    srcs = ["src/lib.rs"],
    wit = ":my_interfaces",
)
  1. Try to use the export macro in src/lib.rs:
use my_component_bindings::{Guest, export};

struct Component;

impl Guest for Component {
    fn process() -> String {
        "Hello".to_string()
    }
}

export\!(Component);
  1. Build fails with error[E0603]: macro export is private

Impact

This blocks migration of projects using the new rust_wasm_component_bindgen API, as there's no way to export the component implementation.

Environment

  • Bazel 8.3.1
  • rules_wasm_component commit: 125a46f
  • Platform: macOS ARM64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions