Skip to content

Commit 18f3ce9

Browse files
authored
Merge pull request #22 from Rust-GPU/feat/ci
feature: initial CI workflow
2 parents fab7a39 + 5918e69 commit 18f3ce9

File tree

9 files changed

+367
-13
lines changed

9 files changed

+367
-13
lines changed

.github/workflows/push.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: push
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
env:
10+
# For setup-rust, see https://github.com/moonrepo/setup-rust/issues/22
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
13+
jobs:
14+
install-and-build-shaders:
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest, macos-latest, windows-latest]
18+
runs-on: ${{ matrix.os }}
19+
defaults:
20+
run:
21+
shell: bash
22+
env:
23+
RUST_LOG: debug
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: moonrepo/setup-rust@v1
27+
- run: rustup default stable
28+
- run: rustup update
29+
- run: cargo test
30+
- run: cargo install --path crates/cargo-gpu
31+
- run: cargo gpu install
32+
- run: cargo gpu build --shader-crate crates/shader-crate-template --output-dir test-shaders
33+
- run: ls -lah test-shaders
34+
- run: cat test-shaders/manifest.json
35+
36+
clippy:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: moonrepo/setup-rust@v1
41+
- run: cargo clippy

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"crates/cargo-gpu",
4+
"crates/shader-crate-template"
45
]
56

67
exclude = [

crates/cargo-gpu/src/main.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,34 @@ struct Spirv {
135135
channel: String,
136136
}
137137

138+
impl Default for Spirv {
139+
fn default() -> Self {
140+
Self {
141+
dep: Self::DEFAULT_DEP.into(),
142+
channel: Self::DEFAULT_CHANNEL.into(),
143+
}
144+
}
145+
}
146+
138147
impl core::fmt::Display for Spirv {
139148
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140149
format!("{}+{}", self.dep, self.channel).fmt(f)
141150
}
142151
}
143152

144153
impl Spirv {
154+
const DEFAULT_DEP: &str = r#"{ git = "https://github.com/Rust-GPU/rust-gpu.git" }"#;
155+
const DEFAULT_CHANNEL: &str = "nightly-2024-04-24";
156+
145157
/// Returns a string suitable to use as a directory.
146158
///
147159
/// Created from the spirv-builder source dep and the rustc channel.
148160
fn to_dirname(&self) -> String {
149161
self.to_string()
150-
.replace([std::path::MAIN_SEPARATOR, '.', ':', '@', '='], "_")
162+
.replace(
163+
[std::path::MAIN_SEPARATOR, '\\', '/', '.', ':', '@', '='],
164+
"_",
165+
)
151166
.split(['{', '}', ' ', '\n', '"', '\''])
152167
.collect::<Vec<_>>()
153168
.concat()
@@ -258,16 +273,13 @@ fn target_spec_dir() -> std::path::PathBuf {
258273
#[derive(Parser, Debug)]
259274
struct Install {
260275
/// spirv-builder dependency, written just like in a Cargo.toml file.
261-
#[clap(
262-
long,
263-
default_value = r#"{ git = "https://github.com/Rust-GPU/rust-gpu.git" }"#
264-
)]
276+
#[clap(long, default_value = Spirv::DEFAULT_DEP)]
265277
spirv_builder: String,
266278

267279
/// Rust toolchain channel to use to build `spirv-builder`.
268280
///
269281
/// This must match the `spirv_builder` argument.
270-
#[clap(long, default_value = "nightly-2024-04-24")]
282+
#[clap(long, default_value = Spirv::DEFAULT_CHANNEL)]
271283
rust_toolchain: String,
272284

273285
/// Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt.
@@ -312,6 +324,7 @@ impl Install {
312324
fn run(&self) -> (std::path::PathBuf, std::path::PathBuf) {
313325
// Ensure the cache dir exists
314326
let cache_dir = cache_dir();
327+
log::info!("cache directory is '{}'", cache_dir.display());
315328
std::fs::create_dir_all(&cache_dir).unwrap_or_else(|e| {
316329
log::error!(
317330
"could not create cache directory '{}': {e}",
@@ -381,12 +394,21 @@ impl Install {
381394
panic!("spirv-builder-cli build failed");
382395
}
383396

384-
let cli_path = release.join("spirv-builder-cli");
397+
let cli_path = if cfg!(target_os = "windows") {
398+
release.join("spirv-builder-cli").with_extension("exe")
399+
} else {
400+
release.join("spirv-builder-cli")
401+
};
385402
if cli_path.is_file() {
386403
log::info!("successfully built {}", cli_path.display());
387404
std::fs::rename(&cli_path, &dest_cli_path).unwrap();
388405
} else {
389406
log::error!("could not find {}", cli_path.display());
407+
log::debug!("contents of '{}':", release.display());
408+
for entry in std::fs::read_dir(&release).unwrap() {
409+
let entry = entry.unwrap();
410+
log::debug!("{}", entry.file_name().to_string_lossy());
411+
}
390412
panic!("spirv-builder-cli build failed");
391413
}
392414
}
@@ -757,7 +779,7 @@ fn dump_full_usage_for_readme() {
757779
println!("{}", buffer);
758780
}
759781

760-
fn write_help(buffer: &mut impl std::io::Write, cmd: &mut clap::Command, depth: usize) {
782+
fn write_help(buffer: &mut impl std::io::Write, cmd: &mut clap::Command, _depth: usize) {
761783
if cmd.get_name() == "help" {
762784
return;
763785
}
@@ -774,14 +796,31 @@ fn write_help(buffer: &mut impl std::io::Write, cmd: &mut clap::Command, depth:
774796

775797
for sub in cmd.get_subcommands_mut() {
776798
let _ = writeln!(buffer);
777-
write_help(buffer, sub, depth + 1);
799+
write_help(buffer, sub, _depth + 1);
778800
}
779801
}
780802

781803
#[cfg(test)]
782804
mod test {
783805
use super::*;
784806

807+
#[test]
808+
fn cached_checkout_dir_sanity() {
809+
// Test that
810+
let spirv = Spirv::default();
811+
let dir = spirv.cached_checkout_path();
812+
let name = dir
813+
.file_name()
814+
.unwrap()
815+
.to_str()
816+
.map(|s| s.to_string())
817+
.unwrap();
818+
assert_eq!(
819+
"git_https___github_com_Rust-GPU_rust-gpu_git+nightly-2024-04-24",
820+
&name
821+
);
822+
}
823+
785824
#[test]
786825
fn builder_from_params() {
787826
let shader_crate = std::path::PathBuf::from("../shader-crate-template");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)