Skip to content

Commit c261f84

Browse files
committed
Optimize the process of adding simulator
1 parent f94d717 commit c261f84

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

add-debugger/src/contract-lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(not(feature = "simulator"), no_std)]
2-
3-
// This file will be automatically placed in the contract file, and rename to lib.rs
4-
5-
// #[cfg(feature = "simulator")]
6-
// pub mod entry;
2+
#![allow(special_module_name)]
3+
#[cfg(feature = "simulator")]
4+
mod main;
5+
#[cfg(feature = "simulator")]
6+
pub use main::program_entry;

add-debugger/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
ckb_std::entry_simulator!(program_entry);
2-
3-
/// program entry
4-
fn program_entry() -> i8 {
5-
// Call main function and return error code
6-
// match {{contract_crate_name}}::entry::main() {
7-
// Ok(_) => 0,
8-
// Err(err) => err as i8,
9-
// }
10-
0
11-
}
1+
ckb_std::entry_simulator!({{contract_crate_name}}::program_entry);

contract/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ build:
4444
done \
4545
fi
4646

47+
build-simulator:
48+
cd {{project-name}}-dbg && cargo build $(MODE_ARGS) && cp target/$(MODE)/*_dbg.* $(TOP)/$(BUILD_DIR)
49+
4750
# test, check, clippy and fmt here are provided for completeness,
4851
# there is nothing wrong invoking cargo directly instead of make.
4952
test:

contract/src/main.rs

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

44
#[cfg(test)]
55
extern crate alloc;
66

7-
#[cfg(not(test))]
7+
#[cfg(not(any(feature = "simulator", test)))]
88
use ckb_std::default_alloc;
9-
#[cfg(not(test))]
9+
#[cfg(not(any(feature = "simulator", test)))]
1010
ckb_std::entry!(program_entry);
11-
#[cfg(not(test))]
11+
#[cfg(not(any(feature = "simulator", test)))]
1212
default_alloc!();
1313

1414
pub fn program_entry() -> i8 {

workspace/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ build:
4848
$(MAKE) -e -C contracts/$(CONTRACT) build; \
4949
fi
5050

51+
build-simulator:
52+
mkdir -p $(BUILD_DIR)
53+
@set -eu; \
54+
if [ "x$(CONTRACT)" = "x" ]; then \
55+
for contract in $(wildcard contracts/*); do \
56+
$(MAKE) -e -C $$contract build-simulator; \
57+
done; \
58+
else \
59+
$(MAKE) -e -C contracts/$(CONTRACT) build-simulator; \
60+
fi
61+
5162
# Run a single make task for a specific contract. For example:
5263
#
5364
# make run CONTRACT=stack-reorder TASK=adjust_stack_size STACK_SIZE=0x200000
@@ -88,6 +99,7 @@ TEMPLATE_REPO := https://github.com/cryptape/ckb-script-templates
8899
CRATE :=
89100
TEMPLATE := contract
90101
DESTINATION := contracts
102+
ALSO_ADD_DEBUGGER := true
91103
generate:
92104
@set -eu; \
93105
if [ "x$(CRATE)" = "x" ]; then \

0 commit comments

Comments
 (0)