mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
minify and filter embed managed pythons json on compile time (#12967)
## Summary In #10939 I added the generated `crates/uv-python/src/download-metadata-minified.json` file which is a minified version of `crates/uv-python/download-metadata.json`. The main reason for this PR is to avoid bloating the git objects as this is a single-line file. As a bonus, I also filtered the embed json to include only the versions for the compiled target. Which should improve the binary size and performance by a bit. ## Test Plan <!-- How was it tested? -->
This commit is contained in:
parent
481d05d8df
commit
5ee54b4fa3
6 changed files with 45 additions and 45 deletions
41
crates/uv-python/build.rs
Normal file
41
crates/uv-python/build.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
fn process_json(data: &serde_json::Value) -> serde_json::Value {
|
||||
let mut out_data = serde_json::Map::new();
|
||||
|
||||
if let Some(obj) = data.as_object() {
|
||||
for (key, value) in obj {
|
||||
if let Some(variant) = value.get("variant") {
|
||||
// Exclude debug variants for now, we don't support them
|
||||
if variant == "debug" {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
out_data.insert(key.clone(), value.clone());
|
||||
}
|
||||
}
|
||||
|
||||
serde_json::Value::Object(out_data)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let version_metadata = Path::new("download-metadata.json");
|
||||
let target = Path::new("src/download-metadata-minified.json");
|
||||
|
||||
let json_data: serde_json::Value = serde_json::from_str(
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
&fs::read_to_string(version_metadata).expect("Failed to read download-metadata.json"),
|
||||
)
|
||||
.expect("Failed to parse JSON");
|
||||
|
||||
let filtered_data = process_json(&json_data);
|
||||
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
fs::write(
|
||||
target,
|
||||
serde_json::to_string(&filtered_data).expect("Failed to serialize JSON"),
|
||||
)
|
||||
.expect("Failed to write minified JSON");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue