Skip to content

Commit bfdbfdc

Browse files
committed
replaced justfile with xtask
1 parent 183da69 commit bfdbfdc

File tree

10 files changed

+221
-41
lines changed

10 files changed

+221
-41
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[alias]
2+
xtask = "run --package xtask --"
3+
build-test-shader = "xtask test-build"

.github/workflows/push.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
rustup update
3636
- run: cargo test
3737
- name: Run a full build
38-
run: just build-shader-template
38+
run: cargo xtask test-build
3939

4040

4141
lints:
@@ -45,5 +45,7 @@ jobs:
4545
- uses: moonrepo/setup-rust@v1
4646
- uses: extractions/setup-just@v2
4747
- uses: cargo-bins/cargo-binstall@main
48-
- run: just setup-lints
49-
- run: just lints
48+
- run: cargo binstall cargo-shear
49+
- run: cargo clippy -- --deny warnings
50+
- run: cargo fmt --check
51+
- run: cargo shear

Cargo.lock

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
3-
"crates/cargo-gpu",
3+
"crates/cargo-gpu",
4+
"crates/xtask",
45
]
56

67
exclude = [
@@ -30,6 +31,7 @@ relative-path = "1.9.3"
3031
serde = { version = "1.0.214", features = ["derive"] }
3132
serde_json = "1.0.132"
3233
toml = "0.8.19"
34+
tempdir = "0.3.7"
3335
test-log = "0.2.16"
3436

3537
[workspace.lints.rust]

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
allow-unwrap-in-tests = true
22
allow-panic-in-tests = true
3+
allow-shadow-reuse = true

crates/cargo-gpu/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ mod test {
173173
// For some reason running a full build (`build.run()`) inside tests fails on Windows.
174174
// The error is in the `build.rs` step of compiling `spirv-tools-sys`. It is not clear
175175
// from the logged error what the problem is. For now we'll just run a full build
176-
// outside the tests environment, see `justfile`'s `build-shader-template`.
176+
// outside the tests environment, see `xtask`'s `test-build`.
177177
} else {
178178
panic!("was not a build command");
179179
}

crates/xtask/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "xtask"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
anyhow.workspace = true
8+
clap.workspace = true
9+
env_logger.workspace = true
10+
log.workspace = true
11+
tempdir.workspace = true
12+
toml.workspace = true
13+
14+
[lints]
15+
workspace = true

crates/xtask/src/main.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//! Project/repository utilities.
2+
3+
use anyhow::Context;
4+
use clap::Parser;
5+
6+
/// Our xtask commands.
7+
#[derive(Debug, clap::Parser)]
8+
enum Cli {
9+
/// Run a test build of the shader-crate-template project.
10+
TestBuild,
11+
}
12+
13+
fn cmd(args: impl IntoIterator<Item = impl AsRef<str>>) -> anyhow::Result<()> {
14+
let mut args = args.into_iter();
15+
let mut cmd = std::process::Command::new(args.next().context("no args")?.as_ref());
16+
for arg in args {
17+
cmd.arg(arg.as_ref());
18+
}
19+
20+
let output = cmd
21+
.stdout(std::process::Stdio::inherit())
22+
.stderr(std::process::Stdio::inherit())
23+
.output()
24+
.context("cmd failed")?;
25+
anyhow::ensure!(output.status.success());
26+
27+
Ok(())
28+
}
29+
30+
struct ShaderCrateTemplateCargoTomlWriter {
31+
original_shader_crate_template_str: String,
32+
table: toml::Table,
33+
}
34+
35+
impl Drop for ShaderCrateTemplateCargoTomlWriter {
36+
fn drop(&mut self) {
37+
log::info!("reverting overwrite of Cargo.toml");
38+
std::fs::write(Self::PATH, &self.original_shader_crate_template_str).unwrap();
39+
}
40+
}
41+
42+
impl ShaderCrateTemplateCargoTomlWriter {
43+
const PATH: &str = "crates/shader-crate-template/Cargo.toml";
44+
45+
fn new() -> Self {
46+
let original_shader_crate_template_str = std::fs::read_to_string(Self::PATH).unwrap();
47+
let table = toml::from_str::<toml::Table>(&original_shader_crate_template_str).unwrap();
48+
Self {
49+
original_shader_crate_template_str,
50+
table,
51+
}
52+
}
53+
54+
fn replace_output_dir(&mut self, path: impl AsRef<std::path::Path>) -> anyhow::Result<()> {
55+
let package = self
56+
.table
57+
.get_mut("package")
58+
.unwrap()
59+
.as_table_mut()
60+
.unwrap();
61+
let metadata = package.get_mut("metadata").unwrap().as_table_mut().unwrap();
62+
let rust_gpu = metadata
63+
.get_mut("rust-gpu")
64+
.unwrap()
65+
.as_table_mut()
66+
.unwrap();
67+
let build = rust_gpu.get_mut("build").unwrap().as_table_mut().unwrap();
68+
let output_dir = build.get_mut("output-dir").unwrap();
69+
*output_dir = toml::Value::String(format!("{}", path.as_ref().display()));
70+
std::fs::write(
71+
Self::PATH,
72+
toml::to_string_pretty(&self.table).context("could not serialize")?,
73+
)
74+
.context("could not overwrite path")?;
75+
Ok(())
76+
}
77+
}
78+
79+
/// Run the xtask.
80+
fn main() {
81+
env_logger::builder().init();
82+
83+
let cli = Cli::parse();
84+
85+
match cli {
86+
Cli::TestBuild => {
87+
log::info!("installing cargo gpu");
88+
cmd(["cargo", "install", "--path", "crates/cargo-gpu"]).unwrap();
89+
90+
log::info!("installing cargo gpu artifacts");
91+
cmd([
92+
"cargo",
93+
"gpu",
94+
"install",
95+
"--shader-crate",
96+
"crates/shader-crate-template",
97+
"--auto-install-rust-toolchain",
98+
])
99+
.unwrap();
100+
101+
let dir = tempdir::TempDir::new("test-shader-output").unwrap();
102+
let mut overwriter = ShaderCrateTemplateCargoTomlWriter::new();
103+
overwriter.replace_output_dir(dir.path()).unwrap();
104+
105+
cmd([
106+
"cargo",
107+
"gpu",
108+
"build",
109+
"--shader-crate",
110+
"crates/shader-crate-template",
111+
"--force-spirv-cli-rebuild",
112+
])
113+
.unwrap();
114+
115+
cmd(["ls", "-lah", dir.path().to_str().unwrap()]).unwrap();
116+
cmd(["cat", dir.path().join("manifest.json").to_str().unwrap()]).unwrap();
117+
}
118+
}
119+
}

justfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/build_shader_template.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)