Skip to content

Commit

Permalink
WIP makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
maximmaxim345 committed Nov 12, 2024
1 parent c3bef34 commit 2279fb9
Showing 1 changed file with 235 additions and 0 deletions.
235 changes: 235 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true

[tasks.verify-strict]
description = "Run all verification tasks with strict warning settings"
workspace = false
dependencies = [
"run-tests",
"lint-strict",
"docs-strict",
"spell-check",
"verify-doc-tests",
"verify-formatting",
]

[tasks.verify]
description = "Run all verification tasks"
workspace = false
dependencies = [
"run-tests",
"lint",
"docs",
"spell-check",
"verify-doc-tests",
"verify-formatting",
]

[tasks.run-tests]
description = "Run tests using nextest runner for better performance"
command = "cargo"
workspace = false
args = ["nextest", "run", "--workspace", "--all-features"]
install_crate = "cargo-nextest"

[tasks.lint]
workspace = false
command = "cargo"
args = ["clippy", "--workspace", "--tests", "--benches", "--all-features"]

[tasks.docs]
workspace = false
command = "cargo"
args = ["doc", "--workspace", "--no-deps", "--all-features"]

[tasks.spell-check]
workspace = false
command = "typos"
install_crate = "typos-cli"

[tasks.verify-doc-tests]
workspace = false
command = "cargo"
args = ["test", "--workspace", "--doc", "--all-features"]

[tasks.verify-formatting]
workspace = false
command = "cargo"
args = ["fmt", "--check", "--all"]

[tasks.lint-strict]
description = "Run Clippy with warnings treated as errors"
workspace = false
command = "cargo"
args = [
"clippy",
"--workspace",
"--tests",
"--benches",
"--all-features",
"--",
"-D",
"warnings",
]

[tasks.docs-strict]
description = "Generate documentation with warnings treated as errors"
workspace = false
command = "cargo"
env = { "RUSTDOCFLAGS" = "--deny warnings" }
args = ["doc", "--workspace", "--no-deps", "--all-features"]

[tasks.get-wasm-cxxlib]
script_runner = "@rust"
workspace = false
script = '''
//! ```cargo
//! [dependencies]
//! ureq = "2"
//! zip = "2"
//! ```
fn main() -> Result<(), Box<dyn std::error::Error>> {
let target_dir = "target/wasm-libcxx";
// Check if library already exists
if std::path::Path::new(target_dir).exists() {
return Ok(());
}
let url = "https://github.com/maximmaxim345/wasm32-unknown-unknown-libcxx/releases/latest/download/wasm32-unknown-unknown-libcxx.zip";
std::fs::create_dir_all(target_dir)?;
println!("Downloading libcxx...");
let response = ureq::get(url).call()?;
let mut content = Vec::new();
response.into_reader().read_to_end(&mut content)?;
println!("Extracting archive to {}...", target_dir);
let reader = std::io::Cursor::new(content);
let mut archive = zip::ZipArchive::new(reader)?;
archive.extract(target_dir)?;
println!("WASM library successfully installed in {}", target_dir);
Ok(())
}
'''

[tasks.ensure-wasm-target]
script_runner = "@rust"
workspace = false
script = '''
fn main() -> Result<(), Box<dyn std::error::Error>> {
let installed_targets = String::from_utf8(
std::process::Command::new("rustup")
.args(["+nightly", "target", "list", "--installed"])
.output()?
.stdout,
)?;
if !installed_targets.contains("wasm32-unknown-unknown") {
println!("Installing wasm32-unknown-unknown target for nightly...");
let status = std::process::Command::new("rustup")
.args(["+nightly", "target", "add", "wasm32-unknown-unknown"])
.status()?;
if !status.success() {
return Err("Failed to install wasm32-unknown-unknown target".into());
}
}
Ok(())
}
'''

[tasks.setup-wasm]
description = "Setup WASM build environment"
workspace = false
dependencies = ["ensure-wasm-target", "get-wasm-cxxlib"]

[tasks.build-wasm-dev]
description = "Build WASM target (development)"
workspace = false
dependencies = ["setup-wasm"]
script_runner = "@shell"
script = '''
source target/wasm-libcxx/wasm32-unknown-unknown-libcxx/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
cd crates/cadara
rustup run nightly wasm-pack build --target web --no-typescript --dev
'''
install_crate = "wasm-pack"

[tasks.build-wasm-debug]
description = "Build WASM target (with debug info)"
workspace = false
dependencies = ["build-wasm-dev"]
script_runner = "@shell"
script = '''
source target/wasm-libcxx/wasm32-unknown-unknown-libcxx/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
cd crates/cadara
wasm-bindgen target/wasm32-unknown-unknown/debug/cadara_lib.wasm --out-dir crates/cadara/pkg --target web --keep-debug
'''
install_crate = "wasm-bindgen-cli"

[tasks.build-wasm-release]
description = "Build WASM target (release)"
workspace = false
dependencies = ["setup-wasm"]
script_runner = "@shell"
script = '''
source target/wasm-libcxx/wasm32-unknown-unknown-libcxx/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
cd crates/cadara
rustup run nightly wasm-pack build --target web --no-typescript
'''
install_crate = "wasm-pack"

[tasks.serve]
description = "Serve the WASM application"
workspace = false
install_crate = "simple-http-server"
command = "simple-http-server"
args = ["-i", "-p", "8080", "-c=wasm", "crates/cadara"]

[tasks.dev]
description = "Serve development build"
workspace = false
dependencies = ["build-wasm-dev", "serve"]

[tasks.debug]
description = "Serve debug build"
workspace = false
dependencies = ["build-wasm-debug", "serve"]

[tasks.release]
description = "Serve release build"
workspace = false
dependencies = ["build-wasm-release", "serve"]

[tasks.help]
description = "Display help information about available tasks"
workspace = false
script_runner = "@rust"
script = '''
println!("Available tasks:");
println!("\nVerification Tasks:");
println!(" verify - Run all standard verification tasks");
println!(" verify-strict - Run all verification tasks with strict warning settings");
println!("\nWASM Build Tasks:");
println!(" build-wasm-dev - Build WASM target (development version)");
println!(" build-wasm-debug - Build WASM target (with debug information)");
println!(" build-wasm-release - Build WASM target (release version)");
println!(" (this will automatically setup a wasm build environment)");
println!("\nServer Tasks:");
println!(" dev - Build development version and serve it");
println!(" debug - Build debug version and serve it");
println!(" release - Build release version and serve it");
println!("\nUsage:");
println!(" cargo make <task-name>");
println!("\nExample:");
println!(" cargo make verify");
println!(" cargo make dev");
'''

0 comments on commit 2279fb9

Please sign in to comment.