Skip to content

Commit 9476144

Browse files
committed
fix: include generation_mode in Rust bindgen output filename
Both guest and native-guest wit_bindgen targets were generating files with the same name (e.g., basic_component.rs), causing Bazel conflicting action errors. Changes: - Add mode_suffix to rust_filename based on generation_mode - Guest mode: no suffix (basic_component.rs) - Native-guest mode: _native_guest suffix (basic_component_native_guest.rs) - Add fallback for world_name when not provided This resolves the build failures: ERROR: file 'test/integration/basic_component.rs' is generated by these conflicting actions: basic_component_wit_bindgen_guest and basic_component_wit_bindgen_native_guest
1 parent c1315d4 commit 9476144

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

wit/wit_bindgen.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,16 @@ def _wit_bindgen_impl(ctx):
4444
if ctx.attr.language == "rust":
4545
# wit-bindgen for Rust generates filename as: world_name.to_snake_case() + ".rs"
4646
# Source: bytecodealliance/wit-bindgen/crates/rust/src/lib.rs - fn finish()
47-
# world_name is now mandatory in wit_library, so this is always predictable
48-
rust_filename = _to_snake_case(wit_info.world_name) + ".rs"
47+
# world_name should be provided for bindgen generation
48+
if wit_info.world_name:
49+
base_filename = _to_snake_case(wit_info.world_name)
50+
else:
51+
# Fallback to target name if world_name not provided
52+
base_filename = ctx.label.name.replace("_wit_bindgen_guest", "").replace("_wit_bindgen_native_guest", "")
53+
54+
# Include generation_mode in filename to avoid conflicts between guest and native-guest
55+
mode_suffix = "_" + ctx.attr.generation_mode.replace("-", "_") if ctx.attr.generation_mode != "guest" else ""
56+
rust_filename = base_filename + mode_suffix + ".rs"
4957
out_file = ctx.actions.declare_file(rust_filename)
5058
elif ctx.attr.language == "c":
5159
# C generates multiple files

0 commit comments

Comments
 (0)