2018-07-05 08:39:04 +00:00
|
|
|
# Ethereum smart contracts in Nim
|
|
|
|
|
|
|
|
Disclaimer: WIP
|
|
|
|
|
|
|
|
This is a sample of how building eWASM contracts in Nim is possible.
|
|
|
|
Requirements:
|
2018-11-13 12:15:28 +00:00
|
|
|
* clang 7.0 or later with WebAssembly support. Most likely has to be built manually.
|
|
|
|
* 32bit version of libc. On linuxes it is usually provided by the package manager.
|
2018-11-14 08:14:30 +00:00
|
|
|
* `wasm2wat` and `wat2wasm` from [wabt (WebAssembly binary toolkit)](https://github.com/WebAssembly/wabt). They need to be in the `PATH`.
|
2018-07-05 08:39:04 +00:00
|
|
|
* [optional] [wasm-gc](https://github.com/alexcrichton/wasm-gc) optimizer
|
|
|
|
|
|
|
|
## Compiling examples
|
|
|
|
```
|
|
|
|
export WASM_LLVM_BIN=/path/to/llvm/bin/folder
|
|
|
|
nimble examples
|
|
|
|
```
|
|
|
|
|
2018-11-13 12:15:28 +00:00
|
|
|
## Troubleshooting
|
|
|
|
* **Emscripten doesn't work!** It is not expected to. Use clang with wasm target enabled.
|
|
|
|
* **clang is difficult to build.** No, it's easy. Follow these steps:
|
|
|
|
```
|
|
|
|
tag=release_70
|
|
|
|
INSTALL_PREFIX=$(pwd)/llvm-wasm
|
|
|
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/llvm.git
|
|
|
|
cd llvm/tools
|
|
|
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/clang
|
|
|
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/lld
|
|
|
|
cd ..
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly ..
|
|
|
|
make -j 4 install
|
|
|
|
```
|
|
|
|
* **C compiler errors: headers not found.** Make sure you have 32bit libc installed and visible to your clang.
|
|
|
|
|
2018-07-05 08:39:04 +00:00
|
|
|
## License
|
|
|
|
|
2018-12-27 14:35:14 +00:00
|
|
|
Licensed and distributed under either of
|
|
|
|
|
|
|
|
* MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
2018-07-05 08:39:04 +00:00
|
|
|
|
2018-12-27 14:35:14 +00:00
|
|
|
at your option. This file may not be copied, modified, or distributed except according to those terms.
|