Skip to content

Commit

Permalink
Fix Makefile and add building the erc20 binary (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Traian Florin Șerbănuță <[email protected]>
  • Loading branch information
virgil-serbanuta and traiansf authored Dec 18, 2024
1 parent e6216cc commit 731e900
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ ulm-build: $(ULM_GETH_TARGET)
ULM_WASM_TARGET_NAME = ulm-wasm$(if $(ULM_TEST),-test,)

.PHONY: ulm-wasm
ulm-wasm: $(ULM_KRYPTO_TARGET) $(ULM_HOOKS_TARGET) $(ULM_WASM_SRC) pykwasm
ulm-wasm: $(ULM_WASM_TARGET)

$(ULM_WASM_TARGET): $(ULM_KRYPTO_TARGET) $(ULM_HOOKS_TARGET) $(ULM_WASM_SRC) pykwasm
$(KDIST) -v build wasm-semantics.$(ULM_WASM_TARGET_NAME) -j3
$(eval ULM_WASM_DIR := $(shell $(KDIST) which wasm-semantics.$(ULM_WASM_TARGET_NAME)))
kore-rich-header "$(ULM_WASM_DIR)/definition.kore" -o "$(ULM_WASM_DIR)/header.bin"
Expand All @@ -198,6 +200,30 @@ $(ULM_WASM_COMPILER_TARGET): $(ULM_WASM_TARGET)
.PHONY: ulm-contract-compiler
ulm-contract-compiler: $(ULM_WASM_COMPILER_TARGET)

ERC20_DIR=tests/ulm/erc20/rust
ERC20_SRC=$(shell find "$(ERC20_DIR)" -type f -a '(' -name '*.rs' -or -name '*.toml' -or -name '*.lock' ')')

ERC20_BUILD_DIR=build/erc20

ERC20_BIN_TARGET= $(ERC20_BUILD_DIR)/erc20.bin
ERC20_WASM_TARGET= $(ERC20_BUILD_DIR)/erc20.wasm

$(ERC20_BUILD_DIR):
mkdir -p $@

$(ERC20_WASM_TARGET): $(ERC20_SRC) $(ERC20_BUILD_DIR)
cd $(ERC20_DIR) && cargo build --target=wasm32-unknown-unknown --release
cp $(ERC20_DIR)/target/wasm32-unknown-unknown/release/erc20.wasm $@

$(ERC20_BIN_TARGET): $(ERC20_WASM_TARGET) $(ULM_WASM_COMPILER_TARGET) $(ULM_WASM_TARGET)
$(eval ULM_WASM_DIR := $(shell $(KDIST) which wasm-semantics.$(ULM_WASM_TARGET_NAME)))
poetry -C pykwasm run wasm2kore $(ULM_WASM_DIR) $< $(ERC20_BUILD_DIR)/erc20.kore
scripts/compile-contract $(ERC20_BUILD_DIR)/erc20.kore > $@

.PHONY: erc20-bin
erc20-bin: $(ERC20_BIN_TARGET)


# Testing
# -------

Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,13 @@ As an example, to deploy a Wasm contract, you can do the following:
2. Compile the contract:

```sh
# compile Rust to Wasm
pushd tests/ulm/erc20/rust
cargo build --target=wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/erc20.wasm ../
popd
# convert the Wasm to Kore
poetry -C pykwasm run wasm2kore build/wasm tests/ulm/erc20/erc20.wasm tests/ulm/erc20/erc20.kore
# convert the Kore to binary
scripts/compile-contract tests/ulm/erc20/erc20.kore > tests/ulm/erc20/erc20.bin
make erc20-bin
```

3. Deploy the compiled Wasm contract:

```sh
poetry -C pykwasm run deploy tests/ulm/erc20/erc20.bin
poetry -C pykwasm run deploy build/erc20/erc20.bin
```

To invoke a deployed Wasm contract, do the following:
Expand Down

0 comments on commit 731e900

Please sign in to comment.