Skip to content

Commit a9d8dd7

Browse files
authored
Merge pull request #14 from joii2020/main
Add Template: Native Simulator Debug
2 parents c4a147d + b6d79b9 commit a9d8dd7

File tree

23 files changed

+1900
-27
lines changed

23 files changed

+1900
-27
lines changed

atomics-contract/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ckb-std = "0.15.1"
7+
ckb-std = { version = "0.16.3", default-features = false, features = ["allocator", "calc-hash", "ckb-types", "libc"] }
88
log = { version = "0.4.20", default-features = false }
99

1010
[build-dependencies]

atomics-contract/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# RUSTFLAGS that are less likely to be tweaked by developers. Most likely
1111
# one would want to keep the default values here.
1212
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS)

atomics-contract/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![no_std]
1+
#![cfg_attr(not(test), no_std)]
22
#![cfg_attr(not(test), no_main)]
33

44
#[cfg(test)]

cargo-generate.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sub_templates = [
77
"contract",
88
"atomics-contract",
99
"stack-reorder-contract",
10+
"native-simulator",
1011
# Dependency crate templates
1112
"c-wrapper-crate",
1213
"x64-simulator-crate",

contract/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ckb-std = "0.15.1"
7+
ckb-std = "0.16.3"
8+
9+
[features]
10+
native-simulator = ["ckb-std/native-simulator"]

contract/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# RUSTFLAGS that are less likely to be tweaked by developers. Most likely
1111
# one would want to keep the default values here.
1212
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS)
@@ -19,6 +19,7 @@ MODE := release
1919
# we use a bash script with somes heuristics to find clang in current system.
2020
CLANG := $(shell $(TOP)/scripts/find_clang)
2121
AR := $(subst clang,llvm-ar,$(CLANG))
22+
OBJCOPY := $(subst clang,llvm-objcopy,$(CLANG))
2223
# When this is set to some value, the generated binaries will be copied over
2324
BUILD_DIR :=
2425
# Generated binaries to copy. By convention, a Rust crate's directory name will
@@ -41,6 +42,8 @@ build:
4142
for binary in $(BINARIES); do \
4243
echo "Copying binary $$binary to build directory"; \
4344
cp $(TOP)/target/riscv64imac-unknown-none-elf/$(MODE)/$$binary $(TOP)/$(BUILD_DIR); \
45+
cp $(TOP)/$(BUILD_DIR)/$$binary $(TOP)/$(BUILD_DIR)/$$binary.debug; \
46+
$(OBJCOPY) --strip-debug --strip-all $(TOP)/$(BUILD_DIR)/$$binary; \
4447
done \
4548
fi
4649

contract/src/lib.rs

+7
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

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#![no_std]
1+
#![cfg_attr(not(any(feature = "native-simulator", test)), 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/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/target

native-simulator/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "{{project-name}}"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[dependencies]
8+
{{project-name | append: "@@SIMULATOR_PLACEHOLDER@@" | remove: "-sim@@SIMULATOR_PLACEHOLDER@@"}} = { path = "../../contracts/{{project-name | append: "@@SIMULATOR_PLACEHOLDER@@" | remove: "-sim@@SIMULATOR_PLACEHOLDER@@"}}", features = ["native-simulator"] }
9+
ckb-std = { version = "0.16.3", features = ["native-simulator"] }
10+
11+
[lib]
12+
crate-type = ["cdylib"]

native-simulator/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# {{project-name}}
2+
3+
TODO: Write this readme
4+
5+
*This template is used to provide native simulator for a particular contract, and is not designed to be used on its own.*
6+
7+
*This project was bootstrapped with [ckb-script-templates].*
8+
9+
10+
[ckb-script-templates]: https://github.com/cryptape/ckb-script-templates

native-simulator/cargo-generate.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[template]
2+
cargo_generate_version = ">=0.16.0"

native-simulator/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ckb_std::entry_simulator!({{project-name | append: "@@SIMULATOR_PLACEHOLDER@@" | remove: "-sim@@SIMULATOR_PLACEHOLDER@@" | replace: "-", "_"}}::program_entry);

stack-reorder-contract/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ckb-std = "0.15.1"
7+
ckb-std = "0.16.3"
88

99
[build-dependencies]
1010
cc = "1.0"

stack-reorder-contract/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# RUSTFLAGS that are less likely to be tweaked by developers. Most likely
1111
# one would want to keep the default values here.
1212
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS) \

stack-reorder-contract/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![no_std]
1+
#![cfg_attr(not(test), no_std)]
22
#![cfg_attr(not(test), no_main)]
33

44
#[cfg(test)]
@@ -11,6 +11,7 @@ ckb_std::entry!(program_entry);
1111
#[cfg(not(test))]
1212
default_alloc!();
1313

14+
#[allow(unused_variables, unused_assignments)]
1415
pub fn program_entry() -> i8 {
1516
let mut x: u64;
1617
unsafe {

standalone-contract/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ckb-std = "0.15.1"
7+
ckb-std = "0.16.3"
88

99
[dev-dependencies]
10-
ckb-testtool = "0.10.2"
10+
ckb-testtool = "0.14.0"
1111
serde_json = "1.0"

standalone-contract/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# RUSTFLAGS that are less likely to be tweaked by developers. Most likely
1111
# one would want to keep the default values here.
1212
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS)

0 commit comments

Comments
 (0)