You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: c_cpp_guide.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# C/C++ to ewasm contracts
1
+
# Compiling C/C++ to Ewasm
2
2
3
3
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.
4
4
5
5
## Introduction
6
6
7
-
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.
7
+
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.
8
8
9
9
There are four quirks to using C/C++ to write ewasm smart contracts. These quirks may improve as tools and ewasm improve.
10
10
@@ -24,13 +24,13 @@ The wasmception package offers patches to libc and libc++ which allow using `mal
make -j4 # Warning: this required lots of bandwidth, RAM, and time. One hours on a mid-level laptop.
27
+
make -j4 # Warning: this required lots of bandwidth, RAM, and time. One hour on a mid-level laptop.
28
28
cd ..
29
29
```
30
30
31
31
Write down the end of the output of the above make command, it should be something like: `--sysroot=/home/user/repos/wasmception/sysroot`.
32
32
33
-
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.
33
+
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.
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.
43
43
44
-
Aside: Alternatively, one can use a rust implementation of `wasm_chisel`. But that requires a rust compiler.
44
+
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.
0 commit comments