Skip to content

Commit 809ef9f

Browse files
committed
libc-test: port windows to use ctest-next
1 parent cf82fdf commit 809ef9f

File tree

12 files changed

+161
-5
lines changed

12 files changed

+161
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
# Remove `-Dwarnings` at the MSRV since lints may be different
9090
export RUSTFLAGS=""
9191
# Remove `ctest-next` which uses the 2024 edition
92-
perl -i -ne 'print unless /"ctest-(next|test)",/' Cargo.toml
92+
perl -i -ne 'print unless /"ctest-(next|test)",/ || /"libc-test",/' Cargo.toml
9393
fi
9494
9595
./ci/verify-build.sh
@@ -320,7 +320,7 @@ jobs:
320320
- name: Install Rust
321321
run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV"
322322
- name: Remove edition 2024 crates
323-
run: perl -i -ne 'print unless /"ctest-(next|test)",/' Cargo.toml
323+
run: perl -i -ne 'print unless /"ctest-(next|test)",/ || /"libc-test",/' Cargo.toml
324324
- uses: Swatinem/rust-cache@v2
325325
- run: cargo build -p ctest
326326

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ctest-next/src/template.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::Deref;
22

33
use askama::Template;
4+
use proc_macro2::Span;
45
use quote::ToTokens;
56
use syn::spanned::Spanned;
67

@@ -453,7 +454,14 @@ impl<'a> TranslateHelper<'a> {
453454
// inside of `Fn` when parsed.
454455
MapInput::Fn(_) => unimplemented!(),
455456
// For structs/unions/aliases, their type is the same as their identifier.
456-
MapInput::Alias(a) => (a.ident(), a.ident().to_string()),
457+
// FIXME(ctest): For some specific primitives such as c_uint, they don't exist on the
458+
// C side and have to be manually translated. If they are removed to use `std::ffi`,
459+
// then this becomes unneeded (although it won't break).
460+
MapInput::Alias(a) => (
461+
a.ident(),
462+
self.translator
463+
.translate_primitive_type(&syn::Ident::new(a.ident(), Span::call_site())),
464+
),
457465
MapInput::Struct(s) => (s.ident(), s.ident().to_string()),
458466
MapInput::Union(u) => (u.ident(), u.ident().to_string()),
459467

ctest-next/src/translator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Translator {
228228
}
229229

230230
/// Translate a Rust primitive type into its C equivalent.
231-
fn translate_primitive_type(&self, ty: &syn::Ident) -> String {
231+
pub(crate) fn translate_primitive_type(&self, ty: &syn::Ident) -> String {
232232
match ty.to_string().as_str() {
233233
"usize" => "size_t".to_string(),
234234
"isize" => "ssize_t".to_string(),

ctest-next/templates/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
mod generated_tests {
1010
#![allow(non_snake_case)]
1111
#![deny(improper_ctypes_definitions)]
12+
#[allow(unused_imports)]
1213
use std::ffi::{CStr, c_char};
1314
use std::fmt::{Debug, LowerHex};
1415
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

ctest-next/tests/input/hierarchy.out.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
mod generated_tests {
77
#![allow(non_snake_case)]
88
#![deny(improper_ctypes_definitions)]
9+
#[allow(unused_imports)]
910
use std::ffi::{CStr, c_char};
1011
use std::fmt::{Debug, LowerHex};
1112
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

ctest-next/tests/input/macro.out.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
mod generated_tests {
77
#![allow(non_snake_case)]
88
#![deny(improper_ctypes_definitions)]
9+
#[allow(unused_imports)]
910
use std::ffi::{CStr, c_char};
1011
use std::fmt::{Debug, LowerHex};
1112
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

ctest-next/tests/input/simple.out.with-renames.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
mod generated_tests {
77
#![allow(non_snake_case)]
88
#![deny(improper_ctypes_definitions)]
9+
#[allow(unused_imports)]
910
use std::ffi::{CStr, c_char};
1011
use std::fmt::{Debug, LowerHex};
1112
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

ctest-next/tests/input/simple.out.with-skips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
mod generated_tests {
77
#![allow(non_snake_case)]
88
#![deny(improper_ctypes_definitions)]
9+
#[allow(unused_imports)]
910
use std::ffi::{CStr, c_char};
1011
use std::fmt::{Debug, LowerHex};
1112
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

libc-test/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ annotate-snippets = { version = "0.11.5", features = ["testing-colors"] }
2121
[build-dependencies]
2222
cc = "1.2.29"
2323
ctest = { path = "../ctest" }
24+
ctest-next = { path = "../ctest-next" }
2425
regex = "1.11.1"
2526

2627
[features]
@@ -33,6 +34,11 @@ name = "main"
3334
path = "test/main.rs"
3435
harness = false
3536

37+
[[test]]
38+
name = "main_next"
39+
path = "test/main_next.rs"
40+
harness = false
41+
3642
[[test]]
3743
name = "linux-fcntl"
3844
path = "test/linux_fcntl.rs"

0 commit comments

Comments
 (0)