Skip to content

Commit 251709c

Browse files
chore: make sure the rust serialization test stays up to date
1 parent 462b416 commit 251709c

5 files changed

Lines changed: 356 additions & 274 deletions

File tree

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ repos:
1919
hooks:
2020
- id: clang-format
2121
files: \.(c|h)$
22+
23+
- repo: local
24+
hooks:
25+
- id: check-serialized
26+
name: Check serialized.zig is up to date
27+
entry: bash -c 'cd src/tests/deserialize_rust && diff <(cargo run --quiet 2>/dev/null) serialized.zig'
28+
language: system
29+
pass_filenames: false

src/tests/deserialize_rust/Cargo.lock

Lines changed: 308 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "create-serialized"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[[bin]]
8+
name = "create-serialized"
9+
path = "main.rs"
10+
11+
[dependencies]
12+
bincode = "1.3.3"
13+
serde = { version = "1.0.192", features = ["derive"] }
14+
runner-shared = { git = "https://github.com/CodSpeedHQ/runner" }

src/tests/deserialize_rust/create_serialized.rs renamed to src/tests/deserialize_rust/main.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
#!/usr/bin/env rust-script
2-
31
//! Serializes the shared `Command` enum to test whether Zig deserializes it correctly.
42
//!
53
//! # Run
64
//!
75
//! ```bash
8-
//! ./create_serialized.rs > serialized.zig
9-
//! ```
10-
//!
11-
//! ```cargo
12-
//! [dependencies]
13-
//! bincode = "1.3.3"
14-
//! serde = { version = "1.0.192", features = ["derive"] }
15-
//! runner-shared = { git = "https://github.com/CodSpeedHQ/runner" }
6+
//! cargo run > serialized.zig
167
//! ```
178
189
// Import from runner-shared to ensure we use the same types
19-
use runner_shared::fifo::{Command, MarkerType, RunnerMode};
10+
use runner_shared::fifo::{Command, IntegrationMode, MarkerType};
2011

2112
fn dump(name: &str, result: &Vec<u8>) {
2213
print!("pub const {}: []const u8 = &.{{ ", name);
@@ -32,7 +23,8 @@ fn example<T: serde::Serialize>(name: &str, value: &T) {
3223
}
3324

3425
fn main() {
35-
println!("// This file is generated using 'cargo run > rust_ser.zig'");
26+
println!("// This file is generated using 'cargo run > serialized.zig'");
27+
println!("// zig fmt: off");
3628
println!("");
3729

3830
example(
@@ -83,17 +75,17 @@ fn main() {
8375
},
8476
);
8577
example("cmd_set_version", &Command::SetVersion(1));
86-
example("cmd_get_runner_mode", &Command::GetRunnerMode);
78+
example("cmd_get_runner_mode", &Command::GetIntegrationMode);
8779
example(
8880
"cmd_runner_mode_perf",
89-
&Command::RunnerModeResponse(RunnerMode::Perf),
81+
&Command::IntegrationModeResponse(IntegrationMode::Perf),
9082
);
9183
example(
9284
"cmd_runner_mode_simulation",
93-
&Command::RunnerModeResponse(RunnerMode::Simulation),
85+
&Command::IntegrationModeResponse(IntegrationMode::Simulation),
9486
);
9587
example(
9688
"cmd_runner_mode_analysis",
97-
&Command::RunnerModeResponse(RunnerMode::Analysis),
89+
&Command::IntegrationModeResponse(IntegrationMode::Analysis),
9890
);
9991
}

0 commit comments

Comments
 (0)