Skip to content

Commit

Permalink
Add instructions and error messages about generate-native-simulator (#21
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joii2020 authored Jan 2, 2025
1 parent 81e813d commit 73cbb47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,20 @@ $ make clippy
The template is tailored built for usage outside of workspace, typically, it is not expected to be used inside a workspace. Feel free to compare it with the default `contract` workspace for differences.

This standalone template also has its own test setup, where in a workspace, a dedicated `tests` crate will handle most of the testing work.

### Native Simulator debug

The `generate-native-simulator` command in the `Makefile` generates a native simulator. It **requires** the `CRATE` parameter to specify an existing subproject. If the parameter is missing or invalid, the command will fail.

```bash
make generate-native-simulator CRATE=<subproject_name>
```

To generate a simulator for the `example_crate` subproject:

```bash
make generate-native-simulator CRATE=example_crate
```

- The `CRATE` parameter must refer to a subproject.
- Missing subprojects will cause the command to fail.
10 changes: 9 additions & 1 deletion workspace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,20 @@ generate:

generate-native-simulator:
@set -eu; \
if [ -z "$(CRATE)" ]; then \
echo "Error: Must have CRATE=<Contract Name>"; \
exit 1; \
fi; \
mkdir -p native-simulators; \
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) native-simulator \
-n $(CRATE)-sim \
--destination native-simulators; \
sed '/@@INSERTION_POINT@@/s/$$/\n "native-simulators\/$(CRATE)-sim",/' Cargo.toml > Cargo.toml.new; \
mv Cargo.toml.new Cargo.toml;
mv Cargo.toml.new Cargo.toml; \
if [ ! -f "contracts/$(CRATE)/Cargo.toml" ]; then \
echo "Warning: This is a non-existent contract and needs to be processed manually"; \
echo " Otherwise compilation may fail."; \
fi;

prepare:
rustup target add riscv64imac-unknown-none-elf
Expand Down

0 comments on commit 73cbb47

Please sign in to comment.