Getting Vala on macOS

Should you develop applications on macOS using Vala? Probably not. Cross-platform applications I can run on my desktop and laptop sound cool though.

Mac Homebrew & Vala

For this guide, I’m using Homebrew. Other options include MacPorts or jhbuild.

To install Homebrew, use:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Code language: JavaScript (javascript)

To install Vala and GTK4, run:

brew install vala gtk4 libadwaita adwaita-icon-theme vala-language-server meson ninja

GTK4 is for developing GUI applications. libadwaita provides modern UI experiences. adwaita-icon-theme gives us a default iconset to use. meson and ninja will act as the build system. vala-language-server is not required, but when we setup code, it’ll provide intellisense.

Setting Up Code

You can use your favorite text editor, but I like using Visual Studio Code. To have the best Vala developer experience, I recommend installing the Vala extension.

Creating Our Project

It’s possible to compile a project using valac, but we’re going to setup a project structure we can build on.

src/Application.vala meson.build README.md

Later on, we can add vapi, tests, data, and more…

For now, we just want to validate Vala’s installation.

src/Application.vala

public class Kamusta { public static int main (string[] argv) { var app = new Gtk.Application ("in.twirp.vala.kamusta", ApplicationFlags.FLAGS_NONE); app.activate.connect (() => { // Create a new Window var window = new Gtk.ApplicationWindow (app); // Create a new button var button = new Gtk.Button.with_label ("Kamusta Vala!"); // Close Window on button click button.clicked.connect (() => { window.close (); }); window.set_title ("Hello Vala!"); window.set_child (button); window.present (); }); return app.run (argv); } }
Code language: JavaScript (javascript)

meson.build

# Project Declaration project( 'in.twirp.vala.kamusta', # Project ID ['vala', 'c'], # Compilers version: '0.0.1' # Version ) lib_dependencies = [ dependency('gtk4'), dependency('libadwaita-1') ] executable( 'kamusta-vala', # Binary Name # Source Files 'src/Application.vala', dependencies: lib_dependencies, install: false )
Code language: PHP (php)

README.md

# Kamusta Vala Sample `Hello World` project.
Code language: PHP (php)

Building & Running

From the root of our project, we can run:

meson build cd build ninja

To run our project

./kamusta-vala

and…

kamusta-vala running

So cool!

Code can be found on GitHub.

Next time, we’ll start going over integrating with macOS.