Skip to content

Commit 2c798e4

Browse files
committed
formatting
1 parent 1e7cd7c commit 2c798e4

File tree

1 file changed

+27
-55
lines changed
  • tests/run-make/core-ffi-typecheck

1 file changed

+27
-55
lines changed

tests/run-make/core-ffi-typecheck/rmake.rs

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
use run_make_support::{rustc, clang, serde_json, rfs};
21
use std::collections::HashMap;
32

3+
use run_make_support::{clang, rfs, rustc, serde_json};
4+
45
const C_TYPES: &[(&str, &str)] = &[
5-
("c_char", "__CHAR_BIT__"), // Character width
6+
("c_char", "__CHAR_BIT__"), // Character width
67
("char_signedness", "__CHAR_UNSIGNED__"),
7-
("c_double", "__SIZEOF_DOUBLE__"), // Double precision floating-point
8-
("c_float", "__SIZEOF_FLOAT__"), // Single precision floating-point
9-
("c_int", "__SIZEOF_INT__"), // Signed integer
10-
("c_long", "__SIZEOF_LONG__"), // Signed long integer
11-
("c_longlong", "__SIZEOF_LONG_LONG__"), // Signed long long integer
12-
("c_schar", "__SIZEOF_CHAR__"), // Signed char
13-
("c_short", "__SIZEOF_SHORT__"), // Signed short integer
14-
("c_uchar", "__SIZEOF_CHAR__"), // Unsigned char
15-
("c_uint", "__SIZEOF_INT__"), // Unsigned integer
16-
("c_ulong", "__SIZEOF_LONG__"), // Unsigned long integer
8+
("c_double", "__SIZEOF_DOUBLE__"), // Double precision floating-point
9+
("c_float", "__SIZEOF_FLOAT__"), // Single precision floating-point
10+
("c_int", "__SIZEOF_INT__"), // Signed integer
11+
("c_long", "__SIZEOF_LONG__"), // Signed long integer
12+
("c_longlong", "__SIZEOF_LONG_LONG__"), // Signed long long integer
13+
("c_schar", "__SIZEOF_CHAR__"), // Signed char
14+
("c_short", "__SIZEOF_SHORT__"), // Signed short integer
15+
("c_uchar", "__SIZEOF_CHAR__"), // Unsigned char
16+
("c_uint", "__SIZEOF_INT__"), // Unsigned integer
17+
("c_ulong", "__SIZEOF_LONG__"), // Unsigned long integer
1718
("c_ulonglong", "__SIZEOF_LONG_LONG__"), // Unsigned long long integer
18-
("c_ushort", "__SIZEOF_SHORT__"), // Unsigned short integer
19-
("c_size_t", "__SIZEOF_SIZE_T__"), // Size type
19+
("c_ushort", "__SIZEOF_SHORT__"), // Unsigned short integer
20+
("c_size_t", "__SIZEOF_SIZE_T__"), // Size type
2021
("c_ptrdiff_t", "__SIZEOF_PTRDIFF_T__"), // Pointer difference type];
2122
];
2223

23-
24-
2524
// #define __CHAR_BIT__ 8 // c_char
2625
// #define __CHAR_UNSIGNED__ 1 // char signedness
2726

@@ -36,7 +35,6 @@ const C_TYPES: &[(&str, &str)] = &[
3635
// #define __SIZEOF_SHORT__ 2 // c_short
3736
// #define __SIZEOF_SIZE_T__ 4 // c_size_t
3837

39-
4038
// const ADDITIONAL_CHECKS: &[(&str, &str)] = &[
4139
// ("bool", "__BOOL_WIDTH__"),
4240
// ("isize", "__INTPTR_WIDTH__"),
@@ -52,25 +50,15 @@ type ClangDefinitions = HashMap<String, String>;
5250
type TargetDefinitions = HashMap<String, ClangDefinitions>;
5351

5452
fn get_target_list() -> String {
53+
let completed_process = rustc().arg("--print").arg("target-list").run();
5554

56-
let completed_process = rustc()
57-
.arg("--print")
58-
.arg("target-list")
59-
.run();
60-
61-
String::from_utf8(completed_process.stdout())
62-
.expect("error not a string")
55+
String::from_utf8(completed_process.stdout()).expect("error not a string")
6356
}
6457

6558
//specifically querying the rust target with the llvm target.
6659
fn get_llvm_target(rust_target: &str) -> Option<String> {
67-
6860
let completed_process = rustc()
69-
.args(&[
70-
"-Z", "unstable-options",
71-
"--print", "target-spec-json",
72-
"--target", rust_target
73-
])
61+
.args(&["-Z", "unstable-options", "--print", "target-spec-json", "--target", rust_target])
7462
.run();
7563

7664
let json_output = match String::from_utf8(completed_process.stdout()) {
@@ -86,18 +74,9 @@ fn get_llvm_target(rust_target: &str) -> Option<String> {
8674
vals["llvm-target"].as_str().map(|s| s.to_string())
8775
}
8876

89-
90-
9177
fn get_clang_definitions(llvm_target: &str) -> HashMap<String, String> {
92-
let completed_process = clang()
93-
.args(&[
94-
"-E",
95-
"-dM",
96-
"-x", "c",
97-
"/dev/null",
98-
"-target", llvm_target
99-
])
100-
.run();
78+
let completed_process =
79+
clang().args(&["-E", "-dM", "-x", "c", "/dev/null", "-target", llvm_target]).run();
10180

10281
let output = completed_process.stdout_utf8();
10382

@@ -119,7 +98,8 @@ fn get_clang_definitions(llvm_target: &str) -> HashMap<String, String> {
11998
definitions // clang defines | int vals
12099
}
121100

122-
fn collect_clang_definitions(target: &HashMap<String, String>) -> TargetDefinitions { //rust target | llvm target
101+
fn collect_clang_definitions(target: &HashMap<String, String>) -> TargetDefinitions {
102+
//rust target | llvm target
123103
let mut all_definitions = HashMap::new();
124104

125105
for llvm_target in target.values() {
@@ -130,19 +110,17 @@ fn collect_clang_definitions(target: &HashMap<String, String>) -> TargetDefiniti
130110
}
131111

132112
all_definitions
133-
134113
}
135114

136-
fn generate_rust_test(definitions: HashMap<String, String>) -> String { //clang definition | int
115+
fn generate_rust_test(definitions: HashMap<String, String>) -> String {
116+
//clang definition | int
137117
let mut test_code = String::new();
138118
test_code.push_str("use std::ffi::c_char;\n");
139119
test_code.push_str("fn main() {");
140120

141121
if let Some(is_unsigned) = definitions.get("__CHAR_UNSIGNED__") {
142122
let char_type = if is_unsigned == "1" { "u8" } else { "i8" };
143-
test_code.push_str(&format!(
144-
" const _CHAR: c_char = 0_{char_type};\n"
145-
));
123+
test_code.push_str(&format!(" const _CHAR: c_char = 0_{char_type};\n"));
146124
}
147125

148126
test_code.push_str("}\n");
@@ -164,9 +142,7 @@ fn generate_rust_test(definitions: HashMap<String, String>) -> String { //clang
164142
fn main() {
165143
let output = get_target_list();
166144

167-
let targets: Vec<&str> = output
168-
.lines()
169-
.collect();
145+
let targets: Vec<&str> = output.lines().collect();
170146

171147
let mut target_map = HashMap::new();
172148

@@ -187,10 +163,6 @@ fn main() {
187163
for defines in all_definitions.values() {
188164
let test = generate_rust_test(defines.clone());
189165
rfs::write("test.rs", test);
190-
rustc()
191-
.arg("-Z")
192-
.arg("no-codegen")
193-
.arg("test.rs")
194-
.run();
166+
rustc().arg("-Z").arg("no-codegen").arg("test.rs").run();
195167
}
196168
}

0 commit comments

Comments
 (0)