3 releases
0.4.3 | Apr 11, 2024 |
---|---|
0.4.2 | Aug 31, 2023 |
0.4.1 | Jul 12, 2023 |
#2 in #parallel-chain
156 downloads per month
50KB
873 lines
ParallelChain Mainnet Contract Compiler (pchain_compile)
pchain_compile
is a command line tool for reproducibly building Rust code into compact, gas-efficient WebAssembly ParallelChain Mainnet Smart Contracts.
Pre-Requisites
pchain_compile
compiles the ParallelChain smart contract code from Rust into a WebAssembly binary. To know more about developing ParallelChain smart contracts, visit ParallelChain Mainnet Contract SDK.
By default, the compiler requires docker to be installed in your local machine. In detail, it pulls the Docker Image from DockerHub, and starts a docker container which provides a complete environment for building WebAssembly binary. To install docker, follow the instructions in Docker Docs.
Installation
Download prebuilt executables from the Github Releases page.
Alternatively, you can install the binary crate pchain_compile by cargo install if Rust has been installed already.
cargo install pchain_compile
Build Smart Contract
Let's say your smart contract source code is in the folder contract
under your home directory.
/home/
|- user/
|- contract/
|- src/
|- lib.rs
|- Cargo.toml
Run pchain_compile
with the arguments source and destination to specify the folder of the source code and the folder for saving the result.
pchain_compile build --source /home/user/contract --destination /home/user/result
Once complete, the console displays message:
Build process started. This could take several minutes for large contracts.
Finished compiling. ParallelChain Mainnet smart contract(s) ["contract.wasm"] are saved at (/home/user/result).
Your WebAssembly smart contract is now saved with file extension .wasm
at the destination folder.
If you are running on Windows, here is the example output:
$ .\pchain_compile.exe build --source 'C:\Users\user\contract' --destination 'C:\Users\user\result'
Build process started. This could take several minutes for large contracts.
Finished compiling. ParallelChain Mainnet smart contract(s) ["contract.wasm"] are saved at (C:\Users\user\result).
To understand more about the commands and arguments, run pchain_compile build --help
.
Using The pchain_compile
Docker Image
pchain_compile
pulls a docker image from ParallelChain Lab's official DockerHub repository for the build process. The docker image provides an environment with installed components:
- rustc: compiler for Rust.
- wasm-snip: WASM utility which removes functions that are never called at runtime.
- wasm-opt: WASM utility to load WebAssembly in text format and run Binaryen IR passes to optimize its size. For more information on Binaryen IR see here.
There are different tags of the docker image. They vary on the versions of the components. The table below describes the tags and their differences.
Image Tag | rustc | wasm-snip | wasm-opt |
---|---|---|---|
0.4.3 | 1.77.1 | 0.4.0 | 114 |
0.4.2 | 1.71.0 | 0.4.0 | 114 |
mainnet01 | 1.66.1 | 0.4.0 | 109 |
To build a smart contract in a specific docker environment, run with argument use-docker-tag. For example,
pchain_compile build --source /home/user/contract --destination /home/user/result --use-docker-tag 0.4.3
If use-docker-tag is not used, the docker image tag is determined by the version of pchain_compile
. For example, pchain_compile
v0.4.3 will pull the docker image with tag 0.4.3
.
Dependencies
~70–105MB
~2M SLoC