Skip to content

Commit 1c09007

Browse files
authored
ci: add cargo fmt --check to Rust CI pipeline (#747)
* ci: add cargo fmt --check to Rust CI pipeline * ci: run rustfmt check in test job * ci: trigger workflow run * style: fix cargo fmt formatting in rs_port * ci: run rust fmt check after rs_port build * style: exclude auto-generated bindings.rs from rustfmt and fix metacall_value.rs formatting * fix: use outer attribute in bindgen raw_line to fix build error * ci: add rustfmt.toml to pin Rust edition for consistent formatting
1 parent 4a5f14c commit 1c09007

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

.github/workflows/release-rust.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,16 @@ jobs:
4141
with:
4242
toolchain: stable
4343
override: true
44+
components: rustfmt
4445

4546
- name: Build the Rust Port
4647
working-directory: source/ports/rs_port
4748
run: cargo build --verbose
4849

50+
- name: Check Rust Formatting
51+
working-directory: source/ports/rs_port
52+
run: cargo fmt --check
53+
4954
- name: Test the Rust Port
5055
working-directory: source/ports/rs_port
5156
env:

source/ports/rs_port/build.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use std::env;
22
use std::path::PathBuf;
33

44
fn generate_bindings() {
5-
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
6-
let output = manifest_dir.join("src").join("bindings.rs");
5+
let manifest_dir =
6+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
7+
let output = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR not set")).join("bindings.rs");
78
let mut builder = bindgen::Builder::default()
9+
.raw_line("#[cfg_attr(rustfmt, rustfmt::skip)]")
810
.allowlist_function("metacall.*")
911
.rustified_enum("metacall_.*");
1012

@@ -25,12 +27,22 @@ fn generate_bindings() {
2527
}
2628

2729
builder = builder
28-
.clang_arg(format!("-I{}", root.join("source/metacall/include").display()))
29-
.clang_arg(format!("-I{}", build_dir.join("source/metacall/include").display()))
30+
.clang_arg(format!(
31+
"-I{}",
32+
root.join("source/metacall/include").display()
33+
))
34+
.clang_arg(format!(
35+
"-I{}",
36+
build_dir.join("source/metacall/include").display()
37+
))
3038
.clang_arg(format!("-I{}", build_dir.join("source/include").display()));
3139
} else {
3240
let lib = metacall_sys::find_metacall_library().unwrap();
33-
let include = lib.path.parent().expect("library path has no parent").join("include");
41+
let include = lib
42+
.path
43+
.parent()
44+
.expect("library path has no parent")
45+
.join("include");
3446
let include_metacall = include.join("metacall");
3547

3648
for entry in std::fs::read_dir(&include_metacall).expect("failed to read include dir") {

source/ports/rs_port/rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edition = "2021"

source/ports/rs_port/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ pub mod inline {
119119

120120
#[allow(warnings)]
121121
#[doc(hidden)]
122-
pub mod bindings;
122+
pub mod bindings {
123+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
124+
}

source/ports/rs_port/src/types/metacall_value.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl MetaCallValue for i64 {
168168
// TODO: This issue happens because we do not have a clear type definition in the Core
169169
// We are not sure yet if we should use fixed sizes in the core, or adapt all the loaders
170170
// and ports to the standard C int type definition. We should define this but it's not yet.
171-
// Meanwhile as a workaround, we just panic if it does not fit.
171+
// Meanwhile as a workaround, we just panic if it does not fit.
172172
#[cfg(any(target_pointer_width = "32", windows))]
173173
{
174174
unsafe { metacall_value_create_long(self.try_into().unwrap()) }
@@ -177,7 +177,6 @@ impl MetaCallValue for i64 {
177177
{
178178
unsafe { metacall_value_create_long(self) }
179179
}
180-
181180
}
182181
}
183182
/// Equivalent to MetaCall float type.

0 commit comments

Comments
 (0)