Skip to content
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

support wasm build #265

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/rainix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ jobs:
CI_FORK_SEPOLIA_BLOCK_NUMBER: ${{ vars.CI_FORK_SEPOLIA_BLOCK_NUMBER }}
CI_FORK_SEPOLIA_DEPLOYER_ADDRESS: ${{ vars.CI_FORK_SEPOLIA_DEPLOYER_ADDRESS }}
CI_DEPLOY_SEPOLIA_RPC_URL: ${{ secrets.CI_DEPLOY_SEPOLIA_RPC_URL || vars.CI_DEPLOY_SEPOLIA_RPC_URL }}
run: nix develop --command ${{ matrix.task }}
run: nix develop --command ${{ matrix.task }}

- name: Build for wasm target
run: nix develop -c cargo build --target wasm32-unknown-unknown --exclude rain-i9r-cli --workspace
env:
CI_FORK_SEPOLIA_BLOCK_NUMBER: ${{ vars.CI_FORK_SEPOLIA_BLOCK_NUMBER }}
CI_FORK_SEPOLIA_DEPLOYER_ADDRESS: ${{ vars.CI_FORK_SEPOLIA_DEPLOYER_ADDRESS }}
CI_DEPLOY_SEPOLIA_RPC_URL: ${{ secrets.CI_DEPLOY_SEPOLIA_RPC_URL || vars.CI_DEPLOY_SEPOLIA_RPC_URL }}
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ serde = "1.0.160"
serde_bytes = "0.11.9"
serde_json = "1.0.112"
thiserror = "1.0.56"
tokio = { version = "1.28.0", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
reqwest = { version = "0.11.17", features = ["json"] }
once_cell = "1.17.1"
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "cbdedb77fb1994a18ceb47e72786f8b32b670669" }
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "d9bd0fe8360d803ed3e58b34063890c8775999f2" }
rain-interpreter-env = { path = "crates/env" }
eyre = "0.6"
rain-error-decoding = { git = "https://github.com/rainlanguage/rain.error", rev = "700142c3c73d5cbaea82f1d51af5ce04de5bac6a" }
rain-error-decoding = { git = "https://github.com/rainlanguage/rain.error", rev = "72d9577fdaf7135113847027ba951f9a43b41827" }

[workspace.dependencies.rain_interpreter_parser]
path = "crates/parser"
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ anyhow = { workspace = true }
clap = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
tokio = { workspace = true }
tokio = { version = "1.28.0", features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ['env-filter'] }
alloy-primitives = { workspace = true }
Expand Down
11 changes: 8 additions & 3 deletions crates/dispair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ alloy-ethers-typecast = { workspace = true }
rain_interpreter_bindings = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
alloy-primitives = {workspace = true}
alloy-sol-types = { workspace = true }
ethers = { workspace = true, features = [
"legacy",
] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
thiserror = { workspace = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
tokio = { version = "1.28.0", features = ["full"] }

[target.'cfg(target_family = "wasm")'.dependencies]
tokio = { version = "1.28.0", features = ["sync", "macros", "io-util", "rt", "time"] }

[package.metadata.docs.rs]
all-features = true
8 changes: 5 additions & 3 deletions crates/eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ rain_interpreter_bindings = { workspace = true }
alloy-sol-types = { workspace = true }
alloy-json-abi = { workspace = true }
alloy-dyn-abi = { workspace = true }
foundry-evm = { workspace = true }
revm = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
reqwest = { workspace = true }
once_cell = { workspace = true }
eyre = { workspace = true }
rain-error-decoding = { workspace = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
foundry-evm = { workspace = true }
revm = { workspace = true }

[dev-dependencies]
tokio = { workspace = true }
tokio = { version = "1.28.0", features = ["full"] }
tracing = { workspace = true }
rain-interpreter-env = { workspace = true }
3 changes: 3 additions & 0 deletions crates/eval/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_primitives::ruint::FromUintError;
#[cfg(not(target_family = "wasm"))]
use foundry_evm::executors::RawCallResult;
use rain_error_decoding::{AbiDecodeFailedErrors, AbiDecodedErrorType};
use thiserror::Error;
Expand All @@ -7,6 +8,7 @@ use thiserror::Error;
pub enum ForkCallError {
#[error("Executor error: {0}")]
ExecutorError(String),
#[cfg(not(target_family = "wasm"))]
#[error("Call failed: {:#?}", .0)]
Failed(RawCallResult),
#[error("Typed error: {0}")]
Expand All @@ -23,6 +25,7 @@ pub enum ForkCallError {
Eyre(#[from] eyre::Report),
}

#[cfg(not(target_family = "wasm"))]
impl From<RawCallResult> for ForkCallError {
fn from(value: RawCallResult) -> Self {
Self::Failed(value)
Expand Down
3 changes: 3 additions & 0 deletions crates/eval/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub mod dispatch;
pub mod error;
#[cfg(not(target_family = "wasm"))]
pub mod eval;
#[cfg(not(target_family = "wasm"))]
pub mod fork;
pub mod namespace;
#[cfg(not(target_family = "wasm"))]
pub mod trace;
7 changes: 6 additions & 1 deletion crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ rain_interpreter_dispair = { workspace = true }
rain_interpreter_bindings = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
ethers = { workspace = true, features = [
"legacy",
] }
thiserror = { workspace = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
tokio = { version = "1.28.0", features = ["full"] }

[target.'cfg(target_family = "wasm")'.dependencies]
tokio = { version = "1.28.0", features = ["sync", "macros", "io-util", "rt", "time"] }
25 changes: 25 additions & 0 deletions crates/parser/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ethers::providers::JsonRpcClient;
use rain_interpreter_bindings::IParserV1::*;
use rain_interpreter_dispair::DISPair;

#[cfg(not(target_family = "wasm"))]
pub trait Parser {
/// Call Parser contract to parse the provided rainlang text.
fn parse_text<T: JsonRpcClient>(
Expand All @@ -26,6 +27,30 @@ pub trait Parser {
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parseReturn, ParserError>> + Send;
}

#[cfg(target_family = "wasm")]
pub trait Parser {
/// Call Parser contract to parse the provided rainlang text.
fn parse_text<T: JsonRpcClient>(
&self,
text: &str,
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parseReturn, ParserError>>
where
Self: Sync,
{
self.parse(text.as_bytes().to_vec(), client)
}

/// Call Parser contract to parse the provided data
/// The provided data must contain valid UTF-8 encoding of valid rainlang text.
fn parse<T: JsonRpcClient>(
&self,
data: Vec<u8>,
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parseReturn, ParserError>>;
}

/// ParserV1
/// Struct representing ParserV1 instances.
#[derive(Clone, Default)]
Expand Down
33 changes: 33 additions & 0 deletions crates/parser/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rain_interpreter_bindings::IParserPragmaV1::*;
use rain_interpreter_bindings::IParserV2::*;
use rain_interpreter_dispair::DISPair;

#[cfg(not(target_family = "wasm"))]
pub trait Parser2 {
/// Call Parser contract to parse the provided rainlang text.
fn parse_text<T: JsonRpcClient>(
Expand Down Expand Up @@ -35,6 +36,38 @@ pub trait Parser2 {
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parsePragma1Return, ParserError>> + Send;
}

#[cfg(target_family = "wasm")]
pub trait Parser2 {
/// Call Parser contract to parse the provided rainlang text.
fn parse_text<T: JsonRpcClient>(
&self,
text: &str,
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parse2Return, ParserError>>
where
Self: Sync,
{
self.parse(text.as_bytes().to_vec(), client)
}

/// Call Parser contract to parse the provided data
/// The provided data must contain valid UTF-8 encoding of valid rainlang text.
fn parse<T: JsonRpcClient>(
&self,
data: Vec<u8>,
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parse2Return, ParserError>>;

/// Call Parser contract to parse the provided rainlang text and provide the pragma.
/// The provided rainlang text must be valid UTF-8 encoding of valid rainlang text.
fn parse_pragma<T: JsonRpcClient>(
&self,
data: Vec<u8>,
client: ReadableClient<T>,
) -> impl std::future::Future<Output = Result<parsePragma1Return, ParserError>>;
}

/// ParserV2
/// Struct representing ParserV2 instances.
#[derive(Clone, Default)]
Expand Down