Skip to content

Commit 54a7c79

Browse files
committed
Fix bug about generate native simulator
1 parent e4fe820 commit 54a7c79

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

native-simulator/GlobalMakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ MODE := release
66
BUILD_DIR := ../build/$(MODE)
77

88
build:
9-
mkdir -p ../$(BUILD_DIR)
9+
mkdir -p $(BUILD_DIR)
1010
@set -eu; \
1111
if [ "x$(CONTRACT)" = "x" ]; then \
1212
for contract in $(wildcard ./*); do \
1313
if [ -f $$contract/Cargo.toml ]; then \
14-
cd $$contract && cargo build && cp target/debug/*_dbg.* ../$(BUILD_DIR); \
14+
cd $$contract && cargo build && cp target/debug/*_sim.* ../$(BUILD_DIR)/; \
1515
fi; \
1616
done; \
1717
else \

workspace/scripts/generate-native-simulator

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ "$CONTRACT_NAME" = "_" ]; then
1414
contracts=()
1515
for i in "${!folders[@]}"; do
1616
contract_name=$(echo "${folders[$i]}" | awk -F'/' '{print $(NF-1)}')
17-
if [ ! -d "${folders[$i]}/${contract_name}-dbg" ]; then
17+
if [ ! -d "${folders[$i]}/${contract_name}-sim" ]; then
1818
contracts+=("${contract_name}")
1919
fi
2020
done
@@ -54,15 +54,22 @@ SIMULATOR_NAME=${CONTRACT_NAME}-sim
5454
cargo generate $2 $3 native-simulator -n $SIMULATOR_NAME --destination native-simulators -d contract_name=$CONTRACT_NAME -d contract_crate_name=$CONTRACT_CRATE
5555
mv native-simulators/$SIMULATOR_NAME/src/contract-lib.rs contracts/$CONTRACT_NAME/src/lib.rs
5656

57+
if [ ! -d 'native-simulators/Makefile' ]; then
58+
mv native-simulators/$SIMULATOR_NAME/GlobalMakefile native-simulators/Makefile
59+
else
60+
rm -f native-simulators/$SIMULATOR_NAME/GlobalMakefile
61+
fi
62+
63+
# Insert feature: simulator into Cargo.toml
5764
FILE=contracts/$CONTRACT_NAME/Cargo.toml
5865
if grep -q "\[features\]" "$FILE"; then
5966
sed -i '/\[features\]/a\simulator = ["ckb-std/simulator"]' "$FILE"
6067
else
6168
echo -e "\n[features]\nsimulator = [\"ckb-std/simulator\"]" >> "$FILE"
6269
fi
6370

64-
if [ ! -d 'native-simulators/Makefile' ]; then
65-
mv native-simulators/$SIMULATOR_NAME/GlobalMakefile native-simulators/Makefile
66-
else
67-
rm -f native-simulators/$SIMULATOR_NAME/GlobalMakefile
68-
fi
71+
FILE=contracts/$CONTRACT_NAME/src/main.rs
72+
sed -i 's/#!\[no_std\]/#!\[cfg_attr(not(feature = "simulator"), no_std)\]/' $FILE
73+
sed -i 's/#!\[cfg_attr(not(test), no_main)\]/#!\[cfg_attr(not(any(feature = "simulator", test)), no_main)\]/' $FILE
74+
sed -i 's/#\[cfg(test)\]/#\[cfg(any(feature = "simulator", test))\]/' $FILE
75+
sed -i 's/#\[cfg(not(test))\]/#\[cfg(not(any(feature = "simulator", test)))\]/' $FILE

0 commit comments

Comments
 (0)