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

Adapt test worker to profile flag #2450

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions polkadot/node/core/pvf/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ pub fn validate_candidate(
///
/// NOTE: This should only be called in dev code (tests, benchmarks) as it relies on the relative
/// paths of the built workers.
pub fn build_workers_and_get_paths(is_bench: bool) -> (PathBuf, PathBuf) {
pub fn build_workers_and_get_paths(release_build: bool) -> (PathBuf, PathBuf) {
mrcnski marked this conversation as resolved.
Show resolved Hide resolved
// Only needs to be called once for the current process.
static WORKER_PATHS: OnceLock<Mutex<(PathBuf, PathBuf)>> = OnceLock::new();

fn build_workers(is_bench: bool) {
fn build_workers(release_build: bool) {
let mut build_args = vec![
"build",
"--package=polkadot",
"--bin=polkadot-prepare-worker",
"--bin=polkadot-execute-worker",
];
if is_bench {
// Benches require --release. Regular tests are debug (no flag needed).
if release_build {
build_args.push("--release");
}

let mut cargo = std::process::Command::new("cargo");
let cmd = cargo
// wasm runtime not needed
Expand Down Expand Up @@ -117,7 +117,11 @@ pub fn build_workers_and_get_paths(is_bench: bool) -> (PathBuf, PathBuf) {
}
}

build_workers(is_bench);
// release build
#[cfg(not(debug_assertions))]
let release_build = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct check.

fn main() {
if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=build_type=\"{}\"", profile);
}
}

with

#[cfg(build_type = "debug")]
(using release).

is the proper approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also just forward profile to the build using --profile {profile}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tried tapping PROFILE in the code, not present obviously. Didn't occur to me I should try the build script. Curious, would #[cfg(not(debug_assertions))] not work as expected in some case or is it just too hacky?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are for example enable debug_assertions in release mode for CI. But your code would assume that it is running in Debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know we could that. :)


build_workers(release_build);

Mutex::new((prepare_worker_path, execute_worker_path))
});
Expand Down
Loading