-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improved resource handling #48
Conversation
This commit reworks the way resources such a the stone-prover binary, are handled by the stone-cli. The new system ensures that: - The stone-cli works even if build on a different machine and moved. - Does not modify the users home directory - Allows uninstalling by using `cargo uninstall` (simply deleting the stone-cli binary will do). Overall, the approach taken: - Retrieve all the resources for the build - Create the desired directory structure in build.rs - Create a tarball with the directory structure - Embed the tarball inside the stone-cli binary - Upon execution of the stone-cli binary extract the tarball to a "temporary" directory, ensuring however that this is only done on the first execution, as oppose to creating a fresh "TempDir" every time.
c28d739
to
7d56e00
Compare
Use the OUT_DIR instead of src/
Use that rename is atomic, rather than creating a flag file
This PR still depends on the |
Code looks really nice, thanks! Left some minor comments.
This sounds good to me. |
(RES_STONE_V6_VERIFIER, BIN_STONE_V6_VERIFIER), | ||
]; | ||
|
||
fn target_dir() -> Result<PathBuf, anyhow::Error> { |
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.
seems like we can guarantee CARGO_TARGET_DIR
value by setting it on .cargo/config.toml
?
...
[build]
target-dir = "path/to/target"
build.rs
Outdated
let tar = flate2::write::GzEncoder::new(tar_gz, flate2::Compression::default()); | ||
let mut archive = tar::Builder::new(tar); | ||
|
||
// decompress the corelib tarball and add "cario/corelib" as "corelib" to the archive |
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.
nit) cario -> cairo
build.rs
Outdated
const RES_STONE_V6_PROVER: &str = "bin:v6-prover"; | ||
const RES_STONE_V5_VERIFIER: &str = "bin:v5-verifier"; | ||
const RES_STONE_V6_VERIFIER: &str = "bin:v6-verifier"; | ||
const RES_CAIRO_1RUN: &str = "tar-gz:cairo1-run"; |
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.
nit) RES_CAIRO_1RUN -> RES_CAIRO1_RUN?
build.rs
Outdated
const BIN_STONE_V6_PROVER: &str = "cpu_air_prover_v6"; | ||
const BIN_STONE_V5_VERIFIER: &str = "cpu_air_verifier_v5"; | ||
const BIN_STONE_V6_VERIFIER: &str = "cpu_air_verifier_v6"; | ||
const BIN_CAIRO_1RUN: &str = "cairo1-run"; |
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.
ditto
src/resources.rs
Outdated
@@ -0,0 +1,18 @@ | |||
// This file is generated by build.rs" |
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.
nit) remove "
src/setup.rs
Outdated
]; | ||
|
||
fn copy_resources(uid: u32, mode: u32) -> anyhow::Result<()> { | ||
// if the flag file exists, return: setup is already done |
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.
flag file -> resource root directory
src/setup.rs
Outdated
let dir = resources::resource_dir(meta.uid()); | ||
for (env_name, filename) in ENV_CONFIGURE.iter() { | ||
let full_path = dir.join(filename); | ||
debug_assert!( |
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.
does this not need to be assert!
?
src/setup.rs
Outdated
"File not found: {:?}", | ||
full_path | ||
); | ||
if std::env::var(env_name).is_err() { |
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.
should we overwrite instead of not writing if it doesn't exist?
also update to use fork of `integrity` since the original repo is not up-to-date with the current version of the `sncast` command
I attempted to merge with the dynamic layout PR (merge with main). However, I'm getting errors on all the cairo1 related tests. Probably because I setup the I also got rid of the environment variables used to point to the various resources and the need to call "setup" explicitly. |
Looks good to merge! (The cairo1 failing issue was due to downloading the wrong version of corelibs in build.rs) |
In relation to issue #44
This PR reworks the way resources such as the
stone-prover
binary, are handled by thestone-cli
. Previously,build.rs
would retrieve the resources and using commands create the required directory structure in$HOME/.stone-cli
.This meant that:
stone-cli
would change the users environment.stone-cli
which would not get overwritten.The new system ensures that:
cargo uninstall
(simply deleting the stone-cli binary will do).Overall, the approach taken is:
The negative results of this approach are:
stone-cli
the first time after rebootstone-cli
binary.