Skip to content

Commit 3bf599d

Browse files
authored
chore: nightly fmt (#225)
* fmt * nightly formatting workflow job * use cache and install rustfmt on nightly * nightly format, again * just format everything with nightly during linkage generation
1 parent 70f5ace commit 3bf599d

32 files changed

Lines changed: 329 additions & 212 deletions

File tree

.github/workflows/push.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,30 @@ jobs:
7878
${{ needs.install-cargo-gpu.outputs.cachepath-Windows }}
7979
key: rust-gpu-cache-0-${{ runner.os }}
8080
- uses: moonrepo/setup-rust@v1
81+
- run: rustup install nightly
82+
- run: rustup component add --toolchain nightly rustfmt
8183
- run: cargo gpu show commitsh
8284
- run: rm -rf crates/renderling/src/linkage/* crates/renderling/shaders
8385
- run: cargo shaders
8486
- run: cargo linkage
8587
- run: cargo build -p renderling
8688
- run: git diff --exit-code --no-ext-diff
8789

90+
# Ensures code is properly formatted with nightly rustfmt
91+
renderling-fmt:
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v2
95+
- uses: actions/cache@v4
96+
with:
97+
path: ~/.cargo
98+
# THIS KEY MUST MATCH ABOVE
99+
key: cargo-cache-${{ env.CARGO_GPU_COMMITSH }}-${{ runner.os }}
100+
- uses: moonrepo/setup-rust@v1
101+
- run: rustup install nightly
102+
- run: rustup component add --toolchain nightly rustfmt
103+
- run: cargo +nightly fmt -- --check
104+
88105
# BAU clippy lints
89106
renderling-clippy:
90107
runs-on: ubuntu-latest

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
- Tests: inline `#[cfg(test)] mod test { ... }` within modules
1616
- CPU-only code: wrap with `#[cfg(cpu)]`
1717

18+
Always format with `cargo +nightly fmt`.
19+
1820
## Disallowed Methods (clippy.toml)
1921
Avoid: `Vec{2,3,4}::normalize_or_zero`, `Mat4::to_scale_rotation_translation`, `f32::signum`

crates/example/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ impl App {
380380

381381
// self.lighting
382382
// .shadow_map
383-
// .update(&self.lighting.lighting, doc.primitives.values().flatten());
384-
// self.lighting.light = light.light.clone();
385-
// self.lighting.light_details = dir.clone();
386-
// }
383+
// .update(&self.lighting.lighting,
384+
// doc.primitives.values().flatten()); self.lighting.light =
385+
// light.light.clone(); self.lighting.light_details =
386+
// dir.clone(); }
387387
// }
388388

389389
self.model = Model::Gltf(Box::new(doc));

crates/examples/src/gltf.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ async fn manual_gltf() {
88
use renderling::{
99
camera::Camera,
1010
context::Context,
11-
glam::Vec4,
12-
glam::{Mat4, Vec3},
11+
glam::{Mat4, Vec3, Vec4},
1312
stage::Stage,
1413
};
1514

crates/examples/src/lighting.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ async fn manual_lighting() {
88
use renderling::{
99
camera::Camera,
1010
context::Context,
11-
glam::Vec4,
12-
glam::{Mat4, Vec3},
11+
glam::{Mat4, Vec3, Vec4},
1312
gltf::GltfDocument,
1413
stage::Stage,
1514
types::GpuOnlyArray,
@@ -155,8 +154,7 @@ async fn manual_lighting_ibl() {
155154
use renderling::{
156155
camera::Camera,
157156
context::Context,
158-
glam::Vec4,
159-
glam::{Mat4, Vec3},
157+
glam::{Mat4, Vec3, Vec4},
160158
gltf::GltfDocument,
161159
stage::Stage,
162160
types::GpuOnlyArray,

crates/examples/src/skybox.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ pub async fn manual_skybox() {
88
use renderling::{
99
camera::Camera,
1010
context::Context,
11-
glam::Vec4,
12-
glam::{Mat4, Vec3},
11+
glam::{Mat4, Vec3, Vec4},
1312
stage::Stage,
1413
};
1514

crates/loading-bytes/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ pub async fn post_bin_wasm<T: serde::de::DeserializeOwned>(
240240
Ok(t)
241241
}
242242

243-
/// Load the file at the given url fragment or path and return it as a vector of bytes, if
244-
/// possible.
243+
/// Load the file at the given url fragment or path and return it as a vector of
244+
/// bytes, if possible.
245245
pub async fn load(path: &str) -> Result<Vec<u8>, LoadingBytesError> {
246246
#[cfg(target_arch = "wasm32")]
247247
{

crates/renderling-build/src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ pub fn wasm_test_output_dir() -> std::path::PathBuf {
171171

172172
#[derive(Debug)]
173173
pub struct RenderlingPaths {
174-
/// `cargo_workspace` is not available when building outside of the project directory.
174+
/// `cargo_workspace` is not available when building outside of the project
175+
/// directory.
175176
pub cargo_workspace: Option<std::path::PathBuf>,
176177
pub renderling_crate: std::path::PathBuf,
177178
pub shader_dir: std::path::PathBuf,
@@ -184,10 +185,12 @@ impl RenderlingPaths {
184185
///
185186
/// If the `CARGO_WORKSPACE_DIR` and subsequently the `cargo_workspace` is
186187
/// _not_ available, this most likely means we're building renderling
187-
/// outside of its own source tree, which means we **don't want to compile shaders**.
188+
/// outside of its own source tree, which means we **don't want to compile
189+
/// shaders**.
188190
///
189-
/// But we may still need to transpile the packaged SPIR-V into WGSL for WASM, and
190-
/// so `cargo_workspace` is `Option` and the entire function also returns `Option`.
191+
/// But we may still need to transpile the packaged SPIR-V into WGSL for
192+
/// WASM, and so `cargo_workspace` is `Option` and the entire function
193+
/// also returns `Option`.
191194
pub fn new() -> Option<Self> {
192195
let cargo_workspace = std::env::var("CARGO_WORKSPACE_DIR")
193196
.map(std::path::PathBuf::from)
@@ -276,11 +279,14 @@ impl RenderlingPaths {
276279

277280
let contents = linkage.to_string();
278281
std::fs::write(&filepath, contents).unwrap();
279-
std::process::Command::new("rustfmt")
280-
.args([&format!("{}", filepath.display())])
281-
.output()
282-
.expect("could not format generated code");
283282
}
283+
// Just format the whole project. I know this is less than ideal,
284+
// but people should be running with a formatter in their editor, and all of
285+
// this is temporary given the wgsl-rs re-stacking happening this year (2026)
286+
std::process::Command::new("cargo")
287+
.args(["+nightly", "fmt"])
288+
.output()
289+
.expect("could not format generated code");
284290
log::info!("...done!")
285291
}
286292
}

crates/renderling/src/atlas.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! All images are packed into an atlas at staging time.
44
//! Texture descriptors describe where in the atlas an image is,
55
//! and how it should sample pixels. These descriptors are packed into a buffer
6-
//! on the GPU. This keeps the number of texture binds to a minimum (one, in most cases).
6+
//! on the GPU. This keeps the number of texture binds to a minimum (one, in
7+
//! most cases).
78
//!
89
//! ## NOTE:
910
//! `Atlas` is a temporary work around until we can use bindless techniques

crates/renderling/src/atlas/atlas_image.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ impl From<AtlasImageFormat> for wgpu::TextureFormat {
5151
match value {
5252
AtlasImageFormat::R8 => wgpu::TextureFormat::R8Unorm,
5353
AtlasImageFormat::R8G8 => wgpu::TextureFormat::Rg8Unorm,
54-
AtlasImageFormat::R8G8B8 => wgpu::TextureFormat::Rgba8Unorm, // No direct 3-channel format, using 4-channel
54+
AtlasImageFormat::R8G8B8 => wgpu::TextureFormat::Rgba8Unorm, /* No direct 3-channel */
55+
// format, using
56+
// 4-channel
5557
AtlasImageFormat::R8G8B8A8 => wgpu::TextureFormat::Rgba8Unorm,
5658
AtlasImageFormat::R16 => wgpu::TextureFormat::R16Unorm,
5759
AtlasImageFormat::R16G16 => wgpu::TextureFormat::Rg16Unorm,
58-
AtlasImageFormat::R16G16B16 => wgpu::TextureFormat::Rgba16Unorm, // No direct 3-channel format, using 4-channel
60+
AtlasImageFormat::R16G16B16 => wgpu::TextureFormat::Rgba16Unorm, /* No direct 3-channel format, using 4-channel */
5961
AtlasImageFormat::R16G16B16A16 => wgpu::TextureFormat::Rgba16Unorm,
6062
AtlasImageFormat::R16G16B16A16FLOAT => wgpu::TextureFormat::Rgba16Float,
6163
AtlasImageFormat::R32FLOAT => wgpu::TextureFormat::R32Float,
62-
AtlasImageFormat::R32G32B32FLOAT => wgpu::TextureFormat::Rgba32Float, // No direct 3-channel format, using 4-channel
64+
AtlasImageFormat::R32G32B32FLOAT => wgpu::TextureFormat::Rgba32Float, /* No direct 3-channel format, using 4-channel */
6365
AtlasImageFormat::R32G32B32A32FLOAT => wgpu::TextureFormat::Rgba32Float,
6466
AtlasImageFormat::D32FLOAT => wgpu::TextureFormat::Depth32Float,
6567
}
@@ -272,8 +274,8 @@ fn apply_linear_xfer(bytes: &mut [u8], format: AtlasImageFormat) {
272274
}
273275
}
274276

275-
/// Interpret/convert the `AtlasImage` pixel data into `wgpu::TextureFormat` pixels,
276-
/// if possible.
277+
/// Interpret/convert the `AtlasImage` pixel data into `wgpu::TextureFormat`
278+
/// pixels, if possible.
277279
///
278280
/// This applies the linear transfer function if `apply_linear_transfer` is
279281
/// `true`.

0 commit comments

Comments
 (0)