Skip to content
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

Slow build.rs / rust analyzer #913

Open
joepio opened this issue Jul 22, 2024 · 3 comments
Open

Slow build.rs / rust analyzer #913

joepio opened this issue Jul 22, 2024 · 3 comments
Assignees

Comments

@joepio
Copy link
Member

joepio commented Jul 22, 2024

Running build.rs has some steps that are sometimes unnecessarily slow. This is particularly annoying because rust-analyzer seems to be slowed down due to this.

  • We could solve this by not running all code in rust analzer flow (not sure how)
  • Or we can identify the most time-consuming part and remove that somehow
@joepio joepio self-assigned this Jul 22, 2024
@joepio
Copy link
Member Author

joepio commented Jul 22, 2024

Skipping the check in build.rs works, lowers refresh time from 7 seconds to about 2 seconds.

    // Check if we're likely running in a check-like context
    let opt_level = std::env::var("OPT_LEVEL").unwrap_or_else(|_| "0".to_string());
    let profile = std::env::var("PROFILE").unwrap_or_else(|_| "release".to_string());

    let is_check_like = profile == "debug" && opt_level == "0";

    if is_check_like {
        println!("cargo:rerun-if-changed=build.rs");
        // Skip the heavy logic
        println!("Skipping build.rs logic for cargo check/clippy.");
    } else {
        const BROWSER_ROOT: &str = "../browser/";

EDIT: No, this does not a good solutions, it too often maps to true (e.g. when running cargo run the first time and there are no assets). I still need a different solution.

joepio added a commit that referenced this issue Jul 23, 2024
joepio added a commit that referenced this issue Jul 23, 2024
@joepio
Copy link
Member Author

joepio commented Aug 23, 2024

New solution:

    println!("cargo:rerun-if-changed=build.rs");

    // Env is set in .vscode/settings.json when rust-analyzer runs
    let is_rust_analyzer = !std::env::var("IS_RUST_ANALYZER")
        .unwrap_or_default()
        .is_empty();

    if is_rust_analyzer {
        p!("Skipping build.rs logic to keep cargo check/clippy fast. If you see this message in some other context: the JS build not run!");
    } else {
        const BROWSER_ROOT: &str = "../browser/";

joepio added a commit that referenced this issue Oct 7, 2024
joepio added a commit that referenced this issue Oct 7, 2024
@Polleps
Copy link
Member

Polleps commented Jan 30, 2025

These settings could help

Image Image

We could add an option to the build command to skip building the frontend. Or if that doesn't work we could use an environment variable

joepio added a commit that referenced this issue Feb 3, 2025
joepio added a commit that referenced this issue Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants