Skip to content

Commit

Permalink
Run Clippy first and share profile (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser authored Oct 11, 2023
1 parent 1168b61 commit 8f5026f
Showing 1 changed file with 33 additions and 43 deletions.
76 changes: 33 additions & 43 deletions crates/cli/src/tasks/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,33 @@ use anyhow::Context;
use cargo_metadata::Message;
use duct::cmd;

pub(crate) fn build_rust(project_path: &Path, skip_clippy: bool, build_debug: bool) -> anyhow::Result<PathBuf> {
// Make sure that we have the wasm target installed (ok to run if its already installed)
cmd!("rustup", "target", "add", "wasm32-unknown-unknown").run()?;
let reader = if build_debug {
cmd!(
"cargo",
"--config=net.git-fetch-with-cli=true",
"build",
"--target=wasm32-unknown-unknown",
"--message-format=json-render-diagnostics"
)
} else {
cmd!(
"cargo",
fn cargo_cmd(subcommand: &str, build_debug: bool, args: &[&str]) -> duct::Expression {
duct::cmd(
"cargo",
[
subcommand,
"--config=net.git-fetch-with-cli=true",
"build",
"--target=wasm32-unknown-unknown",
"--release",
"--message-format=json-render-diagnostics"
)
}
.dir(project_path)
.reader()?;
]
.into_iter()
.chain((!build_debug).then_some("--release"))
.chain(args.iter().copied()),
)
}

let mut artifact = None;
for message in Message::parse_stream(io::BufReader::new(reader)) {
match message {
Ok(Message::CompilerArtifact(art)) => artifact = Some(art),
Err(error) => return Err(anyhow::anyhow!(error)),
_ => {}
}
}
let artifact = artifact.context("no artifact found?")?;
let artifact = artifact.filenames.into_iter().next().context("no wasm?")?;
pub(crate) fn build_rust(project_path: &Path, skip_clippy: bool, build_debug: bool) -> anyhow::Result<PathBuf> {
// Make sure that we have the wasm target installed (ok to run if its already installed)
cmd!("rustup", "target", "add", "wasm32-unknown-unknown").run()?;

// Note: Clippy has to run first so that it can build & cache deps for actual build while checking in parallel.
if !skip_clippy {
let clippy_conf_dir = tempfile::tempdir()?;
fs::write(clippy_conf_dir.path().join("clippy.toml"), CLIPPY_TOML)?;
println!("checking crate with spacetimedb's clippy configuration");
// TODO: should we pass --no-deps here? leaving it out could be valuable if a module is split
// into multiple crates, but without it it lints on proc-macro crates too
let out = cmd!(
"cargo",
"--config=net.git-fetch-with-cli=true",
let out = cargo_cmd(
"clippy",
"--target=wasm32-unknown-unknown",
// TODO: pass -q? otherwise it might be too busy
// "-q",
"--",
"--no-deps",
"-Aclippy::all",
"-Dclippy::disallowed-macros"
build_debug,
&["--", "--no-deps", "-Aclippy::all", "-Dclippy::disallowed-macros"],
)
.dir(project_path)
.env("CLIPPY_DISABLE_DOCS_LINKS", "1")
Expand All @@ -66,6 +41,21 @@ pub(crate) fn build_rust(project_path: &Path, skip_clippy: bool, build_debug: bo
anyhow::ensure!(out.status.success(), "clippy found a lint error");
}

let reader = cargo_cmd("build", build_debug, &["--message-format=json-render-diagnostics"])
.dir(project_path)
.reader()?;

let mut artifact = None;
for message in Message::parse_stream(io::BufReader::new(reader)) {
match message {
Ok(Message::CompilerArtifact(art)) => artifact = Some(art),
Err(error) => return Err(anyhow::anyhow!(error)),
_ => {}
}
}
let artifact = artifact.context("no artifact found?")?;
let artifact = artifact.filenames.into_iter().next().context("no wasm?")?;

check_for_wasm_bindgen(artifact.as_ref())?;

Ok(artifact.into())
Expand Down

0 comments on commit 8f5026f

Please sign in to comment.