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

chore(cargo-build-sbf): allow building from nix store #4061

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dzmitry-lahoda
Copy link

@dzmitry-lahoda dzmitry-lahoda commented Dec 11, 2024

Problem

Previously I enabled using sbf compiler from nix and downloaded via nix #3762,
but still had to side effect into HOME to allow sbf builds.

Summary of Changes

In this PR I fully eliminate any side effects to HOME,
following nix guidance not to side effect to HOME and also allowed build programs with nix cache.

If no --no-rustup option provided, all works a before.

cargo run -- --skip-tools-install --no-rustup --sbf-sdk=/nix/store/zmr52j81db288nrg7arvn98-whatever --tools-version=v1.43

@mergify mergify bot requested a review from a team December 11, 2024 16:48
Copy link

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution again! I'm a fan of the change, but I want to be sure that I understand how to use it.

If you pass --no-rustup, then for it to work, you must either set RUSTC, ie. RUSTC=/path/to/solana/rustc cargo build-sbf..., or ensure that the default rustc in your PATH is the Solana version of rustc. Is that correct?

Otherwise, just a few nits, it looks good to me

sdk/cargo-build-sbf/src/main.rs Outdated Show resolved Hide resolved
sdk/cargo-build-sbf/src/main.rs Outdated Show resolved Hide resolved
sdk/cargo-build-sbf/src/main.rs Outdated Show resolved Hide resolved
@@ -1048,6 +1066,13 @@ fn main() {
.takes_value(false)

Choose a reason for hiding this comment

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

I can't comment higher up, but let rust_base_version = get_base_rust_version(...) on line 995 will use homedir to find the tools version. Since this is just for logging with CI caches, I assume it's OK for it to fail and return an empty string, but I wanted to flag it either way.

Copy link
Author

Choose a reason for hiding this comment

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

in nix wrapper and override I set exact version of tools and path it to cargo-build-sbf.

if that is okey return empty string will do it, so

Copy link
Author

@dzmitry-lahoda dzmitry-lahoda Dec 13, 2024

Choose a reason for hiding this comment

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

    let rust_base_version = get_base_rust_version(DEFAULT_PLATFORM_TOOLS_VERSION);
    let version = format!(
        "{}\nplatform-tools {}\n{}",
        crate_version!(),
        DEFAULT_PLATFORM_TOOLS_VERSION,
        rust_base_version,
    );
    let matches = clap::Command::new(crate_name!())
        .about(crate_description!())
        .version(version.as_str())

oh, recalled what problem was.

  1. I can invoke cargo build sbf in nix even if this lines runs. no worries.
  2. I cannot not invoke it in case of nix, because cli parameters not yet parsed. until i change usage of clap and provide own version command. i want to avoid doing anything with next in this PR .version(version.as_str())

but seems solution which will be backward compatible and provide correct tools and rust version is to do custom command and resolve

bash-5.1$ cargo run -- --version
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
     Running `/home/dz/github.com/anza-xyz/agave/target/debug/cargo-build-sbf --version`
solana-cargo-build-sbf 2.2.0
platform-tools v1.43

bash-5.1$ 

and doing --version --WHATEVER_PARAMETERS_OVERRIDE_RUST as option.

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Dec 12, 2024

if you pass --no-rustup, then for it to work, you must either set RUSTC, ie. RUSTC=/path/to/solana/rustc cargo build-sbf..., or ensure that the default rustc in your PATH is the Solana version of rustc. Is that correct?

yes. and that is what exactly nix does well.

  1. nix consumer of cargo-build-sbf will wrap it https://github.com/arijoon/solana-nix/blob/52dbde3e8bb09fbee644c371de930d5374c3cb8c/solana-cli.nix#L103 with whatever parameters.
  2. it will use default platforms tools for agave release, but allow override with https://ryantm.github.io/nixpkgs/using/overrides/ . from this override platforms tool will be taken and relevant cargo/rust
  3. final consumer can override platform-tools as he pleased too.

specifically i just upstreaming this patch https://github.com/arijoon/solana-nix/blob/52dbde3e8bb09fbee644c371de930d5374c3cb8c/cargo-build-sbf.patch so that nix and non nix (default) solution work from same release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants