Skip to content

Commit

Permalink
Use xtask for various project tasks (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas authored Jan 16, 2024
1 parent 0217b8e commit eb9bc4c
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
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 --"
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions crates/steel-core/src/steel_vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::values::lists::List;
use log::{debug, log_enabled};
use num::ToPrimitive;
use once_cell::sync::Lazy;
use smallvec::SmallVec;
#[cfg(feature = "profiling")]
use std::time::Instant;

Expand Down Expand Up @@ -297,7 +298,6 @@ thread_local! {
#[derive(Clone)]
pub struct SteelThread {
pub(crate) global_env: Env,
// Maybe a neat idea, what if we used an immutable vector here?
pub(crate) stack: Vec<SteelVal>,
profiler: OpCodeOccurenceProfiler,
function_interner: FunctionInterner,
Expand Down Expand Up @@ -3217,9 +3217,11 @@ impl<'a> VmCore<'a> {
let values = self
.thread
.stack
.split_off(self.thread.stack.len() - amount_to_remove);
.drain(self.thread.stack.len() - amount_to_remove..)
.collect();
// .split_off(self.thread.stack.len() - amount_to_remove);

let list = SteelVal::ListV(List::from(values));
let list = SteelVal::ListV(values);

self.thread.stack.push(list);

Expand Down Expand Up @@ -3385,7 +3387,8 @@ impl<'a> VmCore<'a> {
let args = self
.thread
.stack
.split_off(self.thread.stack.len() - payload_size);
.drain(self.thread.stack.len() - payload_size..)
.collect::<SmallVec<[_; 4]>>();

let result = func(self, &args).map(|x| {
x.map_err(|x| {
Expand Down
8 changes: 8 additions & 0 deletions crates/xtask/Cargo.toml
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]
170 changes: 170 additions & 0 deletions crates/xtask/src/main.rs
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(())
}

0 comments on commit eb9bc4c

Please sign in to comment.