Skip to content

Commit

Permalink
The Feature: simulator rename to native-simulator (#102)
Browse files Browse the repository at this point in the history
* Feature simulator rename to native-simulator
  • Loading branch information
joii2020 authored Sep 9, 2024
1 parent 36942aa commit 1a4135e
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["allocator", "ckb-types", "libc", "calc-hash"]
calc-hash = ["ckb-types/calc-hash"]
allocator = ["buddy-alloc"]
simulator = ["ckb-x64-simulator"]
native-simulator = ["ckb-x64-simulator"]
dlopen-c = ["libc"]
build-with-clang = []
libc = []
Expand Down
2 changes: 1 addition & 1 deletion contracts/exec-callee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
simulator = ["ckb-std/simulator"]
native-simulator = ["ckb-std/native-simulator"]

[dependencies]
ckb-std = { path = "../../" }
4 changes: 2 additions & 2 deletions contracts/exec-callee/exec-callee-dbg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
exec-callee = { path = "../", features = ["simulator"] }
ckb-std = { path = "../../../", features = ["simulator"] }
exec-callee = { path = "../", features = ["native-simulator"] }
ckb-std = { path = "../../../", features = ["native-simulator"] }

[lib]
crate-type = ["cdylib"]
Expand Down
6 changes: 3 additions & 3 deletions contracts/exec-callee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "simulator"), no_std)]
#![cfg_attr(not(feature = "native-simulator"), no_std)]

#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
pub mod entry;
#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
pub mod error;
4 changes: 2 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// debug!("hello world");
/// debug!("there is a universal error caused by {}", 42);
/// ```
#[cfg(not(feature = "simulator"))]
#[cfg(not(feature = "native-simulator"))]
#[macro_export]
macro_rules! debug {
($fmt:literal) => {
Expand All @@ -42,7 +42,7 @@ macro_rules! debug {
};
}

#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
#[macro_export]
macro_rules! debug {

Expand Down
8 changes: 6 additions & 2 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ macro_rules! entry {
};
}

#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
#[macro_export]
macro_rules! entry_simulator {
($main:path) => {
Expand All @@ -71,7 +71,11 @@ macro_rules! entry_simulator {
// Arg is the same as *const c_char ABI wise.
argv: *const $crate::env::Arg,
) -> i8 {
let argv = core::slice::from_raw_parts(argv, argc as usize);
let argv = if argc == 0 {
&[]
} else {
core::slice::from_raw_parts(argv, argc as usize)
};
$crate::env::set_argv(argv);
$main()
}
Expand Down
4 changes: 2 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Deref for Arg {
}
}

#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
impl Arg {
pub fn new(arg: &str) -> Self {
Self {
Expand All @@ -53,7 +53,7 @@ pub fn argv() -> &'static [Arg] {
unsafe { ARGV }
}

// For simulator and entry!.
// For native-simulator and entry!.
#[doc(hidden)]
#[inline]
pub unsafe fn set_argv(argv: &'static [Arg]) {
Expand Down
4 changes: 2 additions & 2 deletions src/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ pub fn exec_cell(
hash_type: ScriptHashType,
argv: &[&CStr],
) -> Result<Infallible, SysError> {
#[cfg(not(feature = "simulator"))]
#[cfg(not(feature = "native-simulator"))]
{
let index = look_for_dep_with_hash2(code_hash, hash_type)?;
let ret = syscalls::exec(index, Source::CellDep, 0, 0, argv);
Expand All @@ -664,7 +664,7 @@ pub fn exec_cell(
};
Err(err)
}
#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
syscalls::exec_cell(code_hash, hash_type, argv)
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
//! * `entry!` macro: defines contract entry point
//! * `default_alloc!` and `libc_alloc!` macro: defines global allocator for no-std rust
#![cfg_attr(not(feature = "simulator"), no_std)]
#![cfg_attr(not(feature = "native-simulator"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

#[cfg(not(feature = "rustc-dep-of-std"))]
extern crate alloc;

pub mod ckb_constants;
Expand Down
8 changes: 4 additions & 4 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// re-export to maintain compatible with old versions
pub use crate::error::SysError;

#[cfg(not(feature = "simulator"))]
#[cfg(not(feature = "native-simulator"))]
mod native;
#[cfg(not(feature = "simulator"))]
#[cfg(not(feature = "native-simulator"))]
pub use native::*;

#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
mod simulator;
#[cfg(feature = "simulator")]
#[cfg(feature = "native-simulator")]
pub use simulator::*;
2 changes: 1 addition & 1 deletion src/syscalls/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn load_cell_code(
_index: usize,
_source: Source,
) -> Result<usize, SysError> {
panic!("This is not supported in the simulator!");
panic!("This is not supported in the native-simulator!");
}

pub fn vm_version() -> Result<u64, SysError> {
Expand Down
2 changes: 1 addition & 1 deletion test/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "exec-callee"
path = "src/exec_callee.rs"

[dependencies]
ckb-std = { path = "../..", features = ["ckb-types", "simulator"] }
ckb-std = { path = "../..", features = ["ckb-types", "native-simulator"] }
blake2b-ref = { version = "0.3", default-features = false }
bytes = { version = "1.6.0", default-features = false }
log = { version = "0.4.17", default-features = false }
Expand Down

0 comments on commit 1a4135e

Please sign in to comment.