Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xtask #2688

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Xtask #2688

Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
2 changes: 1 addition & 1 deletion .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
using: composite
steps:
- name: Install mdbook
run: ./install-mdbook.sh
run: cargo xtask install-tools
shell: bash

- name: Install dependencies for mdbook-pandoc
Expand Down
6 changes: 5 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ members = [
"src/unsafe-rust",
"src/user-defined-types",
"third_party/cxx/blobstore",
"xtask",
]
resolver = "2"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cd comprehensive-rust
Then install these tools with:

```shell
bash install-mdbook.sh
cargo xtask install-tools
```

Run
Expand Down
11 changes: 0 additions & 11 deletions install-mdbook.sh

This file was deleted.

6 changes: 6 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"

[dependencies]
70 changes: 70 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::{env, process::Command};

type DynError = Box<dyn std::error::Error>;

fn main() {
if let Err(e) = execute_task() {
eprintln!("{e}");
std::process::exit(-1);
}
}

fn execute_task() -> Result<(), DynError> {
let task = env::args().nth(1);
match task.as_deref() {
Some("install-tools") => install_tools()?,
_ => print_help(task.as_deref()),
}
Ok(())
}

fn install_tools() -> Result<(), DynError> {
println!("Installing project tools...");
// The --locked flag is important for reproducible builds. It also
// avoids breakage due to skews between mdbook and mdbook-svgbob.
Command::new(env!("CARGO"))
.arg("install")
.args(["mdbook", "--locked", "--version", "0.4.44"])
.status()?;
Command::new(env!("CARGO"))
.arg("install")
.args(["mdbook-svgbob", "--locked", "--version", "0.2.1"])
.status()?;
Command::new(env!("CARGO"))
.arg("install")
.args(["mdbook-pandoc", "--locked", "--version", "0.9.3"])
.status()?;
Command::new(env!("CARGO"))
.arg("install")
.args(["mdbook-i18n-helpers", "--locked", "--version", "0.3.5"])
.status()?;
Command::new(env!("CARGO"))
.arg("install")
.args(["i18n-report", "--locked", "--version", "0.2.0"])
.status()?;
// These packages are located in this repository
Command::new(env!("CARGO"))
.arg("install")
.args(["--path", "mdbook-exerciser", "--locked"])
.status()?;
Command::new(env!("CARGO"))
.arg("install")
.args(["--path", "mdbook-course", "--locked"])
.status()?;
Ok(())
}

fn print_help(task: Option<&str>) {
if let Some(t) = task {
eprintln!(
"Unrecognized task '{t}'. Available tasks:

install-tools Installs the tools the project dependends on.

Check warning on line 62 in xtask/src/main.rs

View workflow job for this annotation

GitHub Actions / typos

"dependends" should be "depended".

Run with `cargo xtask [task]`.
"
);
} else {
eprintln!("Missing task. To execute a task run `cargo xtask [task]`.");
}
}
Loading