Build/Debug Argentum compiler on Windows/Visual Studio: tips&tricks

Open compiler project in Visual Studio

  1. Do all steps from Build Argentum from sources on Windows
  2. In Visual Studio main menu choose File->Open->CMake
    select D:\cpp\argentum\CMakeLists.txt or where you installed it.
  3. If your directory is not d:\cpp, open CMakeSettings.json
    open x64-Debug configuration
    and change paths to your directory in the following CMake variables:
    • SDL2_DIR
    • SDL2_image_DIR
    • LLVM_DIR

Run/Debug

Select x64-Debug configuration and ag-test.exe as a startup target. Run/debug code as usual.

To run/debug the Argentum compiler (agc):

  1. Select agc.exe as a startup target
  2. Open Debug->Debug and Launch Settings for agc and locate the property: "name": "agc.exe"
  3. Insert another property after it: , "args": [ "-src", "d:\cpp\argentum\demo", "-start", "helloWorld", "-O3", "-o", "x.obj"]
    (Fix the paths if it differs or add your own desired command line args if needed)
  4. Run/debug as usual

Tip: if paste to "args": [] a raw command line (like -src d:\cpp\argentum\demo -start helloWorld -O3 -o x.obj), it will be automatically tokenized, quoted and escaped (not always correctly though).

Build the release compiler version

In contrast to debug versions, the release agc doesn't use MSVC runtime in DLL. And also they have different iterator safety settings in release and debug. That's why release agc should be linked to the release version of the LLVM. So steps are:

Build release LLVM:

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

cmake -S llvm -B build-rel -G "Visual Studio 17 2022" ^
-Thost=x64 -A x64 ^
-DLLVM_USE_CRT_RELEASE=MT ^
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
-DLLVM_ENABLE_PROJECTS="llvm" ^
-DLLVM_BUILD_RUNTIME=OFF ^
-DLLVM_BUILD_EXAMPLES=OFF ^
-DLLVM_BUILD_TESTS=OFF ^
-DLLVM_BUILD_UTILS=OFF ^
-DLLVM_TARGETS_TO_BUILD=X86 ^
-DCMAKE_INSTALL_PREFIX=D:\cpp\llvm-17.0.4-rel

cmake --build build-rel --target install

Where:

  • LLVM_USE_CRT_RELEASE=MT <-- selects non DLL runtime
  • CMAKE_BUILD_TYPE=RelWithDebInfo <-- adds debug info

Tip: if you want to experiment with LLVM build flags, use a separate step cmake --build build-rel that builds everything but leaves the output directory D:\cpp\llvm-17.0.4-rel intact.

If your directory is not d:\cpp, update SDL2_DIR, SDL2_image_DIR, LLVM_DIR in x64-Release and x64-RelWithDebInfo configurations of CMakeSettings.json
Select x64-Release configuration and build everything Ctrl+Shift+B.

Build results are located in: D:\cpp\argentum\out\build\x64-Release

Leave a Reply

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