atomicdata-dev / atomic-server

An open source headless CMS / real-time database. Powerful table editor, full-text search, and SDKs for JS / React / Svelte.
https://atomicserver.eu
MIT License
950 stars 44 forks source link

Slow build.rs / rust analyzer #913

Open joepio opened 1 month ago

joepio commented 1 month ago

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.

joepio commented 1 month ago

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 commented 3 weeks ago

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/";