Skip to content

Commit

Permalink
perf(xtask): ⚡️ remove rebundant cargo check from build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Feb 11, 2024
1 parent 2bfab4f commit 71f1dba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@ anyhow = "1.0.79"
clap = { version = "4.5.0", features = ["derive"] }
clap_complete = "4.5.0"
clap_mangen = "0.2.20"

[profile.release]
codegen-units = 1
lto = true
strip = true
2 changes: 0 additions & 2 deletions xtask/src/dist/deb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub(crate) fn deb_package(sh: Shell) -> anyhow::Result<()> {

use crate::dist::prepare_out_dir;

cmd!(sh, "cargo build --release").run()?;

prepare_out_dir(&sh)?;

cmd!(sh, "cargo deb -v").run()?;
Expand Down
12 changes: 8 additions & 4 deletions xtask/src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ impl Profile {
}
}

/// Get the `OUT_DIR` directory path of a specified build profile. This will run `cargo build` under the hood.
// TODO: This function should be run only once during CI build process.
pub(crate) fn build_script_out_dir(sh: &Shell, profile: Profile) -> anyhow::Result<PathBuf> {
let pkgid = cmd!(sh, "cargo pkgid").read()?;
let pkgid: Vec<_> = pkgid.split("#").collect();
// dbg!(&pkgid);
let pkgid = pkgid
.split_once("#")
.expect(&format!("Unexpected pkgid: {:?}", pkgid));

let flag = profile.flag();

cmd!(sh, "cargo check {flag...} --message-format=json")
cmd!(sh, "cargo build --locked {flag...} --message-format=json")
.read()?
.lines()
.find_map(|line| {
Expand All @@ -49,7 +53,7 @@ pub(crate) fn build_script_out_dir(sh: &Shell, profile: Profile) -> anyhow::Resu
CargoCheckMessage::BuildScriptExecuted {
package_id,
out_dir,
} if package_id.contains(pkgid[0]) => Some(out_dir),
} if package_id.contains(pkgid.0) => Some(out_dir),
_ => None,
}
})
Expand Down

0 comments on commit 71f1dba

Please sign in to comment.