Skip to content

Commit

Permalink
Add CI step for checking each icrate feature separately
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 11, 2023
1 parent bea5c51 commit 3609945
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ jobs:
- name: Verify that no files changed
run: git diff --exit-code --submodule=diff

check-icrate-features:
name: Check icrate features
runs-on: macos-12
needs:
- fmt
- lint

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Use system Rust
run: cargo --version

- name: Cache Cargo
uses: actions/cache@v3
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ github.job }}-${{ matrix.name }}-${{ hashFiles('**/Cargo.lock') }}

- name: Check `icrate` with each feature enabled separately
run: cargo run --bin=check_icrate_features --features=run-icrate-check

test-macos:
name: Test macOS 12
runs-on: macos-12
Expand Down
8 changes: 8 additions & 0 deletions crates/header-translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ run = [
"tracing-subscriber",
"tracing-tree",
]
run-icrate-check = [
"toml",
"serde",
]

[dependencies]
clang = { version = "2.0", features = ["runtime", "clang_10_0"], optional = true }
Expand All @@ -31,3 +35,7 @@ proc-macro2 = "1.0.49"
[[bin]]
name = "header-translator"
required-features = ["run"]

[[bin]]
name = "check_icrate_features"
required-features = ["run-icrate-check"]
48 changes: 48 additions & 0 deletions crates/header-translator/src/bin/check_icrate_features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::BTreeMap;
use std::error::Error;
use std::fs;
use std::path::Path;
use std::process::Command;

use serde::Deserialize;

#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
struct CargoToml {
features: BTreeMap<String, Vec<String>>,
}

fn main() -> Result<(), Box<dyn Error>> {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let crates_dir = manifest_dir.parent().unwrap();
let cargo_toml = fs::read_to_string(crates_dir.join("icrate").join("Cargo.toml"))?;

let CargoToml { features } = toml::from_str(&cargo_toml)?;

println!("Testing all Foundation features in `icrate`");

for feature in features.keys() {
if feature.contains("gnustep") {
// Skip GNUStep-related features
continue;
}
if feature.contains("_all") || feature.contains("unstable-frameworks-") {
// Skip "_all" features for now
continue;
}
if !feature.contains("Foundation") {
// Skip all other than "Foundation" features for now
continue;
}

println!("Testing {feature:?}");

let status = Command::new("cargo")
.args(["check", "--package=icrate", "--features=Foundation", "--features", feature])
.current_dir(crates_dir)
.status()?;

assert!(status.success(), "failed running cargo check");
}

Ok(())
}

0 comments on commit 3609945

Please sign in to comment.