-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add tx kernel library with stubs and link it on -l base
#277
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44fe589
fix: add tx kernel library with stubs and link it on `-l miden`
greenhat 7874a13
fix: load tx kernel library stubs via SourceManager
greenhat 3151fe2
refactor: rename `midenc-tx-kernel` to `miden-base-sys` and move it to
greenhat 30b4e8b
refactor: build the MASL for the tx kernel stubs in `build.rs` and
greenhat 2b7fdc4
refactor: delete `miden-tx-kernel-sys` crate and move the code to `mi…
greenhat fb80d83
fix clippy warnings
greenhat b9de0b5
fix the build after VM v0.10.3 update
greenhat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "miden-base-sys" | ||
description = "Miden rollup Rust bingings and MASM library" | ||
version = "0.0.0" | ||
rust-version.workspace = true | ||
authors.workspace = true | ||
repository.workspace = true | ||
homepage.workspace = true | ||
documentation.workspace = true | ||
categories.workspace = true | ||
keywords.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
miden-assembly.workspace = true | ||
miden-stdlib-sys = { version = "0.0.1", path = "../stdlib-sys", optional = true } | ||
|
||
[build-dependencies] | ||
miden-assembly.workspace = true | ||
|
||
[features] | ||
default = [] | ||
|
||
# User facing Rust bindings | ||
"bindings" = ["miden-stdlib-sys"] | ||
# MASL library for Miden rollup (tx kernel, etc.) used by the compiler in the link phase | ||
"masl-lib" = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::{env, path::Path, sync::Arc}; | ||
|
||
use miden_assembly::{ | ||
diagnostics::{IntoDiagnostic, Result}, | ||
Assembler, Library as CompiledLibrary, LibraryNamespace, | ||
}; | ||
|
||
/// Read and parse the contents from `./masm/*` and compile it to MASL. | ||
fn main() -> Result<()> { | ||
// re-build the `[OUT_DIR]/assets/` file iff something in the `./masm` directory | ||
// or its builder changed: | ||
println!("cargo:rerun-if-changed=masm"); | ||
|
||
let build_dir = env::var("OUT_DIR").unwrap(); | ||
let build_dir = Path::new(&build_dir); | ||
let manifest_dir = env!("CARGO_MANIFEST_DIR"); | ||
let source_manager = Arc::new(miden_assembly::DefaultSourceManager::default()); | ||
let namespace = "miden".parse::<LibraryNamespace>().expect("invalid base namespace"); | ||
|
||
let tx_asm_dir = Path::new(manifest_dir).join("masm").join("tx"); | ||
let asm = Assembler::new(source_manager); | ||
let txlib = CompiledLibrary::from_dir(tx_asm_dir, namespace, asm)?; | ||
let tx_masl_path = build_dir | ||
.join("assets") | ||
.join("tx") | ||
.with_extension(CompiledLibrary::LIBRARY_EXTENSION); | ||
txlib.write_to_file(tx_masl_path).into_diagnostic()?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Stubs for miden::account tx kernel module | ||
|
||
export.remove_asset | ||
push.1 | ||
assertz | ||
end | ||
|
||
export.add_asset | ||
push.1 | ||
assertz | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Stubs for miden::tx tx kernel module | ||
|
||
export.create_note | ||
push.1 | ||
assertz | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod tx; |
2 changes: 1 addition & 1 deletion
2
sdk/tx-kernel-sys/src/externs.rs → sdk/base-sys/src/bindings/tx/externs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
sdk/tx-kernel-sys/src/lib.rs → sdk/base-sys/src/bindings/tx/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![no_std] | ||
|
||
mod externs; | ||
use externs::*; | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Enable no_std for the bindings module | ||
#![cfg_attr(feature = "bindings", no_std)] | ||
|
||
#[cfg(feature = "bindings")] | ||
pub mod bindings; | ||
#[cfg(feature = "masl-lib")] | ||
pub mod masl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod tx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use miden_assembly::{utils::Deserializable, Library as CompiledLibrary}; | ||
|
||
/// Stubs for the Miden rollup tx kernel | ||
pub struct MidenTxKernelLibrary(CompiledLibrary); | ||
|
||
impl AsRef<CompiledLibrary> for MidenTxKernelLibrary { | ||
fn as_ref(&self) -> &CompiledLibrary { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<MidenTxKernelLibrary> for CompiledLibrary { | ||
fn from(lib: MidenTxKernelLibrary) -> Self { | ||
lib.0 | ||
} | ||
} | ||
|
||
impl Default for MidenTxKernelLibrary { | ||
fn default() -> Self { | ||
let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/assets/tx.masl")); | ||
let contents = CompiledLibrary::read_from_bytes(bytes).expect("failed to read std masl!"); | ||
Self(contents) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![no_std] | ||
|
||
pub use miden_base_sys::bindings::tx::*; | ||
pub use miden_stdlib_sys::*; | ||
pub use miden_tx_kernel_sys::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can simply make the
masl-lib
parts of this use#[cfg(not(target_family = "wasm"))]
, rather than a Cargo feature. This keeps it out of the Wasm builds that would cause this to end up in code processed by the compiler, but otherwise keeps all of the code together.In the future we may need to add a feature that allows those items to exist in a Wasm build as well (for building the compiler to run in the browser), but we're a way away from that point yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or vice versa, make the bindings conditional on
#[cfg(target_family = "wasm")]
- that might make more sense, since the bindings only are needed when targeting Miden.