Skip to content

Commit ea8a4d9

Browse files
committed
Contract add feature: native-simulator
* Contracts support native-simulator by default. * native-simulator project no longer requires scripts to add code to contracts. * simulator renamed to native-simulator.
1 parent 6f01a72 commit ea8a4d9

File tree

7 files changed

+18
-28
lines changed

7 files changed

+18
-28
lines changed

contract/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
ckb-std = "0.15.3"
8+
9+
[features]
10+
native-simulator = ["ckb-std/native-simulator"]

contract/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![cfg_attr(not(feature = "native-simulator"), no_std)]
2+
#![allow(special_module_name)]
3+
#![allow(unused_attributes)]
4+
#[cfg(feature = "native-simulator")]
5+
mod main;
6+
#[cfg(feature = "native-simulator")]
7+
pub use main::program_entry;

contract/src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#![no_std]
1+
#![cfg_attr(not(feature = "native-simulator"), no_std)]
22
#![cfg_attr(not(test), no_main)]
33

4-
#[cfg(test)]
4+
#[cfg(any(feature = "native-simulator", test))]
55
extern crate alloc;
66

7-
#[cfg(not(test))]
8-
use ckb_std::default_alloc;
9-
#[cfg(not(test))]
7+
#[cfg(not(any(feature = "native-simulator", test)))]
108
ckb_std::entry!(program_entry);
11-
#[cfg(not(test))]
12-
default_alloc!();
9+
#[cfg(not(any(feature = "native-simulator", test)))]
10+
ckb_std::default_alloc!();
1311

1412
pub fn program_entry() -> i8 {
1513
ckb_std::debug!("This is a sample contract!");

native-simulator/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[dependencies]
8-
{{contract_name}} = { path = "../../contracts/{{contract_name}}", features = ["simulator"] }
9-
ckb-std = { version = "0.15.3", features = ["simulator"] }
8+
{{contract_name}} = { path = "../../contracts/{{contract_name}}", features = ["native-simulator"] }
9+
ckb-std = { version = "0.15.3", features = ["native-simulator"] }
1010

1111
[lib]
1212
crate-type = ["cdylib"]

native-simulator/src/contract-lib.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

workspace/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ debug = true
1616

1717
# TODO: Will be deleted after release
1818
[replace]
19-
"ckb-std:0.15.3" = { git = "https://github.com/nervosnetwork/ckb-std.git", rev = "36942aa" }
19+
"ckb-std:0.15.3" = { git = "https://github.com/joii2020/ckb-std.git", rev = "76f1ac3" }

workspace/Makefile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ generate-native-simulator:
129129
--destination native-simulators \
130130
-d contract_name=$(CRATE) \
131131
-d contract_crate_name=`echo "$(CRATE)" | tr '-' '_'`; \
132-
mv native-simulators/$(CRATE)-sim/src/contract-lib.rs contracts/$(CRATE)/src/lib.rs; \
133-
FILE=contracts/$(CRATE)/Cargo.toml; \
134-
if grep -q "\\[features\\]" "$$FILE"; then \
135-
sed -i '/\[features\]/a\\simulator = \[\"ckb-std/simulator\"\]' $$FILE; \
136-
else \
137-
echo "\\n[features]\\nsimulator = [\"ckb-std/simulator\"]\\n" >> $$FILE ; \
138-
fi; \
139-
FILE=contracts/$(CRATE)/src/main.rs; \
140-
sed -i 's/#!\[no_std\]/#!\[cfg_attr(not(feature = "simulator"), no_std)\]/' $$FILE; \
141-
sed -i 's/#\[cfg(test)\]/#\[cfg(any(feature = "simulator", test))\]/' $$FILE; \
142-
sed -i 's/#\[cfg(not(test))\]/#\[cfg(not(any(feature = "simulator", test)))\]/' $$FILE; \
143132
sed '/@@INSERTION_POINT@@/s/$$/\n "native-simulators\/$(CRATE)-sim",/' Cargo.toml > Cargo.toml.new; \
144133
mv Cargo.toml.new Cargo.toml;
145134

0 commit comments

Comments
 (0)