Skip to content

Instantly share code, notes, and snippets.

@vheidari
Last active July 17, 2023 00:35
Show Gist options
  • Save vheidari/e6b937b1528b927cdf49daec9ac41752 to your computer and use it in GitHub Desktop.
Save vheidari/e6b937b1528b927cdf49daec9ac41752 to your computer and use it in GitHub Desktop.
Lets compile Jakt programing language compiler on the Linux

Lets compile Jakt programing language compiler on the Linux

Okey, today we work with Jakt.What is Jakt ? this is your answerd -> Jakt is a memory-safe systems programming language.it develop and maintain by Serenity OS team and today we would like to compile it and use it.

Who are the project maintainers?

The project maintainers at this time (Wed 10 May 2023 01:30:45 PM) are :

- @awesomekling, 
- @jntrnr, 
- @linusg,
- @alimpfard, 
- @gunnarbeutner, 
- @bgianfo, 
- @IdanHo,
- @trflynn89, 
- @AtkinsSJ
- @ADKaster.

If you're curious to learn about maintainers, you can read more here.

Requirement

To compile Jakt you need to install these tools

  1. < clang-14
  2. < cmake-14
  3. Latest git version

For this example I use cmake 3.26.3 and clang-15 15.0.7.

Install CMake

To install CMake on Linux, you can download the appropriate version for your needs from the link below :

https://cmake.org/download/

I downloaded cmake-3.26.3-linux-x86_64.sh file a use it to install CMake on my machine. for installing CMake you can use this command like me :

sh cmake-3.26.3-linux-x86_64.sh --prefix=/usr/local --skip-license

This shell script can either install CMake or export it to the address /usr/local.

There are two options that we can use :

  1. --prefix= -> This indicates the export path.
  2. --skip-license -> This option indicates to skip over the license.

Install clang-15

Instead of installing clang-15 manually, I will use apt. For this reason, we can use the following command:

bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

This link can be useful if you want to learn more about installing clang : https://apt.llvm.org/

The above command will download a shell script, run it, and add the necessary clang repository to apt on your system. When all tasks are completed, you can use apt to download clang-15.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install clang-15

Okay, now that we have completed the previous steps, we are ready to compile Jakt on our system. Let's move on to the next section!

Clone Jakt and compile it

To clone the Jakt project from GitHub, we can use the following commands:

mkdir jakt_compiler
cd jakt_compiler
git clone https://github.com/SerenityOS/jakt.git
cd jakt

After completing all of the above tasks, we can use cmake to generate the appropriate compiler build script. To do this, we can use the following command:

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

Note: that cmake creates a build script for clang++-15 by using CMakeLists.txt.

The above command will take approximately a minute to run. Once all tasks are completed, we can use the following command to compile Jakt with ninja:

ninja -C build

When you run the above command, ninja will compile the Jakt source code using the build script that CMake has created.

After the ninja building system has completed its work, a build directory should be created inside the Jakt directory. You can find all of the Jakt files inside this folder. To test the jakt compiler, I recommend following these commands:

cd ./build/bin
./jakt --help

If everything is all right, you should be able to see the help options and commands. If you can see them, then I can say well done! :) We have compiled the Jakt programming language compiler together.

Jakt Hello World app

To test the jakt compiler, create a folder inside the samples directory called mycode, and place your "Hello, World" application inside it. To do this, please follow these instructions:

cd samples
mkdir mycode
cd mycode
touch s-01.jakt
vim s-01.jakt

When you open s-01.jakt with vim, you can enter the following simple "Hello, World" code inside it:

fn main() {
    println("{}", "Hello World")
}

After entering the 'Hello, World' code inside s-01.jakt with vim, save it using the following command within the vim editor:

:wq

Since we know our compiler is located inside the bin folder, we can use the following command to compile the s-01.jakt app:

../../build/bin/jakt -C /usr/bin/clang++-15 ./s-01.jakt

The above command will translate our Jakt code to C++ code. It will then create a build folder inside our mycode directory and compile the translated C++ code using clang++-15, putting the resulting executable inside the build folder.

You may wonder about the -C /usr/bin/clang++-15 option. This option specifies the location of the clang++-15 C++ compiler that Jakt uses to compile exported C++ code.

To see a list of all available options and switches for compilation, run the ./jakt -h command.

To run your compiled app, use the following command in your terminal:

./build/s-01

The result should look something like this:

Hello World

:) Congratulations! We did everything correctly. Now we can use the Jakt compiler. I hope you enjoy it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment