-
Notifications
You must be signed in to change notification settings - Fork 3
EIM-370 embed idf_versions file on build time #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EIM-370 embed idf_versions file on build time #304
Conversation
Summary of ChangesHello @Hahihula, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a robust mechanism for handling ESP-IDF version data. It ensures that the application has access to the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a fallback mechanism to use a cached version of idf_versions.json from build time if fetching it at runtime fails. This is a great addition for offline usability. The implementation in build.rs is sound. However, I've found a critical issue in the fallback logic within src/lib/idf_versions.rs that would cause a panic. I've also included a couple of medium-severity suggestions to improve code quality by removing duplication and a minor inefficiency.
| let versions: Releases = serde_json::from_str(&cached_idf_versions).map_err(|e| { | ||
| format!( | ||
| "Error parsing cached IDF versions JSON: {}", | ||
| e.to_string() | ||
| ) | ||
| })?; |
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 fallback logic will fail at runtime. When download_idf_versions fails, build.rs sets CACHED_IDF_VERSIONS to "{}". Deserializing an empty JSON object into the Releases struct will fail because its fields (VERSIONS, IDF_TARGETS, RELEASES) are not marked with #[serde(default)].
To fix this, you need to update the Releases struct definition (around line 32) to allow deserialization from an empty object:
#[derive(Debug, Deserialize, Clone, Default)]
pub struct Releases {
#[serde(default)]
pub VERSIONS: Vec<Version>,
#[serde(default)]
pub IDF_TARGETS: Vec<IDFTarget>,
#[serde(default)]
pub RELEASES: std::collections::HashMap<String, Release>,
}
src-tauri/build.rs
Outdated
| } | ||
|
|
||
| async fn download_idf_versions() -> Result<String, Box<dyn Error>> { | ||
| let url = "https://dl.espressif.com/dl/esp-idf/idf_versions.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.
This URL is hardcoded here and also defined as a constant in src/lib/idf_versions.rs. This duplication can lead to inconsistencies. Consider defining the constant in this build script and passing it to the library crate as a compile-time environment variable to maintain a single source of truth.
For example, you could define const IDF_VERSIONS_URL: &str = "..."; at the top of build.rs, use it here, and also pass it to the crate with println!("cargo:rustc-env=IDF_VERSIONS_URL={}", IDF_VERSIONS_URL);. Then, in src/lib/idf_versions.rs, you can define the constant as pub const IDF_VERSIONS_URL: &str = env!("IDF_VERSIONS_URL");.
b5f2542 to
0306ac1
Compare
a9d62da to
ff13c16
Compare
ff13c16 to
7dd5c12
Compare
Fabricio-ESP
left a comment
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.
Confirmed working, offline installation now does not require any internet connection.
Offline packages tested on Windows, Ubuntu and MacOS.
No description provided.