Skip to content

Commit f9494f2

Browse files
committed
Move generated files to the generated/ sub-directory
1 parent bc90478 commit f9494f2

File tree

13 files changed

+90
-72
lines changed

13 files changed

+90
-72
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ That means being able to reference WebAssembly components via
113113
same way as Rust crate dependencies:
114114

115115
* add a dependency on a WebAssembly component to `Cargo.toml`
116-
* reference it like you would an external crate (via `bindings::<name>::...`) in
116+
* reference it like you would an external crate (via `generated::<name>::...`) in
117117
your source code
118118
* build using `cargo component build` and out pops your component!
119119

@@ -130,7 +130,7 @@ including Rust.
130130
bindings "inline" with the component's source code.
131131

132132
Unlike `wit-bindgen`, `cargo component` generates bindings directly into your
133-
project at `src/bindings.rs` so that bindings are generated based on the
133+
project at `src/generated/` so that bindings are generated based on the
134134
resolved dependencies from `Cargo.toml` rather than parsing a local definition
135135
of the component's interface.
136136

@@ -214,9 +214,9 @@ The implementation of the component will be in `src/lib.rs`:
214214

215215
```rust
216216
#[allow(warnings)]
217-
mod bindings;
217+
mod generated;
218218

219-
use bindings::Guest;
219+
use generated::Guest;
220220

221221
struct Component;
222222

@@ -227,10 +227,10 @@ impl Guest for Component {
227227
}
228228
}
229229

230-
bindings::export!(Component with_types_in bindings);
230+
generated::export!(Component with_types_in generated);
231231
```
232232

233-
The `bindings` module contains the the types and traits that correspond to the
233+
The `generated` module contains the the types and traits that correspond to the
234234
world targeted by the component; it is automatically generated by
235235
`cargo component`.
236236

example/src/bindings.rs renamed to example/src/generated/component_bindings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT!
1+
// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT!
22
// Options used:
33
#[allow(dead_code)]
44
pub mod example {
@@ -249,7 +249,7 @@ macro_rules! __export_example_impl {
249249
pub(crate) use __export_example_impl as export;
250250

251251
#[cfg(target_arch = "wasm32")]
252-
#[link_section = "component-type:wit-bindgen:0.24.0:example:encoded world"]
252+
#[link_section = "component-type:wit-bindgen:0.25.0:example:encoded world"]
253253
#[doc(hidden)]
254254
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 354] = *b"\
255255
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe4\x01\x01A\x02\x01\
@@ -259,7 +259,7 @@ e\x05\0\x01B\x03\x01p}\x01@\x01\x03urls\0\0\x04\0\x05fetch\x01\x01\x03\x01\x19ex
259259
ample:component/backend\x05\x01\x01B\x03\x01p}\x01@\x01\x03urls\0\0\x04\0\x05fet\
260260
ch\x01\x01\x04\x01\x19example:component/backend\x05\x02\x04\x01\x19example:compo\
261261
nent/example\x04\0\x0b\x0d\x01\0\x07example\x03\0\0\0G\x09producers\x01\x0cproce\
262-
ssed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.24.0";
262+
ssed-by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0";
263263

264264
#[inline(never)]
265265
#[doc(hidden)]

example/src/generated/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Generated by `cargo-component`. DO NOT EDIT!
2+
mod component_bindings;
3+
pub use component_bindings::*;

example/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[allow(warnings)]
2-
mod bindings;
2+
mod generated;
33

4-
use bindings::{
4+
use generated::{
55
example::component::{backend as origin, cache},
66
exports::example::component::backend::Guest,
77
};
@@ -20,4 +20,4 @@ impl Guest for Component {
2020
}
2121
}
2222

23-
bindings::export!(Component with_types_in bindings);
23+
generated::export!(Component with_types_in generated);

src/commands/new.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl NewCommand {
352352
None => {
353353
if self.is_command() {
354354
Ok(r#"#[allow(warnings)]
355-
mod bindings;
355+
mod generated;
356356
357357
fn main() {
358358
println!("Hello, world!");
@@ -361,9 +361,9 @@ fn main() {
361361
.into())
362362
} else {
363363
Ok(r#"#[allow(warnings)]
364-
mod bindings;
364+
mod generated;
365365
366-
use bindings::Guest;
366+
use generated::Guest;
367367
368368
struct Component;
369369
@@ -374,7 +374,7 @@ impl Guest for Component {
374374
}
375375
}
376376
377-
bindings::export!(Component with_types_in bindings);
377+
generated::export!(Component with_types_in generated);
378378
"#
379379
.into())
380380
}

src/generator.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl UseTrie {
178178

179179
self.insert(
180180
[
181-
"bindings",
181+
"generated",
182182
"exports",
183183
pkg.name.namespace.as_str(),
184184
pkg.name.name.as_str(),
@@ -191,7 +191,7 @@ impl UseTrie {
191191
/// Inserts an export trait for the given world key.
192192
fn insert_export_trait(&mut self, resolve: &Resolve, key: &WorldKey) -> Cow<str> {
193193
match key {
194-
WorldKey::Name(name) => self.insert(["bindings", "exports", name.as_str()], "Guest"),
194+
WorldKey::Name(name) => self.insert(["generated", "exports", name.as_str()], "Guest"),
195195
WorldKey::Interface(id) => {
196196
let iface = &resolve.interfaces[*id];
197197
self.insert_interface_type(resolve, iface, "Guest")
@@ -499,7 +499,7 @@ impl<'a> UnimplementedFunction<'a> {
499499
write!(
500500
source,
501501
"{name}",
502-
name = trie.insert(["bindings"], &type_name)
502+
name = trie.insert(["generated"], &type_name)
503503
)
504504
.unwrap();
505505
}
@@ -712,7 +712,7 @@ impl<'a> ImplementationGenerator<'a> {
712712
writeln!(
713713
&mut source,
714714
"\nimpl {name} for {IMPLEMENTER} {{",
715-
name = trie.insert(["bindings"], "Guest")
715+
name = trie.insert(["generated"], "Guest")
716716
)?;
717717

718718
for (i, func) in self.functions.iter().enumerate() {
@@ -767,7 +767,7 @@ impl<'a> SourceGenerator<'a> {
767767
let impls = generator.generate(&mut trie)?;
768768

769769
let mut source = String::new();
770-
writeln!(&mut source, "#[allow(warnings)]\nmod bindings;")?;
770+
writeln!(&mut source, "#[allow(warnings)]\nmod generated;")?;
771771
writeln!(&mut source)?;
772772
write!(
773773
&mut source,
@@ -787,7 +787,7 @@ impl<'a> SourceGenerator<'a> {
787787

788788
writeln!(
789789
&mut source,
790-
"\nbindings::export!({IMPLEMENTER} with_types_in bindings);"
790+
"\ngenerated::export!({IMPLEMENTER} with_types_in generated);"
791791
)?;
792792

793793
if self.format {

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,10 @@ async fn generate_package_bindings(
822822
.manifest_path
823823
.parent()
824824
.unwrap()
825-
.join("src");
826-
let bindings_path = output_dir.join("bindings.rs");
825+
.join("src")
826+
.join("generated");
827+
let bindings_mod_path = output_dir.join("mod.rs");
828+
let bindings_path = output_dir.join("component_bindings.rs");
827829

828830
let last_modified_output = bindings_path
829831
.is_file()
@@ -859,6 +861,19 @@ async fn generate_package_bindings(
859861
)
860862
})?;
861863

864+
fs::write(
865+
&bindings_mod_path,
866+
r#"// Generated by `cargo-component`. DO NOT EDIT!
867+
mod component_bindings;
868+
pub use component_bindings::*;
869+
"#,
870+
)
871+
.with_context(|| {
872+
format!(
873+
"failed to write bindings file `{path}`",
874+
path = bindings_mod_path.display()
875+
)
876+
})?;
862877
fs::write(&bindings_path, bindings).with_context(|| {
863878
format!(
864879
"failed to write bindings file `{path}`",

tests/bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ world generator {
3535
#![feature(test)]
3636
3737
#[allow(warnings)]
38-
mod bindings;
38+
mod generated;
3939
4040
extern crate test;
4141
42-
use bindings::{Guest, Size};
42+
use generated::{Guest, Size};
4343
use test::Bencher;
4444
4545
struct Component;
@@ -58,7 +58,7 @@ impl Guest for Component {
5858
}
5959
}
6060
61-
bindings::export!(Component with_types_in bindings);
61+
generated::export!(Component with_types_in generated);
6262
6363
#[bench]
6464
fn bench_recursive_fibonacci(b: &mut Bencher) {

0 commit comments

Comments
 (0)