Skip to content

Latest commit

 

History

History
77 lines (54 loc) · 3.4 KB

cmake-bootstrap.md

File metadata and controls

77 lines (54 loc) · 3.4 KB

Bootstrapping with CMake

The included CMakeLists.txt at the top level of the project provides cross-platform build rules for auto-bootstrapping the compiler all the way to stage 3.

For reference, the stages:

Stage 0: The bootstrap compiler. This compiler, written in autogenerated C++ is able to parse Jakt source code and output C++ code.

Stage 1: Jakt selfhost compiler. This compiler, written in Jakt, is compiled with the Stage 0 compiler and outputs C++.

Stage 2: Jakt selfhost compiler. This is the same Jakt source code as the Stage 1 compiler, but compiled with the Stage 1 compiler. It outputs C++.

All the stages are compiled with the provided CMAKE_CXX_COMPILER.

Building the bootstrapped compilers

Provide a suitable CMake invocation. Note that a clang version >= 18 is required.

cmake -B build -GNinja -DCMAKE_CXX_COMPILER=clang++-18

Invoke the specified generator

cmake --build build
# OR
ninja -C build

If you want to install the compilers to a location of your choice, provide an install prefix at your favorite location.

cmake -B build -GNinja -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_INSTALL_PREFIX=jakt-install
ninja -C build install

If you want to enable optimizations, be sure to set CMAKE_BUILD_TYPE.

The CMakeLists have an option for what the final stage of the compiler should be, that defaults to stage 1. If you want to build the stage 2 compiler for validation, set the CMake cache variable FINAL_STAGE to 2.

Alternatively, one can build via the provided Dockerfile:

docker build -t jakt:latest -f Dockerfile .
docker run -it jakt:latest
> cd samples/basics
> jakt hello.jakt
> ./build/hello

Supported Platforms

Jakt is known to compile with clang >=18 on Linux, macOS and Windows. g++ also works, provided the version is >=10.2.

MSVC is not supported, however clang-cl.exe and clang.exe do work and clang-cl is used in CI.

On MSYS2, g++ may error out with a "string table overflow" error. In that case, re-configure the build directory with -DCMAKE_BUILD_TYPE=MinSizeRel to get the -Os flag. Do note that using WSL2 or clang directly on windows is a more supported build platform. Maintainers will be reluctant to merge runtime or jakttest patches for MSYS2 quirks to keep the number of supported platfoms under control.

Building with LibLine as the REPL backend

To build jakt with LibLine as the line editor, you need a bootstrap build of Jakt, plus a local build of Lagom (if not available, build lagom using the option described here, or simply invoke Meta/serenity.sh build lagom in a serenity checkout). Once available, the binary can be built by specifying the backend as libline and setting the appropriate linker options:

$ path/to/bootstrap/jakt \
    selfhost/main.jakt \
    --ak-is-my-only-stdlib \
    --config jakt.repl_backend=libline \
    -I path/to/serenity \
    -I path/to/serenity/Userland/Libraries \
    -L path/to/serenity/Build/lagom/Userland/Libraries/LibLine \
    -l lagom-line \
    -Wl-rpath,path/to/serenity/Build/lagom/Userland/Libraries/LibLine

The produced binary can be used to launch a REPL using LibLine as its line editor.