Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo Fmt on Generated Rust Files #79

Merged
merged 2 commits into from
Jul 13, 2023
Merged
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
24 changes: 23 additions & 1 deletion crates/cli/src/subcommands/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use clap::Arg;
use clap::ArgAction::SetTrue;
use convert_case::{Case, Casing};
use duct::cmd;
use spacetimedb_lib::sats::{AlgebraicType, Typespace};
use spacetimedb_lib::{bsatn, MiscModuleExport, ModuleDef, ReducerDef, TableDef, TypeAlias};
use wasmtime::{AsContext, Caller, ExternType};
Expand Down Expand Up @@ -110,10 +111,15 @@ Failed to compile module {:?}. See cargo errors above for more details.",
));
}

let mut paths = vec![];
for (fname, code) in generate(&wasm_file, lang, namespace.as_str())?.into_iter() {
fs::write(out_dir.join(fname), code)?;
let path = out_dir.join(fname);
paths.push(path.clone());
fs::write(path, code)?;
}

format_files(paths, lang)?;

println!("Generate finished successfully.");
Ok(())
}
Expand Down Expand Up @@ -433,3 +439,19 @@ impl Memory {
.get(..len as usize)
}
}

fn format_files(generated_files: Vec<PathBuf>, lang: Language) -> anyhow::Result<()> {
match lang {
Language::Rust => {
cmd!("rustup", "component", "add", "rustfmt").run()?;
for path in generated_files {
cmd!("rustfmt", path.to_str().unwrap()).run()?;
}
}
Language::Csharp => {}
Language::TypeScript => {}
Language::Python => {}
}

Ok(())
}