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

Add cargo-build-bpf #13040

Merged
merged 2 commits into from
Oct 22, 2020
Merged

Add cargo-build-bpf #13040

merged 2 commits into from
Oct 22, 2020

Conversation

mvines
Copy link
Member

@mvines mvines commented Oct 21, 2020

cargo-build-bpf is a less opinionated version of sdk/bpf/rust/build.sh. It:

  • Doesn't care if you don't have a Xargo.toml or Cargo.toml in the current directory (both Cargo and Xargo search up the tree)
  • Doesn't impose --no-default-features --features program on you
  • When in the path, slides in to your normal cargo workflow as cargo build-bpf ...
  • Gets installed by solana-install .. so it just works once you get the solana cli installed

Example: build parts of the tree for BPF:

$ cd sdk/
$ ../cargo-build-bpf --no-default-features --features program
$ cd programs/bpf/rust/sysval
$ ../../../../cargo-build-bpf --no-default-features --features program 

(note: once program-sdk/ exists (#12989), these extra args disappear)

TODO

  • Strip object like do.sh does
  • Add --dump flag to obsolete do.sh dump ...

@mvines mvines force-pushed the cbb branch 3 times, most recently from 7627252 to 600050d Compare October 21, 2020 03:42
@mvines
Copy link
Member Author

mvines commented Oct 21, 2020

Welp looks like I need to rewrite cargo-build-bpf in Rust to get at cargo metadata output sanely, probably for the best.

@mvines
Copy link
Member Author

mvines commented Oct 21, 2020

Neat, I cherry-picked this PR on top of #12989 and it works!

~/ws/s1/sdk/program$ ../../cargo-build-bpf 
+ exec /Users/mvines/ws/s1/sdk/bpf/dependencies/xargo/bin/xargo build --target bpfel-unknown-unknown --release
    Finished release [optimized] target(s) in 0.18s

@mvines mvines force-pushed the cbb branch 2 times, most recently from bf9ab9b to f67f8e5 Compare October 21, 2020 21:16
@mvines
Copy link
Member Author

mvines commented Oct 21, 2020

Rewrote cargo-build-bpf in Rust and it's feeling really nice.

~/ws/s1$ cd programs/bpf/rust/sha256
~/ws/s1/programs/bpf/rust/sha256$ cargo build-bpf
Running: /Users/mvines/ws/s1/sdk/bpf/rust/xargo-build.sh --no-default-features --features=program
   Compiling solana-frozen-abi v1.5.0 (/Users/mvines/ws/s1/frozen-abi)
   Compiling solana-sdk v1.5.0 (/Users/mvines/ws/s1/sdk)
   Compiling solana-bpf-rust-sha256 v1.5.0 (/Users/mvines/ws/s1/programs/bpf/rust/sha256)
    Finished release [optimized] target(s) in 4.83s
Running: /Users/mvines/ws/s1/sdk/bpf/scripts/strip.sh /Users/mvines/ws/s1/programs/bpf/target/bpfel-unknown-unknown/release/solana_bpf_rust_sha256.so /Users/mvines/ws/s1/programs/bpf/target/bpfel-unknown-unknown/deploy/solana_bpf_rust_sha256.so

Now wander over to SPL land:

$ cd ~/ws/spl/token/program
$ cargo build-bpf
Running: /Users/mvines/ws/s1/sdk/bpf/rust/xargo-build.sh --no-default-features --features=program
    Finished release [optimized] target(s) in 0.26s
Running: /Users/mvines/ws/s1/sdk/bpf/scripts/strip.sh /Users/mvines/ws/spl/target/bpfel-unknown-unknown/release/spl_token.so /Users/mvines/ws/spl/target/bpfel-unknown-unknown/deploy/spl_token.so

It's smart enough to know when it's not building a cdylib too:

~/ws/s1/frozen-abi$ cargo build-bpf
Note: solana-frozen-abi crate does not contain a cdylib target
Running: /Users/mvines/ws/s1/sdk/bpf/rust/xargo-build.sh
   Compiling solana-frozen-abi v1.5.0 (/Users/mvines/ws/s1/frozen-abi)
    Finished release [optimized] target(s) in 1.06s

and trying to build something silly produces a reasonable error output:

~/ws/s1/validator$ cargo build-bpf
Note: solana-validator crate does not contain a cdylib target
Running: /Users/mvines/ws/s1/sdk/bpf/rust/xargo-build.sh
Error: Failed to find Xargo.toml

Please create a Xargo.toml file in the same directory as your Cargo.toml with
the following contents:

  [target.bpfel-unknown-unknown.dependencies.std]
  features = []

@jackcmay
Copy link
Contributor

Looking good, nice to see the build scripts tucked under a cargo subcommand

@mvines
Copy link
Member Author

mvines commented Oct 22, 2020

This is pretty much ready to land, latest commit deletes do.sh 👢

@mvines mvines added the v1.4 label Oct 22, 2020
@codecov
Copy link

codecov bot commented Oct 22, 2020

Codecov Report

Merging #13040 into master will decrease coverage by 0.0%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##           master   #13040     +/-   ##
=========================================
- Coverage    82.1%    82.1%   -0.1%     
=========================================
  Files         366      366             
  Lines       86237    86237             
=========================================
- Hits        70878    70869      -9     
- Misses      15359    15368      +9     

@mvines
Copy link
Member Author

mvines commented Oct 22, 2020

ooo, green CI. Now's my chance!

@mvines mvines merged commit 61be155 into solana-labs:master Oct 22, 2020
mergify bot added a commit that referenced this pull request Oct 22, 2020
* Add cargo-build-bpf

(cherry picked from commit 07a853d)

* Remove do.sh

(cherry picked from commit 61be155)

Co-authored-by: Michael Vines <[email protected]>
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