Skip to content

Commit b57e1d2

Browse files
committed
ci: simplify Rust tool and release verification setup
Format generated slang Rust bindings in-process with prettyplease instead of shelling out to rustfmt from the build script. This lets build and release jobs use the minimal pinned Rust toolchain without depending on clippy or rustfmt components. Also remove the duplicate Dev Release Verification workflow now that release.yml exercises the shared artifact workflow on PRs.
1 parent 1de7b76 commit b57e1d2

8 files changed

Lines changed: 7 additions & 96 deletions

File tree

.github/workflows/build-artifacts.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ jobs:
6969
- name: Setup Rust
7070
uses: ./.github/actions/setup-rust
7171
with:
72-
components: rustfmt
7372
targets: ${{ matrix.rustup-target }}
7473

7574
- name: Setup cargo-zigbuild
@@ -194,8 +193,6 @@ jobs:
194193
- name: Setup Rust
195194
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
196195
uses: ./.github/actions/setup-rust
197-
with:
198-
components: rustfmt
199196

200197
- name: Setup sccache
201198
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ jobs:
101101
- uses: actions/checkout@v4
102102
- name: Install Rust
103103
uses: ./.github/actions/setup-rust
104-
with:
105-
components: rustfmt
106104
- name: Setup sccache
107105
uses: ./.github/actions/setup-sccache
108106
with:
@@ -165,8 +163,6 @@ jobs:
165163
- name: Install Rust
166164
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
167165
uses: ./.github/actions/setup-rust
168-
with:
169-
components: rustfmt
170166
- name: Setup sccache
171167
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
172168
uses: ./.github/actions/setup-sccache

.github/workflows/deploy-docs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ jobs:
345345
- name: Install Rust
346346
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
347347
uses: ./.github/actions/setup-rust
348-
with:
349-
components: rustfmt
350348

351349
- name: Setup sccache
352350
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'

.github/workflows/dev-release-verification.yml

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

.github/workflows/docs-preview.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ jobs:
9393
- name: Install Rust
9494
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'
9595
uses: ./.github/actions/setup-rust
96-
with:
97-
components: rustfmt
9896

9997
- name: Setup sccache
10098
if: steps.playground-wasm-cache.outputs.cache-hit != 'true'

crates/slang/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ cmake = "0.1.50"
3737
cxx-build = "1.0.124"
3838
itertools = "0.14.0"
3939
proc-macro2 = "1.0.86"
40+
prettyplease = "0.2.25"
4041
quote = "1.0.36"
4142
regex = "1.11.1"
43+
syn = "2.0.86"
4244
which = "7.0.2"
43-
4445
[dev-dependencies]
4546
utils = { workspace = true, features = ["test-support"] }

crates/slang/bindings/rust/sourcegen.rs

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,9 @@ pub mod loader {
217217
pub mod generator {
218218
use std::{
219219
collections::{BTreeMap, HashMap, HashSet},
220-
env,
221-
ffi::OsString,
222-
fs,
223-
io::{self, BufRead, Write},
220+
env, fs,
221+
io::BufRead,
224222
path::{Path, PathBuf},
225-
process::{Command, Stdio},
226223
};
227224

228225
use inflector::Inflector;
@@ -232,56 +229,16 @@ pub mod generator {
232229

233230
use super::{Ty, TypeInfo, reader_from_file};
234231

235-
// From https://docs.rs/bindgen/0.51.1/src/bindgen/lib.rs.html#1945
236-
fn rustfmt_path() -> io::Result<OsString> {
237-
if let Ok(rustfmt) = env::var("RUSTFMT") {
238-
return Ok(OsString::from(rustfmt));
239-
}
240-
241-
which::which("rustfmt")
242-
.map_or_else(|e| Err(io::Error::other(format!("{}", e))), |p| Ok(p.into_os_string()))
232+
fn format_generated_rust(contents: String) -> String {
233+
syn::parse_file(&contents).map(|file| prettyplease::unparse(&file)).unwrap_or(contents)
243234
}
244235

245236
fn mkdir_and_write(file: &Path, contents: String) -> Result<(), std::io::Error> {
246237
if let Some(parent) = file.parent() {
247238
fs::create_dir_all(parent)?;
248239
}
249240

250-
let rustfmt = rustfmt_path().expect("Failed to find rustfmt");
251-
let mut cmd = Command::new(&*rustfmt);
252-
cmd.arg("--config").arg("use_small_heuristics=Max");
253-
254-
cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
255-
256-
let mut child = cmd.spawn().unwrap();
257-
let mut child_stdin = child.stdin.take().unwrap();
258-
let mut child_stdout = child.stdout.take().unwrap();
259-
260-
let stdin_handle = std::thread::spawn(move || {
261-
let _ = child_stdin.write_all(contents.as_bytes());
262-
contents
263-
});
264-
265-
let mut output = vec![];
266-
io::copy(&mut child_stdout, &mut output).expect("Failed to read rustfmt output");
267-
268-
let status = child.wait().unwrap();
269-
let contents =
270-
stdin_handle.join().expect("The thread writing to rustfmt's stdin doesn't do any");
271-
272-
match (String::from_utf8(output), status.code()) {
273-
(Ok(output), Some(0)) => fs::write(file, output),
274-
(Ok(_), Some(2)) => {
275-
panic!("Rustfmt parsing errors");
276-
}
277-
(Ok(_), Some(3)) => {
278-
panic!("Rustfmt could not format some lines");
279-
}
280-
(Ok(_), _) => {
281-
panic!("Internal rustfmt errors");
282-
}
283-
(Err(_), _) => fs::write(file, contents),
284-
}
241+
fs::write(file, format_generated_rust(contents))
285242
}
286243

287244
fn out_dir(file: &str) -> PathBuf {

rust-toolchain.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[toolchain]
22
channel = "nightly-2026-05-24"
3-
components = ["clippy", "rustfmt"]
43
profile = "minimal"

0 commit comments

Comments
 (0)