Skip to content

Commit 2ee1bc8

Browse files
feat: add the ProtocolLib's masp Package as artifact
1 parent c2c6eaf commit 2ee1bc8

7 files changed

Lines changed: 115 additions & 2 deletions

File tree

.github/workflows/workspace-publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,43 @@ jobs:
3434
release-branch: ${{ github.event.release.target_commitish }}
3535
env:
3636
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
37+
38+
# Upload the pre-compiled artifacts (miden-protocol.masp) on the
39+
# GitHub release page.
40+
# Used by midenup to speed up installs.
41+
upload-artifacts:
42+
name: upload pre-built miden-protocol library artifacts
43+
if: ${{ github.repository_owner == '0xMiden' }}
44+
permissions:
45+
contents: write
46+
id-token: write
47+
attestations: write
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
51+
with:
52+
fetch-depth: 0
53+
ref: ${{ github.event.release.tag_name }}
54+
persist-credentials: false
55+
- uses: ./.github/actions/cleanup-runner
56+
- name: Install Rust
57+
run: |
58+
rustup update --no-self-update
59+
rustc --version
60+
- name: Build miden-core.masp
61+
run: |
62+
make packages
63+
- name: Prepare artifact
64+
run: |
65+
mv target/packages/miden-protocol.masp miden-protocol.masp
66+
- name: Attest miden-core.masp
67+
uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
68+
with:
69+
subject-path: miden-core.masp
70+
- name: Upload miden-core.masp
71+
env:
72+
RELEASE_TAG: ${{ github.event.release.tag_name }}
73+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
run: |
75+
set -e
76+
gh release upload ${RELEASE_TAG} miden-protocol.masp

Cargo.lock

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

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ build-no-std: ## Build without the standard library
146146
build-no-std-testing: ## Build without the standard library. Includes the `testing` feature
147147
$(BUILD_GENERATED_FILES_IN_SRC) cargo build --no-default-features --target wasm32-unknown-unknown --workspace --exclude bench-transaction --features testing
148148

149+
.PHONY: packages
150+
packages: ## Builds .masp packages and store them in target/packages
151+
cargo +nightly -Zscript scripts/generate-package.rs
152+
149153
# --- test vectors --------------------------------------------------------------------------------
150154

151155
.PHONY: generate-solidity-test-vectors

crates/miden-protocol/src/protocol.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use alloc::boxed::Box;
12
use alloc::sync::Arc;
23

4+
use miden_mast_package::{Package, TargetType, Version};
5+
36
use crate::assembly::Library;
47
use crate::assembly::mast::MastForest;
58
use crate::utils::serde::Deserializable;
@@ -10,6 +13,8 @@ use crate::utils::sync::LazyLock;
1013

1114
const PROTOCOL_LIB_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/assets/protocol.masl"));
1215

16+
const PROTOCOL_PACKAGE_NAME: &str = "miden-protocol";
17+
1318
// PROTOCOL LIBRARY
1419
// ================================================================================================
1520

@@ -21,6 +26,23 @@ impl ProtocolLib {
2126
pub fn mast_forest(&self) -> &Arc<MastForest> {
2227
self.0.mast_forest()
2328
}
29+
30+
/// Wraps this library into a [`Package`] named `PROTOCOL_PACKAGE_NAME`,
31+
/// versioned with the `miden-protocol` crate's version.
32+
pub fn into_package(self) -> Box<Package> {
33+
// The ProtocolLib's version is the same as the crate's as per the miden-protocol's
34+
// Cargo.toml.
35+
let version = Version::parse(env!("CARGO_PKG_VERSION"))
36+
.expect("CARGO_PKG_VERSION must be valid semver");
37+
38+
Package::from_library(
39+
PROTOCOL_PACKAGE_NAME.into(),
40+
version,
41+
TargetType::Library,
42+
Arc::new(self.0),
43+
[],
44+
)
45+
}
2446
}
2547

2648
impl AsRef<Library> for ProtocolLib {

crates/miden-standards/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ testing = ["dep:rand", "miden-assembly/testing", "miden-protocol/testing"]
2121

2222
[dependencies]
2323
# Miden dependencies
24-
miden-processor = { workspace = true }
25-
miden-protocol = { workspace = true }
24+
miden-processor = { workspace = true }
25+
miden-protocol = { workspace = true }
26+
miden-mast-package = { workspace = true }
2627

2728
# External dependencies
2829
bon = { workspace = true }

crates/miden-standards/src/standards_lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use alloc::boxed::Box;
12
use alloc::sync::Arc;
23

4+
use miden_mast_package::{Package, TargetType, Version};
35
use miden_protocol::assembly::Library;
46
use miden_protocol::assembly::mast::MastForest;
57
use miden_protocol::utils::serde::Deserializable;
@@ -11,6 +13,8 @@ use miden_protocol::utils::sync::LazyLock;
1113
const STANDARDS_LIB_BYTES: &[u8] =
1214
include_bytes!(concat!(env!("OUT_DIR"), "/assets/standards.masl"));
1315

16+
const STANDARDS_LIB_NAME: &str = "standars";
17+
1418
// MIDEN STANDARDS LIBRARY
1519
// ================================================================================================
1620

@@ -22,6 +26,23 @@ impl StandardsLib {
2226
pub fn mast_forest(&self) -> &Arc<MastForest> {
2327
self.0.mast_forest()
2428
}
29+
30+
/// Wraps this library into a [`Package`] named `PROTOCOL_PACKAGE_NAME`,
31+
/// versioned with the `miden-protocol` crate's version.
32+
pub fn into_package(self) -> Box<Package> {
33+
// The ProtocolLib's version is the same as the crate's as per the miden-standars's
34+
// Cargo.toml.
35+
let version = Version::parse(env!("CARGO_PKG_VERSION"))
36+
.expect("CARGO_PKG_VERSION must be valid semver");
37+
38+
Package::from_library(
39+
STANDARDS_LIB_NAME.into(),
40+
version,
41+
TargetType::Library,
42+
Arc::new(self.0),
43+
[],
44+
)
45+
}
2546
}
2647

2748
impl AsRef<Library> for StandardsLib {

scripts/generate-package.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env cargo
2+
3+
---
4+
[dependencies]
5+
miden-protocol = { path = "../crates/miden-protocol" }
6+
semver = "1"
7+
---
8+
9+
use std::env;
10+
11+
use miden_protocol::ProtocolLib;
12+
13+
fn main() -> std::io::Result<()> {
14+
// Must be run from the workspace root (CARGO_TARGET_DIR is not set for cargo scripts).
15+
let workspace_root = env::current_dir().expect("could not read PWD");
16+
let packages_dir = workspace_root.join("target").join("packages");
17+
std::fs::create_dir_all(&packages_dir)?;
18+
19+
let package = ProtocolLib::default().into_package();
20+
package.write_masp_file(&packages_dir)?;
21+
22+
println!("wrote {}.masp to {}", package.name, packages_dir.display());
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)