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

Improved resource handling #48

Merged
merged 11 commits into from
Feb 17, 2025
Merged

Improved resource handling #48

merged 11 commits into from
Feb 17, 2025

Conversation

rot256
Copy link
Contributor

@rot256 rot256 commented Jan 28, 2025

In relation to issue #44

This PR reworks the way resources such as the stone-prover binary, are handled by the stone-cli. Previously, build.rs would retrieve the resources and using commands create the required directory structure in $HOME/.stone-cli.

This meant that:

  • Building the stone-cli would change the users environment
  • It could leave stale/old versions of the various resources in .stone-cli which would not get overwritten.
  • You could not build the tool on one machine and run it on another.

The new system ensures that:

  • The stone-cli works even if build on a different machine (e.g. we can distribute binaries now).
  • 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 is:

  • 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.

The negative results of this approach are:

  • Slightly longer startup when using the stone-cli the first time after reboot
  • A larger stone-cli binary.

@rot256 rot256 requested a review from mellowcroc January 28, 2025 19:51
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.
@rot256 rot256 force-pushed the improved-resource-handling branch from c28d739 to 7d56e00 Compare January 28, 2025 19:53
@rot256
Copy link
Contributor Author

rot256 commented Jan 29, 2025

This PR still depends on the cairo1-run binary, perhaps we should merge the large PR on dynamic layouts first and I can get rid of the cairo1-run artifact in the subsequent rebase.

@mellowcroc
Copy link
Collaborator

Code looks really nice, thanks! Left some minor comments.

This PR still depends on the cairo1-run binary, perhaps we should merge the large PR on dynamic layouts first and I can get rid of the cairo1-run artifact in the subsequent rebase.

This sounds good to me.

(RES_STONE_V6_VERIFIER, BIN_STONE_V6_VERIFIER),
];

fn target_dir() -> Result<PathBuf, anyhow::Error> {
Copy link
Collaborator

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
Copy link
Collaborator

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";
Copy link
Collaborator

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";
Copy link
Collaborator

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"
Copy link
Collaborator

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
Copy link
Collaborator

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!(
Copy link
Collaborator

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() {
Copy link
Collaborator

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?

rot256 and others added 3 commits February 3, 2025 16:52
also update to use fork of `integrity` since the original repo is not up-to-date with the current version of the `sncast` command
@rot256
Copy link
Contributor Author

rot256 commented Feb 8, 2025

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 corelibs directory wrong when switching to the new resource handling.

I also got rid of the environment variables used to point to the various resources and the need to call "setup" explicitly.

@mellowcroc
Copy link
Collaborator

Looks good to merge! (The cairo1 failing issue was due to downloading the wrong version of corelibs in build.rs)

@rot256 rot256 merged commit f5eacef into main Feb 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants