Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Template: Native Simulator Debug #14

Merged
merged 44 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
23f8e89
Support add debugger
joii2020 Jul 12, 2024
1346f63
remove default_alloc
joii2020 Jul 15, 2024
1304d24
Auto add feature simulator to contract
joii2020 Jul 16, 2024
dce5def
Optimize the process of adding simulator
joii2020 Jul 17, 2024
c77a4f3
Add load_binary_dbg and support native simulator debug
joii2020 Jul 17, 2024
6bbadcd
Fix error
joii2020 Jul 17, 2024
7a7e7cc
revert tests/lib.rs
joii2020 Jul 18, 2024
b5697f6
test add feature simulator
joii2020 Jul 18, 2024
c946ef2
Optimizing Makefile dependencies
joii2020 Jul 22, 2024
756ddb2
Fix some bugs in add-debugger
joii2020 Jul 29, 2024
d45d74a
ckb-testtool version update to 0.12.0
joii2020 Jul 29, 2024
41aa9e3
Some dependencies are replaced with those in git
joii2020 Jul 29, 2024
e903a59
Update ckb-testtool version
joii2020 Aug 1, 2024
490b0c2
Rename add-debugger to native-simulator
joii2020 Aug 22, 2024
c283df9
Add doc: debugging contract
joii2020 Aug 26, 2024
9b983f1
Update docs
joii2020 Aug 26, 2024
5fc5cb6
Fix CI error
joii2020 Aug 26, 2024
295bf10
Refactore: Native simulator debug project move to native-simulator
joii2020 Aug 31, 2024
a90a243
Delete unused code in workspace/Makefile
joii2020 Sep 2, 2024
997b5c2
Revert contract/src/main.rs
joii2020 Sep 2, 2024
0d7e913
Fix bug about generate native simulator
joii2020 Sep 2, 2024
0052926
Remove documentation about debugging
joii2020 Sep 2, 2024
ec8e3a1
Allow warning (stack-reorder-contract)
joii2020 Sep 4, 2024
d556ad9
Refactore generate native-simulator
joii2020 Sep 4, 2024
3228683
ckb-std lock specific version
joii2020 Sep 4, 2024
0c25da1
Update the description about native simulator
joii2020 Sep 4, 2024
6517a72
Fix make check error when add native simulator
joii2020 Sep 5, 2024
aa8a2f0
Add a comment about profile.ckb-debug
joii2020 Sep 5, 2024
b98b2a3
Delete the commented out code
joii2020 Sep 5, 2024
8403fce
build-simulator merge to build
joii2020 Sep 5, 2024
d30d2e3
The built contract has symbols and is deleted using objcopy
joii2020 Sep 5, 2024
30f44d6
ckb-std update to 0.15.3
joii2020 Sep 5, 2024
39da951
Contract add feature: native-simulator
joii2020 Sep 6, 2024
e19c9b3
Fix error: x64-simulator-crate simulator rename to native-simulator
joii2020 Sep 8, 2024
09fdcde
Optiomization workspace/Makefile build
joii2020 Sep 11, 2024
1ff8ac9
Using Liquid to process templates
joii2020 Sep 11, 2024
d81d8d0
Optimize cargo-generate rules
joii2020 Sep 24, 2024
a0a0d4e
Optimize cargo-generate rules in native-simulator lib.rs
joii2020 Sep 24, 2024
3215d67
Update ckb-std rev
joii2020 Sep 24, 2024
2ea0734
Update dependencies: ckb-std and ckb-testtool
joii2020 Nov 1, 2024
ab116fa
Fix CI
joii2020 Nov 1, 2024
8e8a9d9
Fix CI: on Makfile about CUSTOM_RUSTFLAGS
joii2020 Nov 1, 2024
9db520e
Update ckb-std to 0.16.3
joii2020 Nov 1, 2024
b6d79b9
Typos: Makefile CUSTOM_RUSTFLAGS
joii2020 Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atomics-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-std = "0.15.1"
ckb-std = "0.15.3"
log = { version = "0.4.20", default-features = false }

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sub_templates = [
"contract",
"atomics-contract",
"stack-reorder-contract",
"native-simulator",
# Dependency crate templates
"c-wrapper-crate",
"x64-simulator-crate",
Expand Down
5 changes: 4 additions & 1 deletion contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-std = "0.15.1"
ckb-std = "0.15.3"

[features]
native-simulator = ["ckb-std/native-simulator"]
3 changes: 3 additions & 0 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MODE := release
# we use a bash script with somes heuristics to find clang in current system.
CLANG := $(shell $(TOP)/scripts/find_clang)
AR := $(subst clang,llvm-ar,$(CLANG))
OBJCOPY := $(subst clang,llvm-objcopy,$(CLANG))
# When this is set to some value, the generated binaries will be copied over
BUILD_DIR :=
# Generated binaries to copy. By convention, a Rust crate's directory name will
Expand All @@ -41,6 +42,8 @@ build:
for binary in $(BINARIES); do \
echo "Copying binary $$binary to build directory"; \
cp $(TOP)/target/riscv64imac-unknown-none-elf/$(MODE)/$$binary $(TOP)/$(BUILD_DIR); \
cp $(TOP)/$(BUILD_DIR)/$$binary $(TOP)/$(BUILD_DIR)/$$binary.debug; \
$(OBJCOPY) --strip-debug --strip-all $(TOP)/$(BUILD_DIR)/$$binary; \
done \
fi

Expand Down
7 changes: 7 additions & 0 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![cfg_attr(not(feature = "native-simulator"), no_std)]
#![allow(special_module_name)]
#![allow(unused_attributes)]
#[cfg(feature = "native-simulator")]
mod main;
#[cfg(feature = "native-simulator")]
pub use main::program_entry;
12 changes: 5 additions & 7 deletions contract/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#![no_std]
#![cfg_attr(not(feature = "native-simulator"), no_std)]
#![cfg_attr(not(test), no_main)]

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

#[cfg(not(test))]
use ckb_std::default_alloc;
#[cfg(not(test))]
#[cfg(not(any(feature = "native-simulator", test)))]
ckb_std::entry!(program_entry);
#[cfg(not(test))]
default_alloc!();
#[cfg(not(any(feature = "native-simulator", test)))]
ckb_std::default_alloc!();

pub fn program_entry() -> i8 {
ckb_std::debug!("This is a sample contract!");
Expand Down
2 changes: 2 additions & 0 deletions native-simulator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/target
12 changes: 12 additions & 0 deletions native-simulator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "{{project-name}}"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
{{project-name | append: "@@SIMULATOR_PLACEHOLDER@@" | remove: "-sim@@SIMULATOR_PLACEHOLDER@@"}} = { path = "../../contracts/{{project-name | append: "@@SIMULATOR_PLACEHOLDER@@" | remove: "-sim@@SIMULATOR_PLACEHOLDER@@"}}", features = ["native-simulator"] }
ckb-std = { version = "0.15.3", features = ["native-simulator"] }

[lib]
crate-type = ["cdylib"]
10 changes: 10 additions & 0 deletions native-simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# {{project-name}}

TODO: Write this readme
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please state it clearly that this template is used to provide native simulator for a particular contract, and is not designed to be used on its own.

Right now this README resembles the README for a typical contract too much.


*This template is used to provide native simulator for a particular contract, and is not designed to be used on its own.*

*This project was bootstrapped with [ckb-script-templates].*


[ckb-script-templates]: https://github.com/cryptape/ckb-script-templates
2 changes: 2 additions & 0 deletions native-simulator/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[template]
cargo_generate_version = ">=0.16.0"
1 change: 1 addition & 0 deletions native-simulator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ckb_std::entry_simulator!({{project-name | remove: "-sim" | replace: "-", "_"}}::program_entry);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same technique above to append a placeholder first, then remove -sim together with the placeholder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I neglected it, I will change it.

2 changes: 1 addition & 1 deletion stack-reorder-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-std = "0.15.1"
ckb-std = "0.15.3"

[build-dependencies]
cc = "1.0"
1 change: 1 addition & 0 deletions stack-reorder-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ckb_std::entry!(program_entry);
#[cfg(not(test))]
default_alloc!();

#[allow(unused_variables, unused_assignments)]
pub fn program_entry() -> i8 {
let mut x: u64;
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions standalone-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-std = "0.15.1"
ckb-std = "0.15.3"

[dev-dependencies]
ckb-testtool = "0.10.2"
ckb-testtool = "0.13.0"
serde_json = "1.0"
Loading
Loading