From 4e0315994b6c75830e518e6771bf4eb9b7006f50 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 28 Oct 2024 12:23:35 +0200 Subject: [PATCH] feature: load `LinkLibrary` from a Miden package --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 10 +++++----- midenc-session/src/libs.rs | 12 ++++++++++-- .../integration/src/rust_masm_tests/rust_sdk.rs | 4 ++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a11d4a2..9fe5fac7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2974,7 +2974,7 @@ dependencies = [ [[package]] name = "miden-air" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "miden-core", "miden-thiserror", @@ -2985,7 +2985,7 @@ dependencies = [ [[package]] name = "miden-assembly" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "aho-corasick", "lalrpop", @@ -3011,7 +3011,7 @@ dependencies = [ [[package]] name = "miden-core" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "lock_api", "loom", @@ -3029,9 +3029,9 @@ dependencies = [ [[package]] name = "miden-crypto" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a69f8362ca496a79c88cf8e5b9b349bf9c6ed49fa867d0548e670afc1f3fca5" +checksum = "1e0ca714c8242f329b9ea6f1a5bf0e93f1490f348f982e3a606d91b884254308" dependencies = [ "blake3", "cc", @@ -3139,7 +3139,7 @@ dependencies = [ [[package]] name = "miden-package" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "bitcode", "miden-assembly", @@ -3153,7 +3153,7 @@ dependencies = [ [[package]] name = "miden-processor" version = "0.10.6" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "miden-air", "miden-core", @@ -3168,7 +3168,7 @@ version = "0.0.7" [[package]] name = "miden-stdlib" version = "0.10.5" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=e84368bb5b0629e367e615973fa7dd4823a872b7#e84368bb5b0629e367e615973fa7dd4823a872b7" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=3fb46fae44adfb525dc8665a65b07611ed100806#3fb46fae44adfb525dc8665a65b07611ed100806" dependencies = [ "miden-assembly", ] diff --git a/Cargo.toml b/Cargo.toml index fedc0bc3..63db830c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,14 +85,14 @@ derive_more = "0.99" indexmap = "2.2" # miden-assembly = { version = "0.10.3" } # miden-core = { version = "0.10.3" } -miden-assembly = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "e84368bb5b0629e367e615973fa7dd4823a872b7" } -miden-core = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "e84368bb5b0629e367e615973fa7dd4823a872b7" } +miden-assembly = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "3fb46fae44adfb525dc8665a65b07611ed100806" } +miden-core = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "3fb46fae44adfb525dc8665a65b07611ed100806" } miden-parsing = "0.1" # miden-processor = { version = "0.10.3" } # miden-stdlib = { version = "0.10.3", features = ["with-debug-info"] } -miden-processor = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "e84368bb5b0629e367e615973fa7dd4823a872b7" } -miden-stdlib = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "e84368bb5b0629e367e615973fa7dd4823a872b7", features = ["with-debug-info"] } -miden-package = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "e84368bb5b0629e367e615973fa7dd4823a872b7" } +miden-processor = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "3fb46fae44adfb525dc8665a65b07611ed100806" } +miden-stdlib = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "3fb46fae44adfb525dc8665a65b07611ed100806", features = ["with-debug-info"] } +miden-package = { version = "0.10.5", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "3fb46fae44adfb525dc8665a65b07611ed100806" } #miden-assembly = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" } #miden-core = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" } #miden-processor = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" } diff --git a/midenc-session/src/libs.rs b/midenc-session/src/libs.rs index 4bfd78d3..cbbfc220 100644 --- a/midenc-session/src/libs.rs +++ b/midenc-session/src/libs.rs @@ -1,5 +1,5 @@ use alloc::{borrow::Cow, boxed::Box, format, str::FromStr, string::ToString}; -use core::fmt; +use core::{fmt, panic}; use std::{ ffi::OsStr, path::{Path, PathBuf}, @@ -133,7 +133,15 @@ impl LinkLibrary { )) }), LibraryKind::Masp => { - todo!("Should be implemented as part of the https://github.com/0xPolygonMiden/compiler/issues/346") + let bytes = std::fs::read(path).into_diagnostic()?; + let package = miden_package::Package::read_from_bytes(bytes)?; + let lib = match package.mast { + miden_package::MastArtifact::Executable(_) => { + panic!("expected library for Miden package, not program") + } + miden_package::MastArtifact::Library(lib) => lib.clone(), + }; + Ok((*lib).clone()) } } } diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 69f9efea..9cf46856 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -80,8 +80,8 @@ fn rust_sdk_p2id_note_script() { "../rust-apps-wasm/rust-sdk/p2id-note", config, [ - // "--link-library".into(), - // masl_path.into_os_string().into_string().unwrap().into(), + "--link-library".into(), + masp_path.into_os_string().into_string().unwrap().into(), ], ); let artifact_name = test.artifact_name().to_string();