Skip to content

Commit a20dbba

Browse files
authored
Riddle dialects (#2586)
1 parent f31b44e commit a20dbba

28 files changed

+444
-210
lines changed

crates/tests/riddle/src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@ mod nested_module;
33
mod nested_struct;
44
mod params;
55
mod r#struct;
6+
mod win32_struct;
7+
mod winrt_struct;
68

79
use std::process::Command;
810

9-
pub fn run_riddle(name: &str) -> Vec<windows_metadata::File> {
10-
let rd = format!("tests/{name}.rd");
11+
pub fn run_riddle(name: &str, dialect: &str, etc: &[&str]) -> Vec<windows_metadata::File> {
12+
let rdl = format!("tests/{name}.rdl");
1113
let winmd = format!("tests/{name}.winmd");
1214
let rs = format!("src/{name}.rs");
1315

14-
let before = std::fs::read_to_string(&rd).expect("Failed to read input");
16+
let before = std::fs::read_to_string(&rdl).expect("Failed to read input");
1517

16-
// Convert .rd to .winmd
18+
// Convert .rdl to .winmd
1719
let mut command = Command::new("cargo");
1820
command.args([
19-
"run", "-p", "riddle", "--", "--in", &rd, "--out", &winmd, "--filter", "Test",
21+
"run", "-p", "riddle", "--", "--in", &rdl, "--out", &winmd, "--filter", "Test",
2022
]);
2123
assert!(command.status().unwrap().success());
2224

23-
// Convert .winmd back to .rd
25+
// Convert .winmd back to .rdl
2426
let mut command = Command::new("cargo");
2527
command.args([
26-
"run", "-p", "riddle", "--", "--in", &winmd, "--out", &rd, "--filter", "Test",
28+
"run", "-p", "riddle", "--", "--in", &winmd, "--out", &rdl, "--filter", "Test", "--config",
2729
]);
30+
command.arg(format!("TYPE={dialect}"));
2831
assert!(command.status().unwrap().success());
2932

30-
// Check that .rd is unchanged
31-
let after = std::fs::read_to_string(&rd).expect("Failed to read output");
32-
assert_eq!(before, after);
33+
// Check that .rdl is unchanged
34+
let after = std::fs::read_to_string(&rdl).expect("Failed to read output");
35+
assert_eq!(before, after, "no equal {}", rdl);
3336

34-
// Convert .rd to .rs
37+
// Convert .rdl to .rs
3538
let mut command = Command::new("cargo");
3639
command.args([
37-
"run", "-p", "riddle", "--", "--in", &rd, "--out", &rs, "--filter", "Test", "--config",
38-
"FLATTEN",
40+
"run", "-p", "riddle", "--", "--in", &rdl, "--out", &rs, "--filter", "Test",
3941
]);
42+
command.args(etc);
4043
assert!(command.status().unwrap().success());
4144

4245
// Return winmd file for validation
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1+
// Bindings generated by `riddle` 0.0.1
12

3+
#![allow(
4+
non_snake_case,
5+
non_upper_case_globals,
6+
non_camel_case_types,
7+
dead_code,
8+
clippy::all
9+
)]
10+
#[repr(C)]
11+
pub struct Type {
12+
pub field: i32,
13+
}
14+
impl ::core::marker::Copy for Type {}
15+
impl ::core::clone::Clone for Type {
16+
fn clone(&self) -> Self {
17+
*self
18+
}
19+
}
20+
impl ::core::fmt::Debug for Type {
21+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
22+
f.debug_struct("Type").field("field", &self.field).finish()
23+
}
24+
}
25+
impl ::windows_core::TypeKind for Type {
26+
type TypeKind = ::windows_core::CopyType;
27+
}
28+
impl ::windows_core::RuntimeType for Type {
29+
const SIGNATURE: ::windows_core::imp::ConstBuffer =
30+
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.Type;i4)");
31+
}
32+
impl ::core::cmp::PartialEq for Type {
33+
fn eq(&self, other: &Self) -> bool {
34+
self.field == other.field
35+
}
36+
}
37+
impl ::core::cmp::Eq for Type {}
38+
impl ::core::default::Default for Type {
39+
fn default() -> Self {
40+
unsafe { ::core::mem::zeroed() }
41+
}
42+
}

crates/tests/riddle/src/nested_module.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,43 @@
77
dead_code,
88
clippy::all
99
)]
10-
#[repr(C)]
11-
pub struct NestedType {
12-
pub field: f32,
13-
}
14-
impl ::core::marker::Copy for NestedType {}
15-
impl ::core::clone::Clone for NestedType {
16-
fn clone(&self) -> Self {
17-
*self
10+
pub mod NestedModule {
11+
#[repr(C)]
12+
pub struct NestedType {
13+
pub field: f32,
1814
}
19-
}
20-
impl ::core::fmt::Debug for NestedType {
21-
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
22-
f.debug_struct("NestedType")
23-
.field("field", &self.field)
24-
.finish()
15+
impl ::core::marker::Copy for NestedType {}
16+
impl ::core::clone::Clone for NestedType {
17+
fn clone(&self) -> Self {
18+
*self
19+
}
2520
}
26-
}
27-
impl ::windows_core::TypeKind for NestedType {
28-
type TypeKind = ::windows_core::CopyType;
29-
}
30-
impl ::windows_core::RuntimeType for NestedType {
31-
const SIGNATURE: ::windows_core::imp::ConstBuffer =
32-
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.NestedModule.NestedType;f4)");
33-
}
34-
impl ::core::cmp::PartialEq for NestedType {
35-
fn eq(&self, other: &Self) -> bool {
36-
self.field == other.field
21+
impl ::core::fmt::Debug for NestedType {
22+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
23+
f.debug_struct("NestedType")
24+
.field("field", &self.field)
25+
.finish()
26+
}
3727
}
38-
}
39-
impl ::core::cmp::Eq for NestedType {}
40-
impl ::core::default::Default for NestedType {
41-
fn default() -> Self {
42-
unsafe { ::core::mem::zeroed() }
28+
impl ::windows_core::TypeKind for NestedType {
29+
type TypeKind = ::windows_core::CopyType;
30+
}
31+
impl ::windows_core::RuntimeType for NestedType {
32+
const SIGNATURE: ::windows_core::imp::ConstBuffer =
33+
::windows_core::imp::ConstBuffer::from_slice(
34+
b"struct(Test.NestedModule.NestedType;f4)",
35+
);
36+
}
37+
impl ::core::cmp::PartialEq for NestedType {
38+
fn eq(&self, other: &Self) -> bool {
39+
self.field == other.field
40+
}
41+
}
42+
impl ::core::cmp::Eq for NestedType {}
43+
impl ::core::default::Default for NestedType {
44+
fn default() -> Self {
45+
unsafe { ::core::mem::zeroed() }
46+
}
4347
}
4448
}
4549
#[repr(C)]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Bindings generated by `riddle` 0.0.1
2+
3+
#![allow(
4+
non_snake_case,
5+
non_upper_case_globals,
6+
non_camel_case_types,
7+
dead_code,
8+
clippy::all
9+
)]
10+
#[repr(C)]
11+
pub struct Type {
12+
pub field: i32,
13+
}
14+
impl ::core::marker::Copy for Type {}
15+
impl ::core::clone::Clone for Type {
16+
fn clone(&self) -> Self {
17+
*self
18+
}
19+
}
20+
impl ::core::fmt::Debug for Type {
21+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
22+
f.debug_struct("Type").field("field", &self.field).finish()
23+
}
24+
}
25+
impl ::windows_core::TypeKind for Type {
26+
type TypeKind = ::windows_core::CopyType;
27+
}
28+
impl ::core::cmp::PartialEq for Type {
29+
fn eq(&self, other: &Self) -> bool {
30+
self.field == other.field
31+
}
32+
}
33+
impl ::core::cmp::Eq for Type {}
34+
impl ::core::default::Default for Type {
35+
fn default() -> Self {
36+
unsafe { ::core::mem::zeroed() }
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Bindings generated by `riddle` 0.0.1
2+
3+
#![allow(
4+
non_snake_case,
5+
non_upper_case_globals,
6+
non_camel_case_types,
7+
dead_code,
8+
clippy::all
9+
)]
10+
#[repr(C)]
11+
pub struct Type {
12+
pub field: i32,
13+
}
14+
impl ::core::marker::Copy for Type {}
15+
impl ::core::clone::Clone for Type {
16+
fn clone(&self) -> Self {
17+
*self
18+
}
19+
}
20+
impl ::core::fmt::Debug for Type {
21+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
22+
f.debug_struct("Type").field("field", &self.field).finish()
23+
}
24+
}
25+
impl ::windows_core::TypeKind for Type {
26+
type TypeKind = ::windows_core::CopyType;
27+
}
28+
impl ::windows_core::RuntimeType for Type {
29+
const SIGNATURE: ::windows_core::imp::ConstBuffer =
30+
::windows_core::imp::ConstBuffer::from_slice(b"struct(Test.Type;i4)");
31+
}
32+
impl ::core::cmp::PartialEq for Type {
33+
fn eq(&self, other: &Self) -> bool {
34+
self.field == other.field
35+
}
36+
}
37+
impl ::core::cmp::Eq for Type {}
38+
impl ::core::default::Default for Type {
39+
fn default() -> Self {
40+
unsafe { ::core::mem::zeroed() }
41+
}
42+
}

crates/tests/riddle/tests/module_attributes.rd

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![winrt]
2+
3+
mod Test {
4+
struct Type {
5+
field: i32,
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
use test_riddle::run_riddle;
2+
use windows_metadata::*;
13

4+
#[test]
5+
fn test() {
6+
let files = run_riddle("module_attributes", "winrt", &[]);
7+
let _reader = &Reader::new(&files);
8+
}

crates/tests/riddle/tests/nested_module.rd renamed to crates/tests/riddle/tests/nested_module.rdl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![winrt]
2+
13
mod Test {
24
mod NestedModule {
35
struct NestedType {
@@ -7,4 +9,4 @@ mod Test {
79
struct TestType {
810
field: i32,
911
}
10-
}
12+
}

crates/tests/riddle/tests/nested_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use windows_metadata::*;
33

44
#[test]
55
fn test() {
6-
let files = run_riddle("nested_module");
6+
let files = run_riddle("nested_module", "winrt", &[]);
77
let reader = &Reader::new(&files);
88

99
let types: Vec<Item> = reader

0 commit comments

Comments
 (0)