Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
default-features Checker (#712)
Browse files Browse the repository at this point in the history
* reformat toml & some fixes

* CI checks `default-features`

* fix as suggestion

* format output
  • Loading branch information
Xavier Lau authored Jul 16, 2021
1 parent 3ae2ed7 commit 604080a
Show file tree
Hide file tree
Showing 72 changed files with 691 additions and 783 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ env:
CARGO_TERM_COLOR: always

jobs:
check-default-features:
name: Check `default-features`
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
- name: Build checker
run: cargo b --manifest-path .maintain/check-default-features/Cargo.toml
- name: Run checker
run: .maintain/check-default-features/target/debug/check-default-features

test:
name: Run Tests
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

# Package Manager
## cargo
/target
target
## npm
node_modules
134 changes: 134 additions & 0 deletions .maintain/check-default-features/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .maintain/check-default-features/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
edition = "2018"
name = "check-default-features"
version = "0.1.0"

[dependencies]
cargo_toml = { version = "0.9.2" }
walkdir = { version = "2.3.2" }
54 changes: 54 additions & 0 deletions .maintain/check-default-features/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// --- std ---
use std::{env, process};
// --- crates.io ---
use cargo_toml::Manifest;
use walkdir::WalkDir;

fn main() {
let mut incomplete_dependencies = vec![];

for e in WalkDir::new(env::current_dir().unwrap())
.into_iter()
.filter_entry(|e| {
let n = e.file_name().to_str().unwrap();

n != "target" && !(n.starts_with('.') && !n.starts_with("./"))
})
.filter_map(|e| e.ok())
{
if e.file_name() == "Cargo.toml" {
let manifest = Manifest::from_path(e.path()).unwrap();

if let Some(std) = manifest.features.get("std") {
for (alias, dependency) in manifest.dependencies.iter() {
if let Some(detail) = dependency.detail() {
if let Some(default_features) = detail.default_features {
if !default_features {
if !std.contains(&format!("{}/std", alias)) {
incomplete_dependencies.push((
alias.to_owned(),
e.path()
.to_str()
.unwrap()
.split("common/")
.last()
.unwrap()
.to_owned(),
));
}
}
}
}
}
}
}
}

if !incomplete_dependencies.is_empty() {
for (alias, path) in incomplete_dependencies {
println!("Incomplete std feature found for `{}` at `{}`", alias, path);
}

process::exit(1);
}
}
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ members = [
"primitives/storage",
]

exclude = [
".maintain/check-default-features",
]

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of
# their debug info might be missing) or to require to be frequently recompiled. We compile these
Expand Down
19 changes: 6 additions & 13 deletions bin/node/bridge-primitives/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ repository = "https://github.com/darwinia-network/darwinia-common/"
version = "2.5.0"

[dependencies]
# bridge
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", branch = "main" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", branch = "main" }
# darwinia
# darwinia-network
drml-primitives = { default-features = false, path = "../../primitives" }
# substrate
# paritytech
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", branch = "main" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", branch = "main" }
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" }
sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" }
sp-core = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" }
Expand All @@ -26,15 +25,9 @@ sp-std = { default-features = false, git = "https://github.com/darwinia-n
default = ["std"]

std = [
"darwinia-std",
"substrate-std",
]

darwinia-std = [
# darwinia-network
"drml-primitives/std",
]

substrate-std = [
# paritytech
"bp-messages/std",
"bp-runtime/std",
"frame-support/std",
Expand Down
Loading

0 comments on commit 604080a

Please sign in to comment.