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

feat: multi-crate ELF building support #1750

Merged
merged 33 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
67effd2
feat: allow to specify multiple targets
leruaa Nov 5, 2024
abc16df
fix: don't add an empty target by default
leruaa Nov 5, 2024
edb279d
feat: build only the specified packages
leruaa Nov 6, 2024
d6b7e4b
fix: filter packages on their names
leruaa Nov 7, 2024
74e47b3
chore: remove logs
leruaa Nov 7, 2024
1248f9b
fix: dont build the default package when -p arg is set
leruaa Nov 7, 2024
55f254d
fix: build all targets when in a virtual manifest
leruaa Nov 7, 2024
284d112
feat: moving test programs to test-artifacts crate
leruaa Nov 8, 2024
f1049e6
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 8, 2024
adc4be6
feat: use include_elf! in test-artifacts
leruaa Nov 8, 2024
572103f
fix: move test-artifacts to dev dependency in prover
leruaa Nov 8, 2024
a47324a
chore: install SP1 toolchain for tests
leruaa Nov 8, 2024
13a0e9d
fix: add back feature = "export-tests"
leruaa Nov 8, 2024
c83cc1a
fix: CI
leruaa Nov 8, 2024
2c5efac
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 8, 2024
3ccaeca
feat: remove example ELFs from source control
leruaa Nov 12, 2024
4b30a02
feat: use include_elf! in the examples
leruaa Nov 12, 2024
77a166e
feat: remove dead code
leruaa Nov 12, 2024
135a19a
feat: don't copy ELFs
leruaa Nov 12, 2024
fe18a2b
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 12, 2024
ae97599
fix: typo
leruaa Nov 12, 2024
7162264
fix: sdk examples compilation
leruaa Nov 12, 2024
7c126c8
fix: prover scripts not added as binaries
leruaa Nov 12, 2024
f00c51e
fix: typo
leruaa Nov 12, 2024
c94ecef
fix: Check lock files CI
leruaa Nov 12, 2024
eb67240
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 12, 2024
dbe072d
chore: better comment
leruaa Nov 12, 2024
809b0fb
chore: update book
leruaa Nov 13, 2024
8417382
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 14, 2024
7cae2a8
feat: move u256x2048-mul to test-artifacts
leruaa Nov 14, 2024
a509902
feat: update precomiples doc
leruaa Nov 14, 2024
04aa81f
fix: feedbacks
leruaa Nov 14, 2024
920ce2c
Merge branch 'dev' into aurelien/gro-154-multi-crate-elf
leruaa Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
- name: Setup CI
uses: ./.github/actions/setup

- name: Install SP1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
~/.sp1/bin/sp1up
~/.sp1/bin/cargo-prove prove --version

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -72,6 +78,12 @@ jobs:
- name: Setup CI
uses: ./.github/actions/setup

- name: Install SP1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
~/.sp1/bin/sp1up
~/.sp1/bin/cargo-prove prove --version

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -102,6 +114,12 @@ jobs:
- name: Setup CI
uses: ./.github/actions/setup

- name: Install SP1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
~/.sp1/bin/sp1up
~/.sp1/bin/cargo-prove prove --version

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
Expand All @@ -110,6 +128,14 @@ jobs:
env:
CARGO_INCREMENTAL: 1

- name: Check test-artifacts
uses: actions-rs/cargo@v1
with:
command: check
leruaa marked this conversation as resolved.
Show resolved Hide resolved
args: -p test-artifacts
env:
CARGO_INCREMENTAL: 1

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -155,36 +181,6 @@ jobs:
cd ./examples/
cargo clippy --all-targets --all-features -- -D warnings -A incomplete-features

tests:
name: Tests
runs-on: [runs-on, runner=64cpu-linux-x64, "run-id=${{ github.run_id }}"]
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup CI
uses: ./.github/actions/setup

- name: Install SP1 toolchain
run: |
cargo install --locked --force --path crates/cli
cargo prove install-toolchain

- name: Run cargo fmt
run: |
cd ./tests/
cargo fmt --all -- --check

- name: Run cargo clippy
run: |
cd ./tests/
cargo clippy --all-targets --all-features -- -D warnings -A incomplete-features

- name: Build test ELF files
run: |
cd ./tests/
make

cli:
name: CLI
runs-on: [runs-on, runner=8cpu-linux-x64, "run-id=${{ github.run_id }}"]
Expand Down Expand Up @@ -438,13 +434,14 @@ jobs:
run: |
find -name Cargo.lock -type f -exec rm {} \;

- name: "Build SP1 without lock files"
run: |
cargo build --all --all-targets

# We need the SP1 toolchain to be installed in order to build test-artifacts
- name: Install SP1 toolchain
run: |
cargo run -p sp1-cli -- prove install-toolchain

- name: "Build SP1 without lock files"
run: |
cargo build --all --all-targets

- name: "Build examples without lock files"
run: |
Expand Down
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"crates/verifier",
"crates/stark",
"crates/zkvm/*",
"crates/test-artifacts",
]
exclude = ["examples/target"]
resolver = "2"
Expand Down Expand Up @@ -72,6 +73,9 @@ sp1-lib = { path = "crates/zkvm/lib", version = "3.0.0", default-features = fals
# make sure to update this crate.
sp1-zkvm = { path = "crates/zkvm/entrypoint", version = "3.0.1", default-features = false }

# For testing.
test-artifacts = { path = "crates/test-artifacts", version = "3.0.0" }

# p3
# p3-air = "0.1.4-succinct"
# p3-field = "0.1.4-succinct"
Expand Down
4 changes: 1 addition & 3 deletions book/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Your new project will have the following structure (ignoring the `contracts` fol
├── program
│   ├── Cargo.lock
│   ├── Cargo.toml
│   ├── elf
│   │   └── riscv32im-succinct-zkvm-elf
│   └── src
│   └── main.rs
├── rust-toolchain
Expand Down Expand Up @@ -66,7 +64,7 @@ Before we can run the program inside the zkVM, it must be compiled to a RISC-V e
cd program && cargo prove build
```

which will output the compiled ELF to the file `program/elf/riscv32im-succinct-zkvm-elf`.
which will generate an ELF file under `target/elf-compilation`.

Note: the `build.rs` file in the `script` directory will use run the above command automatically to build the ELF, meaning you don't have to manually run `cargo prove build` every time you make a change to the program!

Expand Down
2 changes: 1 addition & 1 deletion book/writing-programs/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To build a program while developing, simply run the following command in the cra
cargo prove build
```

This will compile the ELF that can be executed in the zkVM and put it in the file `elf/riscv32im-succinct-zkvm-elf`. The output from the command will look something like this:
This will compile the ELF that can be executed in the zkVM. The output from the command will look something like this:

```bash
[sp1] Compiling version_check v0.9.4
Expand Down
35 changes: 25 additions & 10 deletions crates/build/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cargo_metadata::camino::Utf8PathBuf;

use crate::{
command::{docker::create_docker_command, local::create_local_command, utils::execute_command},
utils::{cargo_rerun_if_changed, copy_elf_to_output_dir, current_datetime},
utils::{cargo_rerun_if_changed, current_datetime},
BuildArgs, BUILD_TARGET, HELPER_TARGET_SUBDIR,
};

Expand Down Expand Up @@ -48,12 +48,6 @@ pub fn execute_build_program(

let target_elf_paths = generate_elf_paths(&program_metadata, Some(args))?;

// Temporary backward compatibility with the deprecated behavior of copying the ELF file.
// TODO: add option to turn off this behavior
if target_elf_paths.len() == 1 {
copy_elf_to_output_dir(args, &program_metadata, &target_elf_paths[0].1)?;
}

Ok(target_elf_paths)
}

Expand Down Expand Up @@ -120,20 +114,41 @@ fn generate_elf_paths(
args: Option<&BuildArgs>,
) -> Result<Vec<(String, Utf8PathBuf)>> {
let mut target_elf_paths = vec![];
let packages_to_iterate = if let Some(args) = args {
if !args.packages.is_empty() {
args.packages
.iter()
.map(|wanted_package| {
metadata
.packages
.iter()
.find(|p| p.name == *wanted_package)
.ok_or_else(|| {
anyhow::anyhow!("cannot find package named {}", wanted_package)
})
.map(|p| p.id.clone())
})
.collect::<anyhow::Result<Vec<_>>>()?
} else {
metadata.workspace_default_members.to_vec()
}
} else {
metadata.workspace_default_members.to_vec()
};

for program_crate in metadata.workspace_default_members.iter() {
for program_crate in packages_to_iterate {
let program = metadata
.packages
.iter()
.find(|p| &p.id == program_crate)
.find(|p| p.id == program_crate)
.ok_or_else(|| anyhow::anyhow!("cannot find package for {}", program_crate))?;

for bin_target in program.targets.iter().filter(|t| {
t.kind.contains(&"bin".to_owned()) && t.crate_types.contains(&"bin".to_owned())
}) {
// Filter out irrelevant targets if `--bin` is used.
if let Some(args) = args {
if !args.binary.is_empty() && bin_target.name != args.binary {
if !args.binaries.is_empty() && !args.binaries.contains(&bin_target.name) {
continue;
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/build/src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ pub(crate) fn get_program_build_args(args: &BuildArgs) -> Vec<String> {

build_args.push("-Ztrim-paths".to_string());

if !args.binary.is_empty() {
for p in &args.packages {
build_args.push("-p".to_string());
build_args.push(p.to_string());
}

for b in &args.binaries {
build_args.push("--bin".to_string());
build_args.push(args.binary.clone());
build_args.push(b.to_string());
}

if !args.features.is_empty() {
Expand Down
Loading
Loading