aya: Add cargo-public-api

Adds cargo-public-api. This allows for public API changes to get caught
by cargo test, requiring new changes to be "blessed" by using:

   UPDATE_EXPECT=1 cargo test

When this file is changed, Alessandro will need to review the PR.

The change to aya/src/maps/mod.rs is due to public-api requiring
serde_json, which has cause the following type issue:

type annotations needed
multiple `impl`s satisfying `usize: std::cmp::PartialEq<_>`
  found in the following crates: `core`, `serde_json`:
- impl std::cmp::PartialEq for usize;
- impl std::cmp::PartialEq<serde_json::value::Value> for usize;

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
reviewable/pr682/r2
Dave Tucker 2 years ago
parent ec5ff01e41
commit c8200edd6a

@ -73,8 +73,10 @@ num_enum = { version = "0.6", default-features = false }
object = { version = "0.31", default-features = false }
parking_lot = { version = "0.12.0", default-features = false }
proc-macro2 = { version = "1", default-features = false }
public-api = { version = "0.31.2", default-features = false }
quote = { version = "1", default-features = false }
rbpf = { version = "0.2.0", default-features = false }
rustdoc-json = { version = "0.8.6", default-features = false }
syn = { version = "2", default-features = false }
tempfile = { version = "3", default-features = false }
testing_logger = { version = "0.1.1", default-features = false }

@ -29,7 +29,10 @@ tokio = { workspace = true, features = ["rt"], optional = true }
[dev-dependencies]
assert_matches = { workspace = true }
cargo_metadata = { workspace = true }
futures = { workspace = true }
public-api = { workspace = true }
rustdoc-json = { workspace = true }
tempfile = { workspace = true }
[features]

@ -58,3 +58,47 @@ pub mod util;
pub use bpf::*;
pub use obj::btf::{Btf, BtfError};
pub use object::Endianness;
#[cfg(test)]
mod tests {
use cargo_metadata::{Metadata, MetadataCommand};
use std::{
env,
fs::{read_to_string, File},
io::Write,
};
#[test]
#[cfg_attr(miri, ignore = "uses open() which is not supported by miri")]
fn public_api() {
let rustdoc_json = rustdoc_json::Builder::default()
.toolchain("nightly")
.package("aya")
.all_features(true)
.build()
.unwrap();
let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
.build()
.unwrap();
let metadata = MetadataCommand::new()
.no_deps()
.exec()
.expect("failed to run cargo metadata");
let Metadata { workspace_root, .. } = &metadata;
let path = workspace_root.join("aya/src/public-api.txt");
if env::var("UPDATE_EXPECT").is_ok() {
let mut f = File::create(&path).expect("failed to create aya/src/public-api.txt");
f.write_all(public_api.to_string().as_bytes())
.expect("failed to write aya/src/public-api.txt");
}
let current_api = read_to_string(path).expect("failed to read aya/src/public-api.txt");
if current_api != public_api.to_string() {
panic!("public api has changed. please bless by re-running tests with UPDATE_EXPECT=1");
}
}
}

@ -224,7 +224,7 @@ fn maybe_warn_rlimit() {
let limit = unsafe { limit.assume_init() };
let limit: RlimitSize = RlimitSize(limit.rlim_cur.try_into().unwrap());
if limit.0 == RLIM_INFINITY.try_into().unwrap() {
if limit.0 == usize::try_from(RLIM_INFINITY).unwrap() {
return;
}
warn!(

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save