Build Argentum from sources on Windows

Directory structure:

d:\cpp
   llvm-project-llvmorg-17.0.4  - download and extract LLVM sources here
      build-dbg                 - working directory for the build system
   llvm-17.0.4-dbg              - install dir for debug version of llvm
   SDL2-2.28.5                  - install dir for SDL
   SDL2_image-2.6.3             - install dir for SDL_image
   argentum                     - directory for argentum sources
       out                      - working directory for build system (VS-compatible name)

Install prerequisites

Build LLVM from sources

Unzip LLVM sources from https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-17.0.4.zip
to d:\cpp\llvm-project-llvmorg-17.0.4

Make VS project/solution files

This takes several minutes

cd /d D:\cpp\llvm-project-llvmorg-17.0.4

cmake -S llvm -B build-dbg -G "Visual Studio 17 2022" ^
-DLLVM_BUILD_EXAMPLES=OFF ^
-DLLVM_BUILD_TESTS=OFF ^
-DLLVM_ENABLE_PROJECTS="llvm" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DLLVM_TARGETS_TO_BUILD=X86 ^
-DCMAKE_INSTALL_PREFIX=D:\cpp\llvm-17.0.4-dbg

Build the LLVM project

This might take several hours.

cmake --build build-dbg

Install

Check for errors and if everything is ok, install LLVM into d:\cpp\llvm-17.0.4-dbg directory:

cmake --build build-dbg --target install

SDL

  1. Unzip https://github.com/libsdl-org/SDL/releases/download/release-2.28.5/SDL2-devel-2.28.5-VC.zip
    to d:\cpp\SDL2-2.28.5
  2. Unzip https://github.com/libsdl-org/SDL_image/releases/download/release-2.6.3/SDL2_image-devel-2.6.3-VC.zip
    to d:\cpp\SDL2_image-2.6.3

Curl

  1. Download from https://github.com/curl/curl/releases the newest "source_code.zip"
  2. Unzip to d:\curl-src
  3. Build with
cd /d d:\curl-src
cmake -B build -G "Visual Studio 17 2022" -DCURL_USE_SCHANNEL=on -DCMAKE_INSTALL_PREFIX=D:\cpp\curl
cmake --build build --target install

Argentum

Clone repo

cd /d d:\cpp
git clone git@github.com:karol11/argentum.git
cd argentum

Make build files

cmake -S . -B out -G "Visual Studio 17 2022" ^
-DCMAKE_BUILD_TYPE="Debug" ^
-DCMAKE_INSTALL_PREFIX="D:\cpp\argentum-dbg" ^
-DSDL2_DIR="D:/cpp/SDL2-2.28.5/cmake" ^
-DSDL2_image_DIR="D:/cpp/SDL2_image-2.6.3/cmake" ^
-DLLVM_DIR="D:/cpp/llvm-17.0.4-dbg/lib/cmake/llvm"

Build project

cmake --build out

Run the Argentum Compiler

cd /D D:\cpp\argentum\out\Debug
agc --help

Compile to LLVM bit-code:

agc -src d:\cpp\argentum\demo -start helloWorld -o x.ll -emit-llvm -S -g

Where:

  • -src d:\argentum-demo\src -- where ag sources are located
  • -start helloWorld -- module name to compile
  • -o x.ll -- to file x.ll
  • -emit-llvm -- produce llvm bit-code instead of native code
  • -S -- write in text bit-code form
  • -g -- generate debug info

Build and execute Hello World

agc -src d:\cpp\argentum\demo -start helloWorld -O3 -o x.obj
d:\cpp\llvm-17.0.4-dbg\bin\lld-link x.obj ag_runtime.lib
x.exe

Build and execute SDL demo

:: Compile
agc -src d:\cpp\argentum\demo -start demo -o x.obj -O3

:: Link
lld-link x.obj ag_runtime.lib ^
d:\cpp\SDL2-2.28.5\lib\x64\SDL2.lib ^
d:\cpp\SDL2_image-2.6.3\lib\x64\SDL2_image.lib

:: Copy DLLs to cwd
copy d:\cpp\SDL2_image-2.6.3\lib\x64\SDL2_image.dll
copy d:\cpp\SDL2-2.28.5\lib\x64\SDL2.dll

:: Copy graphics
copy d:\cpp\argentum\demo\*.png
copy d:\cpp\argentum\demo\*.jpg

:: run
x

Leave a Reply

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