Skip to content

Commit

Permalink
C/C++ guide fixes, links
Browse files Browse the repository at this point in the history
  • Loading branch information
poemm committed Dec 6, 2018
1 parent 79d99ad commit da24bdd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions c_cpp_guide.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# C/C++ to ewasm contracts
# Compiling C/C++ to Ewasm

First an introduction to discuss quirks, then a step-by-step guide for how to compile ewasm contracts from C and C++. Warning: the ewasm spec and tools below are subject to change.

## Introduction

An ewasm contracts is a WebAssembly module with restrictions. The module's imports must be among the [ewasm helper functions](https://github.com/ewasm/design/blob/master/eth_interface.md) which resemble EVM opcodes to interact with the client. The module's exports must be a `main` function which takes no arguments and returns nothing, and the `memory` of the module. The module can't using floats and other non-determinisms.
An ewasm contract is a WebAssembly module with restrictions. The module's imports must be among the [ewasm helper functions](https://github.com/ewasm/design/blob/master/eth_interface.md) which resemble EVM opcodes to interact with the client. The module's exports must be a `main` function which takes no arguments and returns nothing, and the `memory` of the module. The module can't using floats and other sources of non-determinism.

There are four quirks to using C/C++ to write ewasm smart contracts. These quirks may improve as tools and ewasm improve.

Expand All @@ -24,13 +24,13 @@ The wasmception package offers patches to libc and libc++ which allow using `mal
```sh
git clone https://github.com/yurydelendik/wasmception.git
cd wasmception
make -j4 # Warning: this required lots of bandwidth, RAM, and time. One hours on a mid-level laptop.
make -j4 # Warning: this required lots of bandwidth, RAM, and time. One hour on a mid-level laptop.
cd ..
```

Write down the end of the output of the above make command, it should be something like: `--sysroot=/home/user/repos/wasmception/sysroot`.

Next we modified the wasmception examples into an ewasm contract, and is available for download. Make sure to edit the Makefile with the sysroot above, and change the path to our newly compiled version of clang to something like `/home/user/repos/wasmception/dist/bin/clang`. Make sure that `main.syms` has a list of ewasm helper functions you are using. If you are using C++, make sure to modify the Makefile to clang++, use `extern "C"` around the helper function declarations, and follow other tips from wasmception.
We modified the wasmception example into an ewasm contract, which we will now download. Make sure to edit the Makefile with the sysroot above, and change the path to our newly compiled version of clang to something like `/home/user/repos/wasmception/dist/bin/clang`. Make sure that `main.syms` has a list of ewasm helper functions you are using. If you are using C++, make sure to modify the Makefile to clang++, use `extern "C"` around the helper function declarations, and follow other tips from wasmception.

```sh
git clone https://gist.github.com/poemm/91b64ecd2ca2f1cb4a88d31315313b9b.git cwrc20
Expand All @@ -41,7 +41,7 @@ make

The output is `main.wasm`, but it needs some cleanup to remove some of it's extra import and export junk. For this, we use PyWebAssembly.

Aside: Alternatively, one can use a rust implementation of `wasm_chisel`. But that requires a rust compiler.
Aside: Alternatively, one can use a rust implementation of [wasm-chisel](https://github.com/wasmx/wasm-chisel), or install with `cargo install chisel`. But that requires a rust compiler.
```
cd ..
git clone https://github.com/poemm/pywebassembly.git
Expand All @@ -65,4 +65,4 @@ cd ../../cwrc20
../binaryen/build/bin/wasm-dis main_chiseled.wasm > main_chiseled.wat
```

Now `main_chiseled.wat` can be pasted into ewasm explorer and deployed. Happy hacking!
Now `main_chiseled.wat` can be pasted into [ewasm studio](http://ewasm.ethereum.org/studio/) and deployed. Happy hacking!

0 comments on commit da24bdd

Please sign in to comment.