-
Notifications
You must be signed in to change notification settings - Fork 9
feat: compliant cli checker for correct variants and dependencies #121
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
bcc946d
to
bd4f49f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice to have this! Added a bunch of comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making all the changes! Looks very good already, added some more comments on the new changes.
kernel-compliance-check/build.rs
Outdated
println!("cargo:warning=Fetching remote variants JSON..."); | ||
let url = "https://raw.githubusercontent.com/huggingface/kernel-builder/refs/heads/main/build-variants.json"; | ||
|
||
let mut remote_variants_json = String::new(); | ||
|
||
match ureq::get(url).call() { | ||
Ok(resp) => { | ||
match resp.into_reader().read_to_string(&mut remote_variants_json) { | ||
Ok(_) => { | ||
println!( | ||
"cargo:warning=Successfully fetched remote variants ({} bytes)", | ||
remote_variants_json.len() | ||
); | ||
} | ||
Err(e) => { | ||
println!("cargo:warning=Error reading response body: {e}"); | ||
// Instead of returning an empty JSON, provide fallback content | ||
remote_variants_json = String::from("{}"); | ||
} | ||
} | ||
} | ||
Err(e) => { | ||
println!("cargo:warning=Error fetching remote variants: {e}"); | ||
// Provide fallback content | ||
remote_variants_json = String::from("{}"); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incompatible with Nix, we cannot have network access during the build. We should make the JSON file part of the compliance checker source files. I think (but we need to check) if we add a symlink to the JSON file in e.g. src
, cargo publish
would replace the symlink by the contents of the file. In that way we can keep it in the current repo location, but also include it in the crate (when uploading to crates.io).
I also don't think we should be writing Rust code through a string, we don't get syntax checking, completion, etc. We should use include_str
or include_bytes
and then serde-parse it. The cost of doing so is going to be near-zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point, I've updated with a much more simple solution to include_str of the build_variants.json
at the root of this repo, and added a symlink to copy that file into src (need to confirm that publish will work too), but the build.rs is now removed and is much more clean
kernel-compliance-check/build.rs
Outdated
VARIANTS_CACHE.get_or_init(|| {{ | ||
serde_json::from_str(VARIANTS_DATA).unwrap_or_else(|_| {{ | ||
// Provide a fallback empty object if parsing fails | ||
serde_json::json!({{}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the data comes from the repo, we know it's going to be in-sync and we can panic when the JSON is invalid (since it's a bug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated/removed in latest changes
kernel-compliance-check/src/lib.rs
Outdated
cmd.arg("--force"); | ||
} | ||
|
||
println!("Using huggingface-cli to download repository"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: I would print such messages to stderr
. For me stdout
is only for output that you may want to pipe to other processes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, ive updated many of the print lines to eprintln
kernel-compliance-check/src/lib.rs
Outdated
|
||
// Parse object file | ||
let file = object::File::parse(&*binary_data) | ||
.map_err(|e| eyre::eyre!("Cannot parse object file: {}: {}", so_path.display(), e))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all such cases I always use with_context
in place of map_err
. The original error is printed as well as part of the chain when the error is bubbled up to outside main
. I think error chains are nicer than errors nested in a string (e.g. imagine the caller of this function wrapping it in a string again).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nice thats a great recommendation, i've updated all of the map_err to with_context, that is a very nice error improvement. Thanks!
|
||
/// Manylinux version to check against | ||
#[arg(short, long, default_value = "manylinux_2_28")] | ||
manylinux: ManylinuxVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stringly-type this to avoid having to keep the enum in sync with the data from the manylinux project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updated in the latest commits. Thanks!
40d8da1
to
b8026b1
Compare
…r, stringly type manylinux, respect env cache var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
This PR adds a new cli tool
compliant
that checks kernels for compliance.check args
Usage
list all kernels (in cache and have a build variant)
$ compliant list . ├── kernels-community/activation ├── kernels-community/deformable-detr ├── kernels-community/flash-mla ├── kernels-community/quantization ╰── 4 kernel repositories found
checking a repo
with
--long
output for variant specific abi compatibilityscreenshot to show coloring
Checks
build
dir