X Tutup
Skip to content

Avoid recompiling vm on every git branch/commit change #7226

@ShaharNaveh

Description

@ShaharNaveh

Summary

We currently have the following code:

println!("cargo:rustc-env=RUSTPYTHON_GIT_HASH={}", git_hash());
println!(
"cargo:rustc-env=RUSTPYTHON_GIT_TIMESTAMP={}",
git_timestamp()
);
println!("cargo:rustc-env=RUSTPYTHON_GIT_TAG={}", git_tag());
println!("cargo:rustc-env=RUSTPYTHON_GIT_BRANCH={}", git_branch());
println!("cargo:rustc-env=RUSTC_VERSION={}", rustc_version());
println!(
"cargo:rustc-env=RUSTPYTHON_TARGET_TRIPLE={}",
env::var("TARGET").unwrap()
);
let mut env_path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
env_path.push("env_vars.rs");
let mut f = std::fs::File::create(env_path).unwrap();
write!(
f,
"sysvars! {{ {} }}",
std::env::vars_os().format_with(", ", |(k, v), f| f(&format_args!("{k:?} => {v:?}")))
)
.unwrap();

This changes the sysvars for every branch switch or git commit, even if you haven't changed anything in the source code.

this works fine, but the DX is bad because this forces a recompilation of the following crates:

  • vm
  • stdlib
  • rustpython

And I believe this is what is also affecting our CI cache.

Proposed solution

(depends on rust-lang/cargo#10271 being merged 🫤)

I suggest adding a new build profile called "dist" that can inherit from "release" and set a custom rustflag cfg like "dist_build", and adjusting the build.rs to use the dynamic values when #[cfg(dist_build)] and populate the fields with dummy static values when #[cfg(not(dist_build))]

That way we can still retain the existing behavior for the binaries provided by our release process, while improving the DX for the majority of time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup