Skip to content

Commit 81410d5

Browse files
committed
ctest: Set the ctest-next to MSRV 1.88, bump to edition 2024
`let_chains` is a feature only available in edition 2024 and stabilized in 1.88, so this allows us to make use of them. Needed fixes include substituting `gen` to `gen_` since that is now a reserved keyword, and making `env::set_var` unsafe (this needs to be fixed). There are also automatic changes for format edition 2024 (e.g. import reordering). This needs a small CI hack where we temporarily remove the `ctest-next` crate from the workspace because old Cargo doesn't recognize "2024" as a valid edition.
1 parent 81e4700 commit 81410d5

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ jobs:
8585
- name: Execute build.sh
8686
run: |
8787
set -eux
88-
# Remove `-Dwarnings` at the MSRV since lints may be different
89-
[ "${{ matrix.toolchain }}" = "1.63.0" ] && export RUSTFLAGS=""
88+
if [ "${{ matrix.toolchain }}" = "1.63.0" ]; then
89+
# Remove `-Dwarnings` at the MSRV since lints may be different
90+
export RUSTFLAGS=""
91+
# Remove `ctest-next` which uses the 2024 edition
92+
perl -i -ne 'print unless /"ctest-next",/' Cargo.toml
93+
fi
94+
9095
./ci/verify-build.sh
9196
- name: Target size after job completion
9297
run: du -sh target | sort -k 2
@@ -314,6 +319,8 @@ jobs:
314319
echo "MSRV=$msrv" >> "$GITHUB_ENV"
315320
- name: Install Rust
316321
run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV"
322+
- name: Remove edition 2024 crates
323+
run: perl -i -ne 'print unless /"ctest-next",/' Cargo.toml
317324
- uses: Swatinem/rust-cache@v2
318325
- run: cargo build -p ctest
319326

ctest-next/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "ctest-next"
33
version = "0.1.0"
4-
edition = "2021"
5-
rust-version = "1.87"
4+
edition = "2024"
5+
rust-version = "1.88"
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/rust-lang/libc"
88
publish = false

ctest-next/src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::fs::{canonicalize, File};
2+
use std::fs::{File, canonicalize};
33
use std::io::Write;
44
use std::path::{Path, PathBuf};
55
use std::process::Command;

ctest-next/src/translator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ pub(crate) enum TranslationErrorKind {
6767
HasLifetimes,
6868

6969
/// A type that is not ffi compatible was found.
70-
#[error("this type is not guaranteed to have a C compatible layout. See improper_ctypes_definitions lint")]
70+
#[error(
71+
"this type is not guaranteed to have a C compatible layout. See improper_ctypes_definitions lint"
72+
)]
7173
NotFfiCompatible,
7274
}
7375

ctest-next/tests/basic.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::{Path, PathBuf};
22
use std::{env, fs};
33

4-
use ctest_next::{Result, TestGenerator, __compile_test, __run_test, generate_test};
4+
use ctest_next::{__compile_test, __run_test, Result, TestGenerator, generate_test};
55
use pretty_assertions::assert_eq;
66

77
// Headers are found relevative to the include directory, all files are generated
@@ -12,7 +12,8 @@ use pretty_assertions::assert_eq;
1212
/// The files will be generated in a unique temporary directory that gets
1313
/// deleted when it goes out of scope.
1414
fn default_generator(opt_level: u8, header: &str) -> Result<(TestGenerator, tempfile::TempDir)> {
15-
env::set_var("OPT_LEVEL", opt_level.to_string());
15+
// FIXME(mbyx): Remove this in favor of not-unsafe alternatives.
16+
unsafe { env::set_var("OPT_LEVEL", opt_level.to_string()) };
1617
let temp_dir = tempfile::tempdir()?;
1718
let mut generator = TestGenerator::new();
1819
generator
@@ -44,13 +45,13 @@ fn bless_equal(new_file: impl AsRef<Path>, old_file: impl AsRef<Path>) {
4445
/// Additionally, if this test is not being ran on a cross compiled target, it will compile
4546
/// and run the generated tests as well.
4647
fn check_entrypoint(
47-
gen: &mut TestGenerator,
48+
gen_: &mut TestGenerator,
4849
out_dir: tempfile::TempDir,
4950
crate_path: impl AsRef<Path>,
5051
library_path: impl AsRef<Path>,
5152
include_path: impl AsRef<Path>,
5253
) {
53-
let output_file = gen.generate_files(&crate_path, &library_path).unwrap();
54+
let output_file = gen_.generate_files(&crate_path, &library_path).unwrap();
5455

5556
let rs = include_path
5657
.as_ref()
@@ -63,7 +64,7 @@ fn check_entrypoint(
6364
bless_equal(output_file.with_extension("c"), c);
6465

6566
if env::var("TARGET_PLATFORM") == env::var("HOST_PLATFORM") {
66-
generate_test(gen, &crate_path, &library_path).unwrap();
67+
generate_test(gen_, &crate_path, &library_path).unwrap();
6768
let test_binary = __compile_test(&out_dir, crate_path, library_path).unwrap();
6869
let result = __run_test(test_binary);
6970
if let Err(err) = &result {
@@ -79,8 +80,8 @@ fn test_entrypoint_hierarchy() {
7980
let crate_path = include_path.join("hierarchy/lib.rs");
8081
let library_path = "hierarchy.out.a";
8182

82-
let (mut gen, out_dir) = default_generator(1, "hierarchy.h").unwrap();
83-
check_entrypoint(&mut gen, out_dir, crate_path, library_path, include_path);
83+
let (mut gen_, out_dir) = default_generator(1, "hierarchy.h").unwrap();
84+
check_entrypoint(&mut gen_, out_dir, crate_path, library_path, include_path);
8485
}
8586

8687
#[test]
@@ -89,10 +90,10 @@ fn test_skip_simple() {
8990
let crate_path = include_path.join("simple.rs");
9091
let library_path = "simple.out.with-skips.a";
9192

92-
let (mut gen, out_dir) = default_generator(1, "simple.h").unwrap();
93-
gen.skip_const(|c| c.ident() == "B");
93+
let (mut gen_, out_dir) = default_generator(1, "simple.h").unwrap();
94+
gen_.skip_const(|c| c.ident() == "B");
9495

95-
check_entrypoint(&mut gen, out_dir, crate_path, library_path, include_path);
96+
check_entrypoint(&mut gen_, out_dir, crate_path, library_path, include_path);
9697
}
9798

9899
#[test]
@@ -101,10 +102,10 @@ fn test_map_simple() {
101102
let crate_path = include_path.join("simple.rs");
102103
let library_path = "simple.out.with-renames.a";
103104

104-
let (mut gen, out_dir) = default_generator(1, "simple.h").unwrap();
105-
gen.rename_constant(|c| (c.ident() == "B").then(|| "C_B".to_string()));
105+
let (mut gen_, out_dir) = default_generator(1, "simple.h").unwrap();
106+
gen_.rename_constant(|c| (c.ident() == "B").then(|| "C_B".to_string()));
106107

107-
check_entrypoint(&mut gen, out_dir, crate_path, library_path, include_path);
108+
check_entrypoint(&mut gen_, out_dir, crate_path, library_path, include_path);
108109
}
109110

110111
#[test]
@@ -113,16 +114,16 @@ fn test_entrypoint_macro() {
113114
let crate_path = include_path.join("macro.rs");
114115
let library_path = "macro.out.a";
115116

116-
let (mut gen, out_dir) = default_generator(1, "macro.h").unwrap();
117-
check_entrypoint(&mut gen, out_dir, crate_path, library_path, include_path);
117+
let (mut gen_, out_dir) = default_generator(1, "macro.h").unwrap();
118+
check_entrypoint(&mut gen_, out_dir, crate_path, library_path, include_path);
118119
}
119120

120121
#[test]
121122
fn test_entrypoint_invalid_syntax() {
122123
let crate_path = "tests/input/invalid_syntax.rs";
123-
let mut gen = TestGenerator::new();
124+
let mut gen_ = TestGenerator::new();
124125

125-
let fails = generate_test(&mut gen, crate_path, "invalid_syntax.out").is_err();
126+
let fails = generate_test(&mut gen_, crate_path, "invalid_syntax.out").is_err();
126127

127128
assert!(fails)
128129
}

0 commit comments

Comments
 (0)