diff --git a/Cargo.toml b/Cargo.toml index 0683fa1..6024ee0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/contracts/exec-callee/Cargo.toml b/contracts/exec-callee/Cargo.toml index 4389412..a6fc783 100644 --- a/contracts/exec-callee/Cargo.toml +++ b/contracts/exec-callee/Cargo.toml @@ -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 = "../../" } diff --git a/contracts/exec-callee/exec-callee-dbg/Cargo.toml b/contracts/exec-callee/exec-callee-dbg/Cargo.toml index b0295a2..a644a8e 100644 --- a/contracts/exec-callee/exec-callee-dbg/Cargo.toml +++ b/contracts/exec-callee/exec-callee-dbg/Cargo.toml @@ -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"] diff --git a/contracts/exec-callee/src/lib.rs b/contracts/exec-callee/src/lib.rs index ba66e49..b5e1182 100644 --- a/contracts/exec-callee/src/lib.rs +++ b/contracts/exec-callee/src/lib.rs @@ -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; diff --git a/src/debug.rs b/src/debug.rs index 191e223..e15e0d8 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -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) => { @@ -42,7 +42,7 @@ macro_rules! debug { }; } -#[cfg(feature = "simulator")] +#[cfg(feature = "native-simulator")] #[macro_export] macro_rules! debug { diff --git a/src/entry.rs b/src/entry.rs index 7a1cddc..9a0ab1e 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -59,7 +59,7 @@ macro_rules! entry { }; } -#[cfg(feature = "simulator")] +#[cfg(feature = "native-simulator")] #[macro_export] macro_rules! entry_simulator { ($main:path) => { @@ -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() } diff --git a/src/env.rs b/src/env.rs index ad8565f..cebde4f 100644 --- a/src/env.rs +++ b/src/env.rs @@ -32,7 +32,7 @@ impl Deref for Arg { } } -#[cfg(feature = "simulator")] +#[cfg(feature = "native-simulator")] impl Arg { pub fn new(arg: &str) -> Self { Self { @@ -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]) { diff --git a/src/high_level.rs b/src/high_level.rs index 1684250..6e2cad7 100644 --- a/src/high_level.rs +++ b/src/high_level.rs @@ -653,7 +653,7 @@ pub fn exec_cell( hash_type: ScriptHashType, argv: &[&CStr], ) -> Result { - #[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); @@ -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) } diff --git a/src/lib.rs b/src/lib.rs index f656e62..20eb594 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 1a05217..742e335 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -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::*; diff --git a/src/syscalls/simulator.rs b/src/syscalls/simulator.rs index 88ba05f..8312dd2 100644 --- a/src/syscalls/simulator.rs +++ b/src/syscalls/simulator.rs @@ -211,7 +211,7 @@ pub fn load_cell_code( _index: usize, _source: Source, ) -> Result { - panic!("This is not supported in the simulator!"); + panic!("This is not supported in the native-simulator!"); } pub fn vm_version() -> Result { diff --git a/test/simulator/Cargo.toml b/test/simulator/Cargo.toml index 3bcad82..b35fd86 100644 --- a/test/simulator/Cargo.toml +++ b/test/simulator/Cargo.toml @@ -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 }