* xtask: Implement a new build system xtask is a cargo alias that is used to extend the cargo build system with custom commands. For an introduction to xtask, see here: https://github.com/matklad/cargo-xtask/ The idea is that instead of writing makefiles, xtask requires no additional dependencies except `cargo` and `rustc`, which must be available to build the project anyway. This commit provides a basic implementation of the `build` and `test` subcommands. * xtask/deps: Add 'which' * xtask/test: Handle error when cargo not found * xtask/flags: Add more commands to perform different useful tasks. Includes: - clippy - format - "make" (composite) - "install" (composite) Also add more options to `build` to selectively compile plugins or leave them out entirely. * xtask/main: Return error when cargo not found * xtask/build: Add more subtasks - `wasm_opt_plugins` and - `manpage` that perform other build commands. Add thorough documentation on what each of these does and also handle the new `build` cli flags appropriately. * xtask/clippy: Add job to run clippy * xtask/format: Add job to run rustfmt * xtask/pipeline: Add composite commands that perform multiple atomic xtask commands sequentially in a pipeline sort of fashion. * xtask/deps: Pin dependencies * xtask/main: Integrate new jobs and add documentation. * xtask: Implement 'dist' which performs an 'install' and copies the resulting zellij binary along with some other assets to a `target/dist` folder. * cargo: Update xflags version * xtask: Measure task time, update tty title * xtask: Update various tasks * xtask: wasm-opt plugins in release builds automatically. * xtask/build: Copy debug plugins to assets folder * xtask: Add 'run' subcommand * xtask: Add arbitrary args to test and run * xtask: Rearrange CLI commands in help * xtask: Add deprecation notice * docs: Replace `cargo make` with `xtask` * github: Use `xtask` in workflows. * xtask: Add support for CI commands * xtask: Streamline error handling * github: Use new xtask commands in CI * xtask: Add 'publish' job * xtask/publish: Add retry when publish fails * xtask: Apply rustfmt * xtask: Refine 'make' deprecation warning * xtask: add task to build manpage * contributing: Fix e2e commands * xtask/run: Add missing `--` to pass all arguments following `xtask run` directly to the zellij binary being run. * xtask: Stay in invocation dir and make all tasks that need it change to the project root dir themselves. * xtask/run: Add `--data-dir` flag which will allow very quick iterations when not changing the plugins between builds. * xtask/ci: Install dependencies without asking * utils: Allow including plugins from target folder * utils/assets: Reduce asset map complexity * utils/consts: Update asset map docs * xtask: Fix plugin includes * xtask/test: Build plugins first because the zellij binary needs to include the plugins. * xtask/test: Fix formatting * xtask: Add notice on how to disable it
66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
use crate::{build, flags};
|
|
use anyhow::{anyhow, Context};
|
|
use std::path::Path;
|
|
use xshell::{cmd, Shell};
|
|
|
|
pub fn test(sh: &Shell, flags: flags::Test) -> anyhow::Result<()> {
|
|
let err_context = "failed to run task 'test'";
|
|
|
|
let _pdo = sh.push_dir(crate::project_root());
|
|
let cargo = crate::cargo().context(err_context)?;
|
|
let host_triple = host_target_triple(sh).context(err_context)?;
|
|
|
|
build::build(
|
|
sh,
|
|
flags::Build {
|
|
release: false,
|
|
no_plugins: false,
|
|
plugins_only: true,
|
|
},
|
|
)
|
|
.context(err_context)?;
|
|
|
|
for subcrate in crate::WORKSPACE_MEMBERS.iter() {
|
|
let _pd = sh.push_dir(Path::new(subcrate));
|
|
// Tell the user where we are now
|
|
println!("");
|
|
let msg = format!(">> Testing '{}'", subcrate);
|
|
crate::status(&msg);
|
|
println!("{}", msg);
|
|
|
|
cmd!(sh, "{cargo} test --target {host_triple} --")
|
|
.args(&flags.args)
|
|
.run()
|
|
.with_context(|| format!("Failed to run tests for '{}'", subcrate))?;
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
// Determine the target triple of the host. We explicitly run all tests against the host
|
|
// architecture so we can test the plugins, too (they default to wasm32-wasi otherwise).
|
|
pub fn host_target_triple(sh: &Shell) -> anyhow::Result<String> {
|
|
let rustc_ver = cmd!(sh, "rustc -vV")
|
|
.read()
|
|
.context("Failed to determine host triple")?;
|
|
let maybe_triple = rustc_ver
|
|
.lines()
|
|
.filter_map(|line| {
|
|
if !line.starts_with("host") {
|
|
return None;
|
|
}
|
|
if let Some((_, triple)) = line.split_once(": ") {
|
|
return Some(triple.to_string());
|
|
} else {
|
|
return None;
|
|
}
|
|
})
|
|
.collect::<Vec<String>>();
|
|
match maybe_triple.len() {
|
|
0 => Err(anyhow!("rustc didn't output the 'host' triple")),
|
|
1 => Ok(maybe_triple.into_iter().next().unwrap()),
|
|
_ => Err(anyhow!(
|
|
"rustc provided multiple host triples: {:?}",
|
|
maybe_triple
|
|
)),
|
|
}
|
|
}
|