Skip to content

Commit 1ec4308

Browse files
feat: cargo CLI update target directory (#1662)
Resolves INT-3882, and records changes in the book as per INT-4038. Most importantly, reworks command outputs to primarily use the `target/` directory that Cargo uses and assumes full control over. - User can specify `target_dir`; if unspecified, `cargo openvm` will use the Cargo default - Keys are stored in `${target_dir}/openvm/`, while all other artifacts are stored in `${target_dir}/openvm/${profile}` - User can copy outputs to `${output_dir}` - **NOTE** - generated proofs are stored at `.`, as this file should generally be the final output Other changes include: - `build` no longer generates app commits - `run` will call `build` before attempting to execute - `prove` will call `build` before attempting to generate a proof - Replaced all references to `evm-proving-setup` with references to `setup` - `openvm.toml`'s default location is in the working directory instead of `.` The basic workflow should now be `cargo openvm prove ...` into `cargo openvm verify ...`.
1 parent 274c422 commit 1ec4308

File tree

25 files changed

+1166
-437
lines changed

25 files changed

+1166
-437
lines changed

.github/workflows/cli.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
working-directory: examples/ecc
5050
run: |
5151
cargo openvm build
52-
mv openvm/app.vmexe app1.vmexe
52+
mv target/openvm/release/ecc-example.vmexe app1.vmexe
5353
cargo openvm build
54-
cmp app1.vmexe openvm/app.vmexe || (echo "Build is not deterministic!" && exit 1)
54+
cmp app1.vmexe target/openvm/release/ecc-example.vmexe || (echo "Build is not deterministic!" && exit 1)
5555
5656
- name: Build and run book examples
5757
working-directory: examples
@@ -72,7 +72,7 @@ jobs:
7272
run: |
7373
export RUST_BACKTRACE=1
7474
cargo build
75-
cargo run --bin cargo-openvm -- openvm keygen --config ./example/app_config.toml --output app.pk --vk-output app.vk
75+
cargo run --bin cargo-openvm -- openvm keygen --config ./example/app_config.toml --output-dir .
7676
7777
- name: Run CLI tests
7878
working-directory: crates/cli

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/execute/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_openvm::{default::DEFAULT_APP_CONFIG_PATH, util::read_config_toml_or_default};
1+
use cargo_openvm::util::read_config_toml_or_default;
22
use clap::{Parser, ValueEnum};
33
use eyre::Result;
44
use openvm_benchmarks_utils::{get_elf_path, get_programs_dir, read_elf_file};
@@ -106,7 +106,7 @@ fn main() -> Result<()> {
106106
let elf_path = get_elf_path(&program_dir);
107107
let elf = read_elf_file(&elf_path)?;
108108

109-
let config_path = program_dir.join(DEFAULT_APP_CONFIG_PATH);
109+
let config_path = program_dir.join("openvm.toml");
110110
let vm_config = read_config_toml_or_default(&config_path)?.app_vm_config;
111111

112112
let exe = VmExe::from_elf(elf, vm_config.transpiler())?;

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Overview](./writing-apps/overview.md)
1313
- [Writing a Program](./writing-apps/write-program.md)
1414
- [Compiling](./writing-apps/build.md)
15+
- [Running a Program](./writing-apps/run.md)
1516
- [Generating Proofs](./writing-apps/prove.md)
1617
- [Verifying Proofs](./writing-apps/verify.md)
1718
- [Solidity SDK](./writing-apps/solidity.md)

book/src/writing-apps/build.md

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,135 +9,142 @@ The command `cargo openvm build` compiles the program on host to an executable f
99
It first compiles the program normally on your _host_ platform with RISC-V and then transpiles it to a different target. See here for some explanation of [cross-compilation](https://rust-lang.github.io/rustup/cross-compilation.html).
1010
Right now we use `riscv32im-risc0-zkvm-elf` target which is available in the [Rust toolchain](https://doc.rust-lang.org/rustc/platform-support/riscv32im-risc0-zkvm-elf.html), but we will contribute an OpenVM target to Rust in the future.
1111

12-
## Build flags
12+
## Build Flags
1313

14-
The following flags are available for the `cargo openvm build` command:
14+
The following flags are available for the `cargo openvm build` command. You can run `cargo openvm build --help` for this list within the command line.
1515

16-
- `--manifest-dir <MANIFEST_DIR>`
16+
Generally, outputs will always be built to the **target directory**, which will either be determined by the manifest path or explicitly set using the `--target-dir` option. By default Cargo sets this to be `<workspace_or_package_root>/target/`.
1717

18-
**Description**: Specifies the directory containing the `Cargo.toml` file for the guest code.
18+
OpenVM-specific artifacts will be placed in `${target_dir}/openvm/`, but if `--output-dir` is specified they will be copied to `${output-dir}/` as well.
1919

20-
**Default**: The current directory (`.`).
20+
### OpenVM Options
2121

22-
**Usage Example**: If your `Cargo.toml` is located in `my_project/`, you can run:
22+
- `--no-transpile`
2323

24-
```bash
25-
cargo openvm build --manifest-dir my_project
26-
```
24+
**Description**: Skips transpilation into an OpenVM-compatible `.vmexe` executable when set.
2725

28-
This ensures the build command is executed in that directory.
26+
- `--config <CONFIG>`
2927

30-
- `--target-dir <TARGET_DIR>`
28+
**Description**: Path to the OpenVM config `.toml` file that specifies the VM extensions. By default will search the manifest directory for `openvm.toml`. If no file is found, OpenVM will use a default configuration. Currently the CLI only supports known extensions listed in the [Using Existing Extensions](../custom-extensions/overview.md) section. To use other extensions, use the [SDK](../advanced-usage/sdk.md).
3129

32-
**Description**: Specifies the directory where the guest binary will be built. If not specified, the default target directory is used.
30+
- `--output_dir <OUTPUT_DIR>`
3331

34-
**Default**: The `target` directory in the package root directory.
32+
**Description**: Output directory for OpenVM artifacts to be copied to. Keys will be placed in `${output-dir}/`, while all other artifacts will be in `${output-dir}/${profile}`.
3533

36-
**Usage Example**: To build the guest binary in the `my_target` directory:
34+
- `--init-file-name <INIT_FILE_NAME>`
3735

38-
```bash
39-
cargo openvm build --target-dir my_target
40-
```
36+
**Description**: Name of the generated initialization file, which will be written into the manifest directory.
4137

42-
- `--features <FEATURES>`
38+
**Default**: `openvm_init.rs`
4339

44-
**Description**: Passes a list of feature flags to the Cargo build process. These flags enable or disable conditional compilation features defined in your `Cargo.toml`.
40+
### Package Selection
4541

46-
**Usage Example**: To enable the `my_feature` feature:
42+
As with `cargo build`, default package selection depends on the working directory. If the working directory is a subdirectory of a specific package, then only that package will be built. Else, all packages in the workspace will be built by default.
4743

48-
```bash
49-
cargo openvm build --features my_feature
50-
```
44+
- `--package <PACKAGES>`
5145

52-
- `--bin <NAME>`
46+
**Description**: Builds only the specified packages. This flag may be specified multiple times or as a comma-separated list.
5347

54-
**Description**: Restricts the build to the binary target with the given name, similar to `cargo build --bin <NAME>`. If your project has multiple target types (binaries, libraries, examples, etc.), using `--bin <NAME>` narrows down the build to the binary target with the given name.
48+
- `--workspace`
5549

56-
**Usage Example**:
50+
**Description**: Builds all members of the workspace (alias `--all`).
5751

58-
```bash
59-
cargo openvm build --bin my_bin
60-
```
52+
- `--exclude <PACKAGES>`
6153

62-
- `--example <NAME>`
54+
**Description**: Excludes the specified packages. Must be used in conjunction with `--workspace`. This flag may be specified multiple times or as a comma-separated list.
6355

64-
**Description**: Restricts the build to the example target with the given name, similar to `cargo build --example <NAME>`. Projects often include code samples or demos under the examples directory, and this flag focuses on compiling a specific example.
56+
### Target Selection
6557

66-
**Usage Example**:
58+
By default all package libraries and binaries will be built. To build samples or demos under the `examples` directory, use either the `--example` or `--examples` option.
6759

68-
```bash
69-
cargo openvm build --example my_example
70-
```
60+
- `--lib`
7161

72-
- `--no-transpile`
62+
**Description**: Builds the package's library.
7363

74-
**Description**: After building the guest code, doesn't transpile the target ELF into an OpenVM-compatible executable (by default it does).
64+
- `--bin <BIN>`
7565

76-
**Usage Example**:
66+
**Description**: Builds the specified binary. This flag may be specified multiple times or as a comma-separated list.
7767

78-
```bash
79-
cargo openvm build --no-transpile
80-
```
68+
- `--bins`
8169

82-
- `--config <CONFIG>`
70+
**Description**: Builds all binary targets.
71+
72+
- `--example <EXAMPLE>`
73+
74+
**Description**: Builds the specified example. This flag may be specified multiple times or as a comma-separated list.
75+
76+
- `--examples`
77+
78+
**Description**: Builds all example targets.
79+
80+
- `--all-targets`
81+
82+
**Description**: Builds all package targets. Equivalent to specifying `--lib` `--bins` `--examples`.
83+
84+
### Feature Selection
85+
86+
The following options enable or disable conditional compilation features defined in your `Cargo.toml`.
87+
88+
- `-F`, `--features <FEATURES>`
89+
90+
**Description**: Space or comma separated list of features to activate. Features of workspace members may be enabled with `package-name/feature-name` syntax. This flag may also be specified multiple times.
91+
92+
- `--all-features`
93+
94+
**Description**: Activates all available features of all selected packages.
95+
96+
- `--no-default-features`
97+
98+
**Description**: Do not activate the `default` feature of the selected packages.
99+
100+
### Compilation Options
101+
102+
- `--profile <NAME>`
83103

84-
**Description**: Specifies the path to a .toml configuration file that defines which VM extensions to use.
104+
**Description**: Builds with the given profile. Common profiles are `dev` (faster builds, less optimization) and `release` (slower builds, more optimization). For more information on profiles, see [Cargo's reference page](https://doc.rust-lang.org/cargo/reference/profiles.html).
85105

86-
**Default**: `./openvm.toml` if `--config` flag is not provided.
106+
**Default**: `release`
87107

88-
**Usage Example**:
108+
### Output Options
89109

90-
```bash
91-
cargo openvm build --config path/to/openvm.toml
92-
```
110+
- `--target_dir <TARGET_DIR>`
93111

94-
This allows you to customize the extensions. Currently the CLI only supports known extensions listed in the [Using Existing Extensions](../custom-extensions/overview.md) section. To use other extensions, use the [SDK](../advanced-usage/sdk.md).
112+
**Description**: Directory for all generated artifacts and intermediate files. Defaults to directory `target/` at the root of the workspace.
95113

96-
- `--exe-output <EXE_OUTPUT>`
114+
### Display Options
97115

98-
**Description**: Sets the output path for the transpiled program.
116+
- `-v`, `--verbose`
99117

100-
**Default**: `./openvm/app.vmexe` if `--exe-output` flag is not provided.
118+
**Description**: Use verbose output.
101119

102-
**Usage Example**: To specify a custom output filename:
120+
- `-q`, `--quiet`
103121

104-
```bash
105-
cargo openvm build --exe-output ./output/custom_name.vmexe
106-
```
122+
**Description**: Do not print Cargo log messages.
107123

108-
- `--profile <PROFILE>`
124+
- `--color <WHEN>`
109125

110-
**Description**: Determines the build profile used by Cargo. Common profiles are dev (faster builds, less optimization) and release (slower builds, more optimization).
126+
**Description**: Controls when colored output is used.
111127

112-
**Default**: release
128+
**Default**: `always`
113129

114-
**Usage Example**:
130+
### Manifest Options
115131

116-
```bash
117-
cargo openvm build --profile dev
118-
```
132+
- `--manifest-path <PATH>`
119133

120-
- `--help`
134+
**Description**: Path to the guest code Cargo.toml file. By default, `build` searches for the file in the current or any parent directory. The `build` command will be executed in that directory.
121135

122-
**Description**: Prints a help message describing the available options and their usage.
136+
- `--ignore-rust-version`
123137

124-
**Usage Example**:
138+
**Description**: Ignores rust-version specification in packages.
125139

126-
```bash
127-
cargo openvm build --help
128-
```
140+
- `--locked`
129141

130-
## Running a Program
142+
**Description**: Asserts the same dependencies and versions are used as when the existing Cargo.lock file was originally generated.
131143

132-
After building and transpiling a program, you can execute it using the `run` command. The `run` command has the following arguments:
144+
- `--offline`
133145

134-
```bash
135-
cargo openvm run
136-
--exe <path_to_transpiled_program>
137-
--config <path_to_app_config>
138-
--input <path_to_input>
139-
```
146+
**Description**: Prevents Cargo from accessing the network for any reason.
140147

141-
If `--exe` and/or `--config` are not provided, the command will search for these files in `./openvm/app.vmexe` and `./openvm.toml` respectively. If `./openvm.toml` is not present, a default configuration will be used.
148+
- `--frozen`
142149

143-
If your program doesn't require inputs, you can (and should) omit the `--input` flag.
150+
**Description**: Equivalent to specifying both `--locked` and `--offline`.

book/src/writing-apps/prove.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,46 @@ Generating a proof using the CLI is simple - first generate a key, then generate
44

55
```bash
66
cargo openvm keygen
7-
cargo openvm prove [app | evm]
7+
cargo openvm prove [app | stark | evm]
88
```
99

1010
## Key Generation
1111

12-
The `keygen` CLI command has the following optional arguments:
12+
The `keygen` command generates both an application proving and verification key.
1313

1414
```bash
1515
cargo openvm keygen
1616
--config <path_to_app_config>
17-
--output <path_to_app_pk>
18-
--vk_output <path_to_app_vk>
1917
```
2018

21-
If `--config` is not provided, the command will search for `./openvm.toml` and use that as the application configuration if present. If it is not present, a default configuration will be used.
19+
Similarly to `build`, `run`, and `prove`, options `--manifest-path`, `--target-dir`, and `--output-dir` are provided.
2220

23-
If `--output` and/or `--vk_output` are not provided, the keys will be written to default locations `./openvm/app.pk` and/or `./openvm/app.vk` respectively.
21+
If `--config` is not specified, the command will search for `openvm.toml` in the manifest directory. If the file isn't found, a default configuration will be used.
22+
23+
The proving and verification key will be written to `${target_dir}/openvm/` (and `--output-dir` if specified).
2424

2525
## Proof Generation
2626

27-
The `prove` CLI command has the following optional arguments:
27+
The `prove` CLI command, at its core, uses the options below. `prove` gets access to all of the options that `run` has (see [Running a Program](../writing-apps/run.md) for more information).
2828

2929
```bash
30-
cargo openvm prove [app | evm]
31-
--app_pk <path_to_app_pk>
30+
cargo openvm prove [app | stark | evm]
31+
--app-pk <path_to_app_pk>
3232
--exe <path_to_transpiled_program>
3333
--input <path_to_input>
34-
--output <path_to_output>
34+
--proof <path_to_proof_output>
3535
```
3636

37+
If `--app-pk` is not provided, the command will search for a proving key at `${target_dir}/openvm/app.pk`.
38+
39+
If `--exe` is not provided, the command will call `build` before generating a proof.
40+
3741
If your program doesn't require inputs, you can (and should) omit the `--input` flag.
3842

39-
If `--app_pk` and/or `--exe` are not provided, the command will search for these files in `./openvm/app.pk` and `./openvm/app.vmexe` respectively. Similarly, if `--output` is not provided then the command will write the proof to `./openvm/[app | evm].proof` by default.
43+
If `--proof` is not provided then the command will write the proof to `./[app | stark | evm].proof` by default.
44+
4045

41-
The `app` subcommand is used to generate an application-level proof, while the `evm` command generates an end-to-end EVM proof.
46+
The `app` subcommand generates an application-level proof, the `stark` command generates an aggregated root-level proof, while the `evm` command generates an end-to-end EVM proof. For more information on aggregation, see [this specification](https://github.com/openvm-org/openvm/blob/bf8df90b13f4e80bb76dbb71f255a12154c84838/docs/specs/continuations.md).
4247

4348
> ⚠️ **WARNING**
4449
> In order to run the `evm` subcommand, you must have previously called the costly `cargo openvm setup`, which requires very large amounts of computation and memory (~200 GB).

0 commit comments

Comments
 (0)