Skip to content

Commit

Permalink
Iterate workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Nov 30, 2023
1 parent db2eaff commit 4f5fa68
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ license = "MIT OR Apache-2.0"
[dependencies]
anyhow = "1.0.75"
clap = { version = "4.4.8", features = ["derive"] }
serde_json = { version = "1" }
73 changes: 56 additions & 17 deletions xtask/src/runchecks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::process::{Child, Command, Stdio};
use std::str;
use std::time::Instant;

use serde_json::Value;

// Targets constants
const WASM32_TARGET: &str = "wasm32-unknown-unknown";
const ARM_TARGET: &str = "thumbv7m-none-eabi";
Expand Down Expand Up @@ -43,6 +45,38 @@ fn run_command(command: &str, args: &[&str], command_error: &str, child_error: &
handle_child_process(command, child_error);
}

// Get the workspaces available
fn get_workspaces() -> Vec<String> {
// Run `cargo metadata` command to get project metadata
let output = Command::new("cargo")
.arg("metadata")
.output()
.expect("Failed to execute command");

// Parse the JSON output
let metadata: Value = serde_json::from_slice(&output.stdout).expect("Failed to parse JSON");

// Extract workspaces from the metadata, excluding examples/ and xtask
let workspaces = metadata["workspace_members"]
.as_array()
.expect("Expected an array of workspace members")
.iter()
.filter_map(|member| {
let mut parts = member.as_str()?.split_whitespace();
let workspace_name = parts.next()?.to_string();
let workspace_path = parts.last()?.to_string();

if !workspace_path.contains("examples/") && workspace_name != "xtask" {
Some(workspace_name)
} else {
None
}
})
.collect();

workspaces
}

// Start section print in CI
fn start_group(title: String) {
if std::env::var("CI").is_ok() {
Expand Down Expand Up @@ -121,17 +155,18 @@ fn cargo_test(params: Params) {

// Run cargo fmt command
fn cargo_fmt() {
// Run cargo fmt
start_group("cargo: fmt".to_string());
run_cargo(
"fmt",
["--check", "--all", "--", "--color=always"].into(),
"Failed to run cargo fmt",
);
end_group();
}

// Run cargo clippy command
fn cargo_clippy() {
if std::env::var("CI_RUN").is_ok() {
if std::env::var("CI").is_ok() {
return;
}
// Run cargo clippy
Expand Down Expand Up @@ -220,8 +255,6 @@ fn run_grcov() {

// Run no_std checks
fn no_std_checks() {
println!("Checks for no_std environment...\n\n");

// Install wasm32 target
rustup("target", WASM32_TARGET);

Expand All @@ -243,8 +276,6 @@ fn no_std_checks() {

// Test burn-core with tch and wgpu backend
fn burn_core_std() {
println!("\n\nRun checks for burn-core crate with tch and wgpu backend");

// Run cargo test --features test-tch
start_group("Test: burn-core (tch)".to_string());
cargo_test(["-p", "burn-core", "--features", "test-tch"].into());
Expand Down Expand Up @@ -292,22 +323,24 @@ fn std_checks() {
let is_coverage = std::env::var("COVERAGE").is_ok();
let disable_wgpu = std::env::var("DISABLE_WGPU").is_ok();

println!("Running std checks");

// Check format
cargo_fmt();

// Check clippy lints
cargo_clippy();

// Build each workspace
start_group("Build: workspaces".to_string());
if disable_wgpu {
cargo_build(["--workspace", "--exclude=xtask", "--exclude=burn-wgpu"].into());
} else {
cargo_build(["--workspace", "--exclude=xtask"].into());
let workspaces = get_workspaces();
println!("Workspaces: {:?}", workspaces);
for workspace in workspaces.clone() {
if disable_wgpu && workspace == "burn-wgpu" {
continue;
}

start_group(format!("Build: {}", workspace));
cargo_build(Params::from(["-p", &workspace]));
end_group()
}
end_group();

// Produce documentation for each workspace
start_group("Docs: workspaces".to_string());
Expand All @@ -320,9 +353,15 @@ fn std_checks() {
}

// Test each workspace
start_group("Test: workspaces".to_string());
cargo_test(["--workspace"].into());
end_group();
for workspace in workspaces {
if disable_wgpu && workspace == "burn-wgpu" {
continue;
}

start_group(format!("Test: {}", workspace));
cargo_test(Params::from(["-p", &workspace]));
end_group();
}

// Test burn-candle with accelerate (macOS only)
#[cfg(target_os = "macos")]
Expand Down

0 comments on commit 4f5fa68

Please sign in to comment.