0xMiden / 0xMiden/protocol

Building a package from the Rust project for Mockchain-based tests

未关闭
#2,611 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
132
派生
167
平均合并
1 天 23 小时
30 天内合并 PR
110

描述

As mentioned in https://github.com/0xMiden/compiler/issues/981#issuecomment-3949988737 and to complement the DX features added in https://github.com/0xMiden/protocol/pull/2502 we need to provide a user with a way to build the package.

I suggest implementing it as a function but I'm open to other ideas:
```rust
pub(super) fn compile_rust_package(project_path: &str, release: bool) -> Arc {
let mode_flag = if release { "--release" } else { "--dev" };
let output = std::process::Command::new("miden")
.arg("build")
// Midenup's "miden build" command inherits all of cargo miden's flags.
.current_dir(project_path)
.env("MIDENUP_MANIFEST_URI", format!("file://{project_path}/channel-manifest.json"))
.arg(mode_flag)
.output()
// TODO: Add the cargo install command once `midenup` is published
// in crates.io.
.expect("failed to execute `miden build`. Is midenup installed?.
If not, follow the installation instructions in: https://github.com/0xMiden/midenup");

if !output.status.success() {
panic!("miden build failed:\n{}", String::from_utf8_lossy(&output.stderr))
}

// Read the .masp artifact from the project's target directory
let masp_path = std::path::Path::new(project_path)
.join("target/miden/release")
.read_dir()
.expect("failed to read target/miden/release")
.filter_map(|e| e.ok())
.find(|e| e.path().extension().is_some_and(|ext| ext == "masp"))
.map(|entry| entry.path())
.expect("no .masp file found in target/miden/release");

let masp_bytes = std::fs::read(&masp_path).expect("failed to read .masp artifact");
Arc::new(Package::read_from_bytes(&masp_bytes).expect("failed to parse .masp package"))
}
```
@PhilippGackstatter What do you think?

@lima-limon-inc

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。