-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use xtask for various project tasks (#136)
- Loading branch information
1 parent
0217b8e
commit eb9bc4c
Showing
5 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[target.aarch64-unknown-linux-gnu] | ||
linker = "/usr/bin/aarch64-linux-gnu-gcc" | ||
|
||
[alias] | ||
xtask = "run --package xtask --" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "xtask" | ||
edition = "2021" | ||
version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
use std::{ | ||
error::Error, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
fn workspace_dir() -> PathBuf { | ||
let output = std::process::Command::new(env!("CARGO")) | ||
.arg("locate-project") | ||
.arg("--workspace") | ||
.arg("--message-format=plain") | ||
.output() | ||
.unwrap() | ||
.stdout; | ||
let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim()); | ||
cargo_path.parent().unwrap().to_path_buf() | ||
} | ||
|
||
// Generate documentation by invoking the docs script! | ||
fn generate_docs() -> Result<(), Box<dyn Error>> { | ||
println!("Generating docs..."); | ||
|
||
let mut workspace_dir = workspace_dir(); | ||
|
||
let mut base = workspace_dir.clone(); | ||
|
||
workspace_dir.push("crates"); | ||
workspace_dir.push("steel-doc"); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("run") | ||
.current_dir(&workspace_dir) | ||
.spawn()? | ||
.wait()?; | ||
|
||
workspace_dir.pop(); | ||
workspace_dir.pop(); | ||
|
||
workspace_dir.push("docs"); | ||
workspace_dir.push("src"); | ||
workspace_dir.push("builtins"); | ||
|
||
println!("Cleaning target directory..."); | ||
|
||
std::fs::remove_dir_all(&workspace_dir)?; | ||
|
||
base.push("crates"); | ||
base.push("steel-doc"); | ||
base.push("generated"); | ||
|
||
println!("Moving generated docs into place..."); | ||
|
||
std::fs::rename(base, &workspace_dir)?; | ||
|
||
println!("Done!"); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn install_everything() -> Result<(), Box<dyn Error>> { | ||
println!("Installing `steel`..."); | ||
|
||
let mut workspace_dir = workspace_dir(); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("install") | ||
.arg("--path") | ||
.arg(".") | ||
.arg("--force") | ||
.spawn()? | ||
.wait()?; | ||
|
||
println!("Successfully installed `steel`"); | ||
|
||
println!("Installing `steel-language-server`"); | ||
|
||
workspace_dir.push("crates"); | ||
workspace_dir.push("steel-language-server"); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("install") | ||
.arg("--path") | ||
.arg(&workspace_dir) | ||
.spawn()? | ||
.wait()?; | ||
|
||
println!("Successfully installed `steel-language-server`"); | ||
|
||
workspace_dir.pop(); | ||
|
||
workspace_dir.push("cargo-steel-lib"); | ||
|
||
println!("Installing `cargo-steel-lib`"); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("install") | ||
.arg("--path") | ||
.arg(&workspace_dir) | ||
.spawn()? | ||
.wait()?; | ||
|
||
println!("Successfully installed `cargo-steel-lib`"); | ||
|
||
println!("Installing all dylibs"); | ||
|
||
let dylibs = &[ | ||
"steel-sys-info", | ||
"steel-websockets", | ||
"steel-webrequests", | ||
"steel-webserver", | ||
]; | ||
|
||
workspace_dir.pop(); | ||
|
||
// Could build in parallel, but we can do sequentially for now | ||
for dylib in dylibs { | ||
workspace_dir.push(dylib); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("steel-lib") | ||
.current_dir(&workspace_dir) | ||
.spawn()? | ||
.wait()?; | ||
|
||
workspace_dir.pop(); | ||
} | ||
|
||
println!("Finished."); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn install_cogs() -> Result<(), Box<dyn Error>> { | ||
let mut workspace_dir = workspace_dir(); | ||
workspace_dir.push("cogs"); | ||
|
||
std::process::Command::new("cargo") | ||
.arg("run") | ||
.arg("--") | ||
.arg("install.scm") | ||
.current_dir(workspace_dir) | ||
.spawn()? | ||
.wait()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn run_tests() -> Result<(), Box<dyn Error>> { | ||
std::process::Command::new("cargo") | ||
.arg("test") | ||
.arg("--all") | ||
.spawn()? | ||
.wait()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let task = std::env::args().nth(1); | ||
match task { | ||
None => {} | ||
Some(t) => match t.as_str() { | ||
"install" => install_everything()?, | ||
"cogs" => install_cogs()?, | ||
"docgen" => generate_docs()?, | ||
"test" => run_tests()?, | ||
invalid => return Err(format!("Invalid task name: {}", invalid).into()), | ||
}, | ||
}; | ||
Ok(()) | ||
} |