Quick Start
Installation
The Olac compiler is a single binary. It can be installed in different ways, listed below.
Option 1: Download from Brew
Olac is available on Brew via a private tap. This works only for MacOS systems, both Intel and Apple Silicon. To install Olac via Brew, run the following command:
Option 2: Download binaries
There are binaries available on github releases
Download the file and save it somewhere in your $PATH
, for example the bin directory in your home directory. If the path you use is not already in $PATH
, then you need to add it yourself.
On MacOS, remember to give execution permission to the file and remove it from quarantine by executing the following commands:
If you are using an Intel based Mac, please, exchange olac-mac-arm
by olac-mac-intel
in both of the above commands.
On Linux, permission to execute the binary is also necessary, so, please, run chmod +x olac-linux-x86-64
.
Option 3: Build Olac from source
In order to build Olac from source, you will need:
Rust nightly version 1.72.0 or higher
A pre-built LLVM Libraries, version 15.0.7
Step 1: Install Rust
If you do not have the correct version of rust installed, go to rustup.
Step 2: Install the LLVM Libraries
Ola needs a build of LLVM Libraries, You can download the pre-built libraries from github After that, you need to add the bin
of your LLVM directory to your path, so that the build system of O la c can find the correct version of LLVM to use.
Linux(Ubuntu)
A pre-built version of LLVM, is available at https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.6/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz
You need to replace your llvm download directory here.
Windows
For Windows users, the official LLVM does not provide additional tools like llvm-config
, which causes Olac to fail to build. Therefore, we provide pre-built versions for Windows. is available at https://github.com/Sin7Y/ola-llvm/releases/download/llvm15-0/llvm15.0-win.zip
After unzipping the file, add the bin directory to your path.
You need to replace your llvm download directory here.
Mac
For macOS users, you can download the llvm official build package. A pre-built version of LLVM for intel macs, is available at https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz. After downloading, untar the file in a terminal and add it to your path like so:
arm macs there is https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-arm64-apple-darwin22.0.tar.xz After downloading, untar the file in a terminal and add it to your path like so:
You need to replace your llvm download directory here.
After you finish installing LLVM, you should try the llvm-config command to check if the output version is correct.
Step 3: Build Olac
Once you have the correct LLVM version in your path, simply run:
If you encounter the following error message, then you need to check if llvm is installed correctly and if the llvm-config command can be executed correctly.
error: No suitable version of LLVM was found system-wide or pointed to by LLVM_SYS_150_PREFIX.
After you ensure that the LLVM environment variable is configured, you can clean the cargo build cache and re-build.
The executable will be in target/release/olac
Alternative step 3: Build Olac from crates.io
The latest Ola release is on crates.io. Once you have the correct LLVM version in your path, ensure you have GNU make installed and simply run:
Using olac on the command line
The olac compiler is run on the command line. The ola source file names are provided as command line arguments; the output is an optimized asm file and anabi file (also known as the abi).
Compiler Usage
olac compile [OLA SOURCE FILE] ... [OPTIONS]…
Assuming there is a Fibonacci sequence contract, the command to compile this contract is:
The above command will generate the files fib_abi.json
and fib_asm.json
.
Ola supports some debug mode options. This means that the command line is olac compile
followed by any options described below, followed by one source file.
Options:
--gen phase
This option is can be used for debugging Olac itself. This is used to output early phases of compilation.
abi Ouput Ola contract's ABI information
ast Output Abstract Syntax Tree as a graphviz dot file. This can be viewed with xdot or any other tool that can visualize graphviz dot files.
llvm-ir Output llvm IR as text.
asm Output assembly text file.
Write Ola using an IDE
Ola supports writing on vscode, we have developed an extension to vscode to support ola syntax highlighting, and we will continue to improve the plugin in the future.
The extension can be found on the Visual Studio Marketplace.
Hello Ola
After configuring the above environment, we can happily write Ola smart contracts named fib.ola on vscode with ola extension. The following is an example of a Fibonacci sequence.
Compile this contract next.
The above command will generate the files fib_abi.json
and fib_asm.json
. fib_abi.json
is the ABI file of the contract, which will be used by ola-sdk to build contract request transactions. fib_asm.json
is the assembly form of the contract source code, used for contract deployment and invocation.
Last updated