Skip to content

Commit 5afb01a

Browse files
authored
Merge pull request #4 from mikkelhegn/main
Add clap comments, add additional derives to bindings
2 parents 9332786 + d57078a commit 5afb01a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ anyhow = "1.0.87"
88
clap = { version = "4.5.17", features = ["derive"] }
99
dialoguer = "0.11.0"
1010
reqwest = "0.12.7"
11+
serde = { version = "1.0", features = ["derive"] }
12+
serde_json = "1"
1113
sha2 = "0.10.8"
1214
spin-manifest = { git = "https://github.com/fermyon/spin" }
1315
spin-serde = { git = "https://github.com/fermyon/spin" }

src/commands/bindings.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ pub enum BindingsLanguage {
1414

1515
#[derive(Args, Debug)]
1616
pub struct GenerateBindingsCommand {
17+
/// The programming language to generate bindings in
1718
#[clap(short = 'L', long)]
1819
pub language: BindingsLanguage,
20+
21+
/// Output directory
1922
#[clap(short = 'o', long)]
2023
pub output: PathBuf,
24+
25+
/// Id of the component, which dependencies to generate the bindings for
2126
#[clap(short = 'c', long)]
2227
pub component_id: String,
2328
}
@@ -40,8 +45,18 @@ impl GenerateBindingsCommand {
4045

4146
match &self.language {
4247
BindingsLanguage::Rust => {
48+
// TODO: If wit-bindgen is not in Cargo.toml, make sure to add it.
4349
let opts = wit_bindgen_rust::Opts {
4450
generate_all: true,
51+
// TODO: Make the extra attributes a clap option
52+
additional_derive_attributes: vec![
53+
"serde::Serialize".to_string(),
54+
"serde::Deserialize".to_string(),
55+
"Hash".to_string(),
56+
"Clone".to_string(),
57+
"PartialEq".to_string(),
58+
"Eq".to_string(),
59+
],
4560
// Uncomment this once spin-sdk is updated and remove dependency on wit_bindgen in Cargo.toml
4661
//runtime_path: Some("::spin_sdk::wit_bindgen".to_string()),
4762
..Default::default()
@@ -65,6 +80,7 @@ impl GenerateBindingsCommand {
6580
}
6681

6782
fs::write(self.output.join("mod.rs"), mod_output).await?;
83+
println!("Bindings generated for Rust in {0}. You need to add the `wit-bindgen` crate to your Rust Spin app - e.g., `cargo add wit-bindgen`", self.output.to_str().expect("Failed to parse output path"));
6884
}
6985
BindingsLanguage::Ts => {
7086
todo!("generate ts")

0 commit comments

Comments
 (0)