Skip to content

Commit 5ee406f

Browse files
authored
Merge branch 'main' into issues/4340
2 parents 5145ee8 + 22e7314 commit 5ee406f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5779
-149
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ on:
66
types: [opened, synchronize, reopened]
77

88
env:
9+
CARGO_TERM_COLOR: always
910
CARGO_TERM_VERBOSE: true
1011
LIBC_CI: 1
12+
RUSTDOCFLAGS: -Dwarnings
13+
RUSTFLAGS: -Dwarnings
14+
RUST_BACKTRACE: full
1115

1216
defaults:
1317
run:
@@ -41,6 +45,12 @@ jobs:
4145
TOOLCHAIN: ${{ matrix.toolchain }}
4246
steps:
4347
- uses: actions/checkout@v4
48+
# Remove `-Dwarnings` at the MSRV since lints may be different or buffier
49+
- name: Update RUSTFLAGS
50+
run: |
51+
set -eux
52+
[ "${{ matrix.toolchain }}" = "1.63.0" ] && echo 'RUSTFLAGS=' >> "$GITHUB_ENV" || true
53+
4454
- name: Setup Rust toolchain
4555
run: ./ci/install-rust.sh
4656

@@ -203,6 +213,23 @@ jobs:
203213
export PATH=$HOME/.rust_solaris/bin:$PATH
204214
./ci/run.sh ${{ matrix.target }}
205215
216+
ctest_msrv:
217+
name: Check MSRV
218+
runs-on: ubuntu-24.04
219+
timeout-minutes: 10
220+
env:
221+
RUSTFLAGS: # No need to check warnings on old MSRV, unset `-Dwarnings`
222+
steps:
223+
- uses: actions/checkout@master
224+
- run: |
225+
msrv="$(perl -ne 'print if s/rust-version\s*=\s*"(.*)"/\1/g' ctest/Cargo.toml)"
226+
echo "MSRV: $msrv"
227+
echo "MSRV=$msrv" >> "$GITHUB_ENV"
228+
- name: Install Rust
229+
run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV"
230+
- uses: Swatinem/rust-cache@v2
231+
- run: cargo build -p ctest
232+
206233
# One job that "summarizes" the success state of this pipeline. This can then be added to branch
207234
# protection, rather than having to add each job separately.
208235
success:
@@ -214,6 +241,7 @@ jobs:
214241
- test_tier2
215242
- test_tier2_vm
216243
- verify_build
244+
- ctest_msrv
217245
# Github branch protection is exceedingly silly and treats "jobs skipped because a dependency
218246
# failed" as success. So we have to do some contortions to ensure the job fails if any of its
219247
# dependencies fails.

.github/workflows/release.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# release-plz for the stable 0.2 branch
2+
3+
name: Release-plz
4+
5+
permissions:
6+
pull-requests: write
7+
contents: write
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
14+
jobs:
15+
release-plz:
16+
name: Release-plz
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Install Rust (rustup)
24+
run: rustup update stable --no-self-update && rustup default stable
25+
- name: Run release-plz
26+
uses: MarcoIeni/[email protected]
27+
with:
28+
# On the main branch, only release ctest
29+
manifest_path: ctest/Cargo.toml
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.release-plz.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
[workspace]
1+
[[package]]
2+
name = "libc"
3+
changelog_path = "CHANGELOG.md"
24
git_release_name = "{{ version }}"
35
git_tag_name = "{{ version }}"
46

7+
[[package]]
8+
name = "ctest"
9+
changelog_path = "ctest/CHANGELOG.md"
10+
git_release_name = "ctest-{{ version }}"
11+
git_tag_name = "ctest-{{ version }}"
12+
513
[changelog]
614
body = """
715
## [{{ version | trim_start_matches(pat="v") }}]\

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ rustc-dep-of-std = ["rustc-std-workspace-core"]
140140
extra_traits = []
141141

142142
[workspace]
143-
members = ["libc-test"]
143+
members = [
144+
"ctest",
145+
"ctest-test",
146+
"libc-test",
147+
]

ci/docker/x86_64-unknown-linux-gnu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM ubuntu:24.10
22

33
RUN apt-get update
44
RUN apt-get install -y --no-install-recommends \
5-
gcc libc6-dev ca-certificates linux-headers-generic
5+
gcc g++ libc6-dev ca-certificates linux-headers-generic
66

77
RUN apt search linux-headers
88
RUN ls /usr/src

ci/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ case "$target" in
9393
*) cmd="$cmd --workspace"
9494
esac
9595

96+
# garando_errors only compiles on `cfg(any(unix, windows))`
97+
case "$target" in
98+
*wasm*) cmd="$cmd --exclude ctest --exclude ctest-test"
99+
esac
100+
101+
# # FIXME(ctest): duplicate symbol errors for statics, e.g. T1_static_mut_u8, on Unix-
102+
# # like platforms.
103+
# cast "$(uname -s)" in
104+
# *windows*msvc) ;;
105+
# *apple*) ;;
106+
# *) cmd="$cmd --exclude ctest-test" ;;
107+
# esca
108+
96109
if [ "$target" = "s390x-unknown-linux-gnu" ]; then
97110
# FIXME: s390x-unknown-linux-gnu often fails to test due to timeout,
98111
# so we retry this N times.

ci/style.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ done < "$tmpfile"
6060
rm "$tmpfile"
6161

6262
if shellcheck --version ; then
63-
find . -name '*.sh' -print0 | xargs -0 shellcheck
63+
# FIXME(ctest): update ctest scripts so we don't need to exclude them
64+
find . -name '*.sh' -not -path './ctest/*' -print0 | xargs -0 shellcheck
6465
else
6566
echo "shellcheck not found"
6667
exit 1

ctest-test/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "ctest-test"
3+
version = "0.1.0"
4+
authors = ["Alex Crichton <[email protected]>"]
5+
build = "build.rs"
6+
edition = "2021"
7+
publish = false
8+
9+
[build-dependencies]
10+
ctest = { path = "../ctest" }
11+
cc = "1.0"
12+
13+
[dependencies]
14+
cfg-if = "1.0.0"
15+
libc = { path = ".." }
16+
17+
[[bin]]
18+
name = "t1"
19+
test = false
20+
21+
[[bin]]
22+
name = "t2"
23+
test = false
24+
25+
[[bin]]
26+
name = "t1_cxx"
27+
test = false
28+
29+
[[bin]]
30+
name = "t2_cxx"
31+
test = false

ctest-test/build.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
use std::env;
5+
let opt_level = env::var("OPT_LEVEL")
6+
.ok()
7+
.and_then(|s| s.parse().ok())
8+
.unwrap_or(0);
9+
let profile = env::var("PROFILE").unwrap_or_default();
10+
if profile == "release" || opt_level >= 2 {
11+
println!("cargo:rustc-cfg=optimized");
12+
}
13+
cc::Build::new()
14+
.include("src")
15+
.warnings(false)
16+
.file("src/t1.c")
17+
.compile("libt1.a");
18+
println!("cargo:rerun-if-changed=src/t1.c");
19+
println!("cargo:rerun-if-changed=src/t1.h");
20+
cc::Build::new()
21+
.warnings(false)
22+
.file("src/t2.c")
23+
.compile("libt2.a");
24+
println!("cargo:rerun-if-changed=src/t2.c");
25+
println!("cargo:rerun-if-changed=src/t2.h");
26+
ctest::TestGenerator::new()
27+
.header("t1.h")
28+
.include("src")
29+
.fn_cname(|a, b| b.unwrap_or(a).to_string())
30+
.type_name(move |ty, is_struct, is_union| match ty {
31+
"T1Union" => ty.to_string(),
32+
"Transparent" => ty.to_string(),
33+
t if is_struct => format!("struct {}", t),
34+
t if is_union => format!("union {}", t),
35+
t => t.to_string(),
36+
})
37+
.volatile_item(t1_volatile)
38+
.array_arg(t1_arrays)
39+
.skip_roundtrip(|n| n == "Arr")
40+
.generate("src/t1.rs", "t1gen.rs");
41+
ctest::TestGenerator::new()
42+
.header("t2.h")
43+
.include("src")
44+
.type_name(move |ty, is_struct, is_union| match ty {
45+
"T2Union" => ty.to_string(),
46+
t if is_struct => format!("struct {}", t),
47+
t if is_union => format!("union {}", t),
48+
t => t.to_string(),
49+
})
50+
.skip_roundtrip(|_| true)
51+
.generate("src/t2.rs", "t2gen.rs");
52+
53+
println!("cargo::rustc-check-cfg=cfg(has_cxx)");
54+
if !cfg!(unix) || Command::new("c++").arg("v").output().is_ok() {
55+
// A C compiler is always available, but these are only run if a C++ compiler is
56+
// also available.
57+
println!("cargo::rustc-cfg=has_cxx");
58+
59+
ctest::TestGenerator::new()
60+
.header("t1.h")
61+
.language(ctest::Lang::CXX)
62+
.include("src")
63+
.fn_cname(|a, b| b.unwrap_or(a).to_string())
64+
.type_name(move |ty, is_struct, is_union| match ty {
65+
"T1Union" => ty.to_string(),
66+
"Transparent" => ty.to_string(),
67+
t if is_struct => format!("struct {}", t),
68+
t if is_union => format!("union {}", t),
69+
t => t.to_string(),
70+
})
71+
.volatile_item(t1_volatile)
72+
.array_arg(t1_arrays)
73+
.skip_roundtrip(|n| n == "Arr")
74+
.generate("src/t1.rs", "t1gen_cxx.rs");
75+
ctest::TestGenerator::new()
76+
.header("t2.h")
77+
.language(ctest::Lang::CXX)
78+
.include("src")
79+
.type_name(move |ty, is_struct, is_union| match ty {
80+
"T2Union" => ty.to_string(),
81+
t if is_struct => format!("struct {}", t),
82+
t if is_union => format!("union {}", t),
83+
t => t.to_string(),
84+
})
85+
.skip_roundtrip(|_| true)
86+
.generate("src/t2.rs", "t2gen_cxx.rs");
87+
} else {
88+
println!("cargo::warning=skipping C++ tests");
89+
}
90+
}
91+
92+
fn t1_volatile(i: ctest::VolatileItemKind) -> bool {
93+
use ctest::VolatileItemKind::*;
94+
match i {
95+
StructField(ref n, ref f) if n == "V" && f == "v" => true,
96+
Static(ref n) if n == "vol_ptr" => true,
97+
FunctionArg(ref n, 0) if n == "T1_vol0" => true,
98+
FunctionArg(ref n, 1) if n == "T1_vol2" => true,
99+
FunctionRet(ref n) if n == "T1_vol1" || n == "T1_vol2" => true,
100+
Static(ref n) if n == "T1_fn_ptr_vol" => true,
101+
_ => false,
102+
}
103+
}
104+
105+
fn t1_arrays(n: &str, i: usize) -> bool {
106+
match n {
107+
"T1r" | "T1s" | "T1t" | "T1v" if i == 0 => true,
108+
_ => false,
109+
}
110+
}

ctest-test/src/bin/t1.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![cfg(not(test))]
2+
#![deny(warnings)]
3+
4+
use ctest_test::t1::*;
5+
use libc::*;
6+
7+
include!(concat!(env!("OUT_DIR"), "/t1gen.rs"));

ctest-test/src/bin/t1_cxx.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![cfg(not(test))]
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(has_cxx)] {
5+
use ctest_test::t1::*;
6+
use libc::*;
7+
8+
include!(concat!(env!("OUT_DIR"), "/t1gen_cxx.rs"));
9+
} else {
10+
fn main() {}
11+
}
12+
}

ctest-test/src/bin/t2.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![cfg(not(test))]
2+
#![deny(warnings)]
3+
4+
use ctest_test::t2::*;
5+
6+
include!(concat!(env!("OUT_DIR"), "/t2gen.rs"));

ctest-test/src/bin/t2_cxx.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![cfg(not(test))]
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(has_cxx)] {
5+
use ctest_test::t2::*;
6+
7+
include!(concat!(env!("OUT_DIR"), "/t2gen_cxx.rs"));
8+
} else {
9+
fn main() {}
10+
}
11+
}

ctest-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod t1;
2+
pub mod t2;

0 commit comments

Comments
 (0)