Building a package from the Rust project for Mockchain-based tests
- Lingua principale
- Rust
- Stelle
- 132
- Fork
- 167
- Merge medio
- 1g 23h
- PR unite (30g)
- 110
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.