Build Argentum compiler on Ubuntu

Preparations

Install GCC and friends:

sudo apt-get update
sudo apt-get install build-essential

Install Ninja build system and CMake

sudo apt-get -y install ninja-build
sudo apt-get install cmake

LLVM

Get LLVM sources:

mkdir ~/cpp/
cd ~/cpp/
wget -qO llvm.tgz \
https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-17.0.4.tar.gz

tar -xzf llvm.tgz
rm llvm.tgz
mv llvm-project-llvmorg-17.0.4/ llvm-17.0.4-src

Prepare build files:

cd ~/cpp/llvm-17.0.4-src
mkdir build-rel

cmake -S llvm -B build-rel -G Ninja \
-DLLVM_BUILD_RUNTIME=OFF -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_BUILD_UTILS=OFF \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DCMAKE_INSTALL_PREFIX=$(pwd)/../llvm17.0.4-rel

Build LLVM (this will take ~~hour)

cmake --build build-rel

Install LLVM to out dir

cmake --build build-rel --target install

Now ~/cpp/llvm17.0.4-rel contains the newly built release version of LLVM

SDL

Install dev versions SDL and SDL_image:

sudo apt install libsdl2-dev
sudo apt install libjpeg-dev libwebp-dev libtiff5-dev libsdl2-image-dev
sudo apt install libsdl2-ttf-dev

Some versions of libsdl2-image-dev have no cmake files.

In this case it should be added manually:

Create directories:

  • /usr/lib/x86_64-linux-gnu/cmake/SDL2_image/
  • /usr/lib/x86_64-linux-gnu/cmake/SDL2_ttf/

Copy there four .cmake files from argentum/third-party/SDL2_* directories

CURL

# Download and extract CURL sources to ~/cpp/curl-8.5.0/
cd ~/cpp
wget -qO curl-src.tgz https://github.com/curl/curl/releases/download/curl-8_5_0/curl-8.5.0.tar.gz
tar -xvzf curl-src.tgz
rm curl-src.tgz

# Build CUR and install its libs-headers to ~/cpp/curl/
mkdir curl-8.5.0/build
cmake -S curl-8.5.0/ -B curl-8.5.0/build -G Ninja -DCMAKE_INSTALL_PREFIX=curl
cmake --build curl-8.5.0/build/

Build Argentum compiler

Get sources

cd ~/cpp
git clone https://github.com/karol11/argentum.git

Build

cd ~/cpp/argentum
cmake -S . -B build -G Ninja -DLLVM_DIR=../llvm17.0.4-rel/lib/cmake/llvm/
cmake --build build

Build and run examples

cd build
./agc --help

Compile helloWorld to asm file out.a

./agc -src  ../demo -start helloWorld -S -o out.a

Build and run helloWorld

# compile
./agc -src  ../demo -start helloWorld -o out.o

# link
gcc -no-pie out.o libag_runtime.a -o hw

# run
./hw

Build and run SDL demo application

# compile and link
./agc -src  ../demo -start demo -o demo.o

gcc -no-pie demo.o libag_runtime.a \
-L/usr/lib/x86_64-linux-gnu \
-lSDL2 -lSDL2_image \
-o demo

# copy image resources
cp ../demo/*.jpg .
cp ../demo/*.png .

# run
./demo

Build and run CURL demo application

./agc -src  ../demo -start httpDemo -o ht.o
gcc -no-pie ht.o libag_runtime.a ../../curl/lib/libcurl.so -o ht
./ht

Build DEB-package

# prepare release build directory
cd ~/cpp/argentum
cmake -S . -B build-rel \
-DCMAKE_BUILD_TYPE=Release \
-G Ninja \
-DLLVM_DIR=../llvm17.0.4-rel/lib/cmake/llvm/

# build deb
cd ~/cpp/argentum/deb
./build-def.bash

It will create aglan_0.0-1_amd64.deb and give instructions on how to install and uninstall it.

Leave a Reply

Your email address will not be published. Required fields are marked *