Skip to content

Commit 47635c3

Browse files
authored
Add cargo risczero deploy (risc0#1592)
Closes risc0#1363
1 parent 46e3176 commit 47635c3

File tree

15 files changed

+288
-115
lines changed

15 files changed

+288
-115
lines changed

.vscode/settings.json

+85-68
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,92 @@
11
{
2-
"[rust]": {
3-
"editor.formatOnSave": true
4-
},
5-
"[starlark]": {
6-
"editor.formatOnSave": true
7-
},
8-
"emmet.includeLanguages": {
9-
"rust": "html"
10-
},
11-
"[javascript][javascriptreact][typescript][typescriptreact][github-actions-workflow]": {
12-
"editor.defaultFormatter": "biomejs.biome",
13-
"editor.codeActionsOnSave": {
14-
"quickfix.biome": "explicit",
15-
"source.organizeImports.biome": "explicit"
16-
},
17-
"editor.formatOnSave": true
18-
},
19-
"biome.rename": true,
20-
"biome.enabled": true,
21-
"rust-analyzer.cargo.extraEnv": {
22-
"RISC0_SKIP_BUILD": "1"
23-
},
24-
"files.eol": "\n",
25-
"git.ignoreLimitWarning": true,
26-
"files.associations": {
27-
"*.sh": "shellscript",
28-
"*.py": "python",
29-
"*.cl": "c",
30-
"*.rs": "rust",
31-
"*.BUILD": "starlark",
32-
"meson.build": "meson",
33-
"*.mlir": "mlir",
34-
"*.pbtxt": "prototxt",
35-
"*.cfg": "python",
36-
"*.scr": "tcl",
37-
"cstddef": "cpp",
38-
"*.bazel": "starlark",
39-
"fstream": "cpp",
40-
"ios": "cpp",
41-
"iosfwd": "cpp",
42-
"vector": "cpp",
43-
"charconv": "cpp",
44-
"stdexcept": "cpp",
45-
"array": "cpp",
2+
"[rust]": {
3+
"editor.formatOnSave": true
4+
},
5+
"[starlark]": {
6+
"editor.formatOnSave": true
7+
},
8+
"emmet.includeLanguages": {
9+
"rust": "html"
10+
},
11+
"[javascript][javascriptreact][typescript][typescriptreact][github-actions-workflow]": {
12+
"editor.defaultFormatter": "biomejs.biome",
13+
"editor.codeActionsOnSave": {
14+
"quickfix.biome": "explicit",
15+
"source.organizeImports.biome": "explicit"
16+
},
17+
"editor.formatOnSave": true
18+
},
19+
"biome.rename": true,
20+
"biome.enabled": true,
21+
"rust-analyzer.cargo.extraEnv": {
22+
"RISC0_SKIP_BUILD": "1"
23+
},
24+
"files.eol": "\n",
25+
"git.ignoreLimitWarning": true,
26+
"files.associations": {
27+
"*.sh": "shellscript",
28+
"*.py": "python",
29+
"*.cl": "c",
30+
"*.rs": "rust",
31+
"*.BUILD": "starlark",
32+
"meson.build": "meson",
33+
"*.mlir": "mlir",
34+
"*.pbtxt": "prototxt",
35+
"*.cfg": "python",
36+
"*.scr": "tcl",
37+
"cstddef": "cpp",
38+
"*.bazel": "starlark",
39+
"fstream": "cpp",
40+
"ios": "cpp",
41+
"iosfwd": "cpp",
42+
"vector": "cpp",
43+
"charconv": "cpp",
44+
"stdexcept": "cpp",
45+
"array": "cpp",
4646
"*.css": "tailwindcss"
47-
},
47+
},
4848
"tailwindCSS.experimental.classRegex": [
49-
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
50-
["cn\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
51-
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
49+
[
50+
"cva\\(([^)]*)\\)",
51+
"[\"'`]([^\"'`]*).*?[\"'`]"
52+
],
53+
[
54+
"cn\\(([^)]*)\\)",
55+
"[\"'`]([^\"'`]*).*?[\"'`]"
56+
],
57+
[
58+
"cx\\(([^)]*)\\)",
59+
"(?:'|\"|`)([^']*)(?:'|\"|`)"
60+
],
5261
"twc\\.[^`]+`([^`]*)`",
5362
"twc\\(.*?\\).*?`([^`]*)",
54-
["twc\\.[^`]+\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
55-
["twc\\(.*?\\).*?\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
63+
[
64+
"twc\\.[^`]+\\(([^)]*)\\)",
65+
"(?:'|\"|`)([^']*)(?:'|\"|`)"
66+
],
67+
[
68+
"twc\\(.*?\\).*?\\(([^)]*)\\)",
69+
"(?:'|\"|`)([^']*)(?:'|\"|`)"
70+
]
5671
],
57-
"rust-analyzer.showUnlinkedFileNotification": false,
58-
"rust-analyzer.linkedProjects": [
59-
"Cargo.toml",
60-
"benchmarks/Cargo.toml",
61-
"examples/Cargo.toml",
62-
"risc0/zkvm/methods/guest/Cargo.toml",
63-
"risc0/zkvm/methods/std/Cargo.toml",
64-
"tools/crates-validator/Cargo.toml"
65-
],
66-
"cSpell.words": [
67-
"Groth",
68-
"Holesky",
69-
"Sepolia",
70-
"Zeroable",
71-
"bytemuck",
72-
"posix",
73-
"repr"
74-
]
72+
"rust-analyzer.showUnlinkedFileNotification": false,
73+
"rust-analyzer.linkedProjects": [
74+
"Cargo.toml",
75+
"benchmarks/Cargo.toml",
76+
"examples/Cargo.toml",
77+
"risc0/zkvm/methods/guest/Cargo.toml",
78+
"risc0/zkvm/methods/std/Cargo.toml",
79+
"tools/crates-validator/Cargo.toml"
80+
],
81+
"cSpell.words": [
82+
"Groth",
83+
"Holesky",
84+
"Sepolia",
85+
"Zeroable",
86+
"bytemuck",
87+
"canonicalize",
88+
"posix",
89+
"repr",
90+
"risczero",
91+
]
7592
}

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/Cargo.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

risc0/build/src/docker.rs

+28-17
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,40 @@ const DOCKER_IGNORE: &str = r#"
3434
**/tmp
3535
"#;
3636

37-
const TARGET_DIR: &str = "target/riscv-guest/riscv32im-risc0-zkvm-elf/docker";
37+
/// The target directory for the ELF binaries.
38+
pub const TARGET_DIR: &str = "target/riscv-guest/riscv32im-risc0-zkvm-elf/docker";
39+
40+
/// Indicates weather the build was successful or skipped.
41+
pub enum BuildStatus {
42+
/// The build was successful.
43+
Success,
44+
/// The build was skipped.
45+
Skipped,
46+
}
3847

3948
/// Build the package in the manifest path using a docker environment.
40-
pub fn docker_build(manifest_path: &Path, src_dir: &Path, features: &[String]) -> Result<()> {
49+
pub fn docker_build(
50+
manifest_path: &Path,
51+
src_dir: &Path,
52+
features: &[String],
53+
) -> Result<BuildStatus> {
4154
if !get_env_var("RISC0_SKIP_BUILD").is_empty() {
42-
return Ok(());
55+
eprintln!("Skipping build because RISC0_SKIP_BUILD is set");
56+
return Ok(BuildStatus::Skipped);
4357
}
4458

4559
let manifest_path = manifest_path
4660
.canonicalize()
4761
.context(format!("manifest_path: {manifest_path:?}"))?;
4862
let src_dir = src_dir.canonicalize().context("src_dir")?;
49-
eprintln!("Docker context: {src_dir:?}");
50-
5163
let meta = MetadataCommand::new()
5264
.manifest_path(&manifest_path)
5365
.exec()
5466
.context("Manifest not found")?;
55-
let root_pkg = meta.root_package().context("failed to parse Cargo.toml")?;
67+
let root_pkg = meta.root_package().context("Failed to parse Cargo.toml")?;
5668
let pkg_name = &root_pkg.name;
5769

70+
eprintln!("Docker context: {src_dir:?}");
5871
eprintln!("Building ELF binaries in {pkg_name} for riscv32im-risc0-zkvm-elf target...");
5972

6073
if !Command::new("docker")
@@ -81,16 +94,14 @@ pub fn docker_build(manifest_path: &Path, src_dir: &Path, features: &[String]) -
8194
println!("ELFs ready at:");
8295

8396
let target_dir = src_dir.join(TARGET_DIR);
84-
for target in root_pkg.targets.iter() {
85-
if target.is_bin() {
86-
let elf_path = target_dir.join(&pkg_name).join(&target.name);
87-
let image_id = compute_image_id(&elf_path)?;
88-
let rel_elf_path = Path::new(TARGET_DIR).join(&pkg_name).join(&target.name);
89-
println!("ImageID: {} - {:?}", image_id, rel_elf_path);
90-
}
97+
for target in root_pkg.targets.iter().filter(|t| t.is_bin()) {
98+
let elf_path = target_dir.join(&pkg_name).join(&target.name);
99+
let image_id = compute_image_id(&elf_path)?;
100+
let rel_elf_path = Path::new(TARGET_DIR).join(&pkg_name).join(&target.name);
101+
println!("ImageID: {} - {:?}", image_id, rel_elf_path);
91102
}
92103

93-
Ok(())
104+
Ok(BuildStatus::Success)
94105
}
95106

96107
/// Create the dockerfile.
@@ -162,7 +173,7 @@ fn create_dockerfile(
162173
Ok(())
163174
}
164175

165-
/// Build the dockerfile and ouputs the ELF.
176+
/// Build the dockerfile and outputs the ELF.
166177
///
167178
/// Overwrites if an ELF with the same name already exists.
168179
fn build(src_dir: &Path, temp_dir: &Path) -> Result<()> {
@@ -218,7 +229,7 @@ mod test {
218229
fn build(manifest_path: &str) {
219230
let src_dir = Path::new(SRC_DIR);
220231
let manifest_path = Path::new(manifest_path);
221-
self::docker_build(manifest_path, &src_dir, &[]).unwrap()
232+
self::docker_build(manifest_path, &src_dir, &[]).unwrap();
222233
}
223234

224235
fn compare_image_id(bin_path: &str, expected: &str) {
@@ -239,7 +250,7 @@ mod test {
239250
build("../../risc0/zkvm/methods/guest/Cargo.toml");
240251
compare_image_id(
241252
"risc0_zkvm_methods_guest/multi_test",
242-
"f3bd3eff02e3a351530e2f3e18d2a9447487529d79ef4bf6f12700d2f497daea",
253+
"66b09f00792e3a13e7b07b920381c743fc0aea13855614ae750d14eb6e84bac2",
243254
);
244255
}
245256
}

risc0/build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use risc0_zkp::core::digest::DIGEST_WORDS;
3636
use risc0_zkvm_platform::memory;
3737
use serde::Deserialize;
3838

39-
pub use docker::docker_build;
39+
pub use docker::{docker_build, BuildStatus, TARGET_DIR};
4040

4141
const RUSTUP_TOOLCHAIN_NAME: &str = "risc0";
4242

0 commit comments

Comments
 (0)