-
Notifications
You must be signed in to change notification settings - Fork 1.6k
☭ Liberate workers! ☭ #7570
base: master
Are you sure you want to change the base?
☭ Liberate workers! ☭ #7570
Changes from 8 commits
cc8e1fd
3c43f00
25f950c
53d035d
5ae83f3
c9329ca
dcbd057
8d50a4c
3ab5657
96d2a90
63ee515
c172aab
85f0a50
c4d8844
a8c98c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "polkadot-execute-worker" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
[[bin]] | ||
name = "polkadot-execute-worker" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
polkadot-node-core-pvf-common = { path = "../../node/core/pvf/common" } | ||
polkadot-node-core-pvf-execute-worker = { path = "../../node/core/pvf/execute-worker" } | ||
|
||
[build-dependencies] | ||
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
fn main() { | ||
substrate_build_script_utils::generate_cargo_keys(); | ||
// For the node/worker version check, make sure we always rebuild the node and binary workers | ||
// when the version changes. | ||
substrate_build_script_utils::rerun_if_git_head_changed(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/// Execute worker binary name | ||
pub const BINARY_NAME: &str = "polkadot-execute-worker"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Execute worker. | ||
|
||
#[cfg(test)] | ||
use polkadot_execute_worker::BINARY_NAME; | ||
|
||
polkadot_node_core_pvf_common::decl_worker_main!( | ||
"execute-worker", | ||
polkadot_node_core_pvf_execute_worker::worker_entrypoint, | ||
env!("SUBSTRATE_CLI_IMPL_VERSION") | ||
); | ||
|
||
#[test] | ||
fn name_test() { | ||
// If binary name ever needs to change, it must be changed in the package manifest | ||
// as well as in the constant value | ||
assert_eq!(env!("CARGO_BIN_NAME"), BINARY_NAME); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "polkadot-prepare-worker" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
[[bin]] | ||
name = "polkadot-prepare-worker" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
polkadot-node-core-pvf-common = { path = "../../node/core/pvf/common" } | ||
polkadot-node-core-pvf-prepare-worker = { path = "../../node/core/pvf/prepare-worker" } | ||
|
||
[build-dependencies] | ||
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
fn main() { | ||
substrate_build_script_utils::generate_cargo_keys(); | ||
// For the node/worker version check, make sure we always rebuild the node and binary workers | ||
// when the version changes. | ||
substrate_build_script_utils::rerun_if_git_head_changed(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/// Prepare worker binary name | ||
pub const BINARY_NAME: &str = "polkadot-prepare-worker"; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Prepare worker. | ||
|
||
#[cfg(test)] | ||
use polkadot_prepare_worker::BINARY_NAME; | ||
|
||
polkadot_node_core_pvf_common::decl_worker_main!( | ||
"prepare-worker", | ||
polkadot_node_core_pvf_prepare_worker::worker_entrypoint, | ||
env!("SUBSTRATE_CLI_IMPL_VERSION") | ||
); | ||
|
||
#[test] | ||
fn name_test() { | ||
// If binary name ever needs to change, it must be changed in the package manifest | ||
// as well as in the constant value | ||
assert_eq!(env!("CARGO_BIN_NAME"), BINARY_NAME); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,59 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Build script to ensure that PVF worker binaries are always built whenever polkadot is built. | ||
//! | ||
//! This is needed because `default-members` does the same thing, but only for `cargo build` -- it | ||
//! does not work for `cargo run`. | ||
|
||
use std::{env::var, path::Path, process::Command}; | ||
|
||
use polkadot_node_core_pvf::{EXECUTE_BINARY_NAME, PREPARE_BINARY_NAME}; | ||
|
||
// TODO: unskip | ||
#[rustfmt::skip] | ||
fn main() { | ||
// Build additional artifacts if a single package build is explicitly requested. | ||
{ | ||
let cargo = dbg!(var("CARGO").expect("`CARGO` env variable is always set by cargo")); | ||
let target = dbg!(var("TARGET").expect("`TARGET` env variable is always set by cargo")); | ||
let profile = dbg!(var("PROFILE").expect("`PROFILE` env variable is always set by cargo")); | ||
let out_dir = dbg!(var("OUT_DIR").expect("`OUT_DIR` env variable is always set by cargo")); | ||
let target_dir = format!("{}/workers", out_dir); | ||
|
||
// assert!(false); | ||
|
||
// TODO: opt-level, debug, features, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this But how do we forward everything from the cargo command that was called. For features we will have to iterate over all env vars to get them and pass them on. For things like opt-level, lto etc. (there are more) I don't see how to pass them on, but I think the child cargo process inherits it from env vars, but am not sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remembered that we eventually want to build these workers with the musl target, so we'll need this script anyways. Also, I realized we don't need support for features, the workers don't use any. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually they are not. I ran We should be able to forward them with rustc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should undo the change removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can experiment with moving the build script to Edit: everything in above comments has been done except this one! |
||
let mut args = vec![ | ||
"build", | ||
"-p", | ||
EXECUTE_BINARY_NAME, | ||
"-p", | ||
PREPARE_BINARY_NAME, | ||
"--target", | ||
&target, | ||
"--target-dir", | ||
&target_dir, | ||
]; | ||
if profile != "debug" { | ||
args.push("--profile"); | ||
args.push(&profile); | ||
} | ||
|
||
Command::new(cargo).args(&args).status().unwrap(); | ||
std::fs::rename( | ||
Path::new(&format!("{target_dir}/{target}/{profile}/{EXECUTE_BINARY_NAME}")), | ||
Path::new(&format!("{target_dir}/../../../../{EXECUTE_BINARY_NAME}")), | ||
) | ||
.unwrap(); | ||
std::fs::rename( | ||
Path::new(&format!("{target_dir}/{target}/{profile}/{PREPARE_BINARY_NAME}")), | ||
Path::new(&format!("{target_dir}/../../../../{PREPARE_BINARY_NAME}")), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
// TODO: is this needed here? | ||
substrate_build_script_utils::generate_cargo_keys(); | ||
// For the node/worker version check, make sure we always rebuild the node and binary workers | ||
// when the version changes. | ||
|
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.
It's the same as
PREPARE_BINARY_NAME
in pvf-host. Can we move it to the pvf/prepare-worker crate, and use that here, for less duplication?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.
Hmm there is an issue with the PVF host depending on the worker binaries in this way. The worker binaries will be recompiled after every commit which will be annoying when hacking on
pvf
crate. I think we can move the binary names intopvf-common
.