Skip to content

Commit

Permalink
feat: also build builtins as a dynamic library
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Apr 14, 2024
1 parent 23593dc commit 6f43b14
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 35 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

9 changes: 0 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ rust.unused_must_use = "deny"
rust.rust_2018_idioms = "deny"
rustdoc.all = "warn"

[profile.bitcode]
inherits = "release"
opt-level = 3
debug = 0
lto = "fat"
strip = "symbols"
panic = "abort"
codegen-units = 1

[workspace.dependencies]
revm-jit = { version = "0.1.0", path = "crates/revm-jit", default-features = false }
revm-jit-backend = { version = "0.1.0", path = "crates/revm-jit-backend", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions crates/revm-jit-builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ repository.workspace = true
exclude.workspace = true

[lib]
crate-type = ["rlib"]
# We want this library both to be available in the final binary for JIT-ing, as well as a dynamic
# library for the AOT-produced object files to link against.
crate-type = ["lib", "dylib"]

[lints]
workspace = true
Expand All @@ -30,6 +32,4 @@ revm-jit-backend = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }

[features]
default = ["std"]
ir = ["dep:revm-jit-backend", "dep:tracing"]
std = ["revm-jit-context/std"]
4 changes: 1 addition & 3 deletions crates/revm-jit-builtins/src/ir.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use revm_jit_backend::{Attribute, Backend, Builder, FunctionAttributeLocation, TypeMethods};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use revm_jit_backend::{Attribute, Backend, Builder, FunctionAttributeLocation, TypeMethods};

/// Builtin cache.
#[derive(Debug)]
Expand Down
6 changes: 2 additions & 4 deletions crates/revm-jit-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(missing_docs, clippy::missing_safety_doc)]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[allow(unused_imports)]
#[macro_use]
Expand All @@ -12,6 +12,7 @@ extern crate alloc;
#[macro_use]
extern crate tracing;

use alloc::{boxed::Box, vec::Vec};
use revm_interpreter::{
as_u64_saturated, as_usize_saturated, gas as rgas, CallInputs, CallScheme, CreateInputs,
InstructionResult, InterpreterAction, InterpreterResult, LoadAccountResult, SStoreResult,
Expand All @@ -23,9 +24,6 @@ use revm_primitives::{
U256,
};

#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};

#[cfg(feature = "ir")]
mod ir;
#[cfg(feature = "ir")]
Expand Down
2 changes: 0 additions & 2 deletions crates/revm-jit-context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ revm-interpreter = { workspace = true, default-features = false }
revm-primitives = { workspace = true, default-features = false }

[features]
default = ["std"]
std = ["revm-interpreter/std", "revm-primitives/std"]
host-ext-any = []
10 changes: 2 additions & 8 deletions crates/revm-jit-context/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[cfg(not(feature = "std"))]
extern crate alloc;

use alloc::vec::Vec;
use core::{fmt, mem::MaybeUninit, ptr};
use revm_interpreter::{
Contract, FunctionStack, Gas, Host, InstructionResult, Interpreter, InterpreterAction,
InterpreterResult, SharedMemory,
};
use revm_primitives::{Address, Bytes, Env, U256};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[cfg(feature = "host-ext-any")]
use core::any::Any;

Expand Down Expand Up @@ -258,7 +255,6 @@ impl EvmStack {

/// Creates a vector that can be used as a stack.
#[inline]
#[cfg(feature = "std")]
pub fn new_heap() -> Vec<EvmWord> {
Vec::with_capacity(1024)
}
Expand All @@ -282,7 +278,6 @@ impl EvmStack {
///
/// Panics if the vector's capacity is less than the required stack capacity.
#[inline]
#[cfg(feature = "std")]
pub fn from_vec(vec: &Vec<EvmWord>) -> &Self {
assert!(vec.capacity() >= Self::CAPACITY);
unsafe { Self::from_ptr(vec.as_ptr()) }
Expand All @@ -306,7 +301,6 @@ impl EvmStack {
/// assert_eq!(stack.as_slice().len(), EvmStack::CAPACITY);
/// ```
#[inline]
#[cfg(feature = "std")]
pub fn from_mut_vec(vec: &mut Vec<EvmWord>) -> &mut Self {
assert!(vec.capacity() >= Self::CAPACITY);
unsafe { Self::from_mut_ptr(vec.as_mut_ptr()) }
Expand Down
8 changes: 4 additions & 4 deletions crates/revm-jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ workspace = true

[dependencies]
revm-jit-backend.workspace = true
revm-jit-builtins = { workspace = true, features = ["ir", "std"] }
revm-jit-context = { workspace = true, features = ["std"] }
revm-jit-builtins = { workspace = true, features = ["ir"] }
revm-jit-context.workspace = true
revm-jit-cranelift = { workspace = true, optional = true }
revm-jit-llvm = { workspace = true, optional = true }

alloy-primitives.workspace = true
alloy-primitives = { workspace = true, features = ["std"] }
revm-interpreter.workspace = true
revm-primitives.workspace = true

Expand All @@ -33,7 +33,7 @@ rustc-hash.workspace = true
tracing.workspace = true

[dev-dependencies]
revm-jit-context = { workspace = true, features = ["std", "host-ext-any"] }
revm-jit-context = { workspace = true, features = ["host-ext-any"] }
paste = "1.0"

[features]
Expand Down
1 change: 1 addition & 0 deletions crates/revm-jit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate tracing;
#[macro_use]
extern crate revm_jit_backend;

// For features.
use alloy_primitives as _;

mod bytecode;
Expand Down

0 comments on commit 6f43b14

Please sign in to comment.