meson.build(5)
β¨ NAME β¨
okay bestie, gather round, because we're reading the meson.build(5) page from the File Formats Manual π β this is the whole tea on meson.build, aka a build system dsl π
π¦ DESCRIPTION π¦
so the meson dsl is a dynamically typed language, lowkey like other interpreted languages such as python and ruby ππ
- every single object is immutable β no cap, you literally cannot mutate anything π
- you cannot define functions β only the built-in functions are available, periodt π ββοΈ
here's the little map of what's coming up, iykyk:
- STRUCTURE β overview of source and project layout ποΈ
- TYPES β information on all primitive types π
- SYNTAX β description of syntax and keywords βοΈ
π STRUCTURE π
every meson project must have a file called meson.build at the project root π«Ά that's the root build file, bestie. and it must have a call to the project() function as its first statement β first, like, no skipping the line π
you can also have extra meson.build files chilling in any subdirectories of the project πΈ those build files get executed with the subdir() function. iconic behaviour honestly.
π TYPES π
the meson build system dsl has most of the common types you'd expect, no surprises here:
- booleans (written as
trueandfalse) β - integers π’
- strings π§΅
- arrays π
- dictionaries π
π Booleans π
booleans are either true or false. that's it, that's the whole vibe π¦
OPERATORS
andβ logical andorβ logical ornotβ logical and
π₯ Integers π₯
you can specify an integer literal using decimal, hexadecimal, octal, and binary β so many flavours, so many options π
int_1 = 1
int_42 = 42
int_255 = 0xFF
int_493 = 0o755
int_1365 = 0b10101010101
all the common arithmetic operations are implemented for integers: addition, subtraction, division, multiplication, and modulo. the whole squad is here π
OPERATORS
*β multiplication/β integer division%β modulo (remainder)+β addition-β subtraction==β equal to!=β not equal to<β less than>β greater than<=β less than or equal to>=β greater than or equal to
πΈ Strings πΈ
strings in Meson are declared with single quotes β¨ and the backslash (\) is the escape character.
the full list of escape sequences is, and yes you're getting all of them:
\\β Backslash\'β Single quote\aβ Bell\bβ Backspace\fβ Formfeed\nβ Newline\rβ Carriage Return\tβ Horizontal Tab\vβ Vertical Tab\oooβ Character with octal value ooo, up to 3 digits long\xhhβ Character with hex value hh\uxxxxβ Character with 16-bit hex value xxxx\Uxxxxxxxxβ Character with 32-bit hex value xxxxxxxx\N{name}β Character named name in Unicode database
Multi-line strings are surrounded by 3 consecutive quotes π
these are raw strings, which means they do not support any of the escape sequences listed above. not one. so don't come crying to me about your \n π
Format strings are expressed by placing a leading f before the first opening quote π§ inside of a format string, sequences of the form @[a-z_]+@ will be substituted with the value of the matching variable. that variable can be of type bool, int, or str.
name = 'Alice'
# prints "Hello Alice"
message(f'Hello @name@')
OPERATORS
+β concatenate two strings/β concatenate two strings as ifjoin_paths()was called[int]β access the character at index<str> in <str>β check if str is a substring<str> not in <str>β check if str is not a substring==β equal to!=β not equal to
π Arrays π
arrays are delimited by brackets. an array can contain an arbitrary number of objects of any type β go feral, bestie π
OPERATORS
+β if the rhs operand is an array, it will be joined to the lhs array. if it is a scalar, it will be appended to the lhs array.[int]β access the object at index<any> in <array>β check if object is inarray<any> not in <array>β check if object is not inarray==β equal to!=β not equal to
π Dictionaries π
dictionaries are delimited by curly braces. a dictionary can contain an arbitrary number of key: value pairs π«Ά keys are required to be strings, but values can be objects of any type. dictionaries are immutable and do not have a guaranteed order β so don't you dare rely on ordering, that's giving chaos πͺοΈ
OPERATORS
+β merge two dictionaries. in case of a conflicting key, the value from the rhs dictionary will be taken.[str]β access the object with keykey<str> in <dict>β check if key is indict<str> not in <dict>β check if key is not indict==β equal to!=β not equal to
π SYNTAX π
a meson build file is composed of statements, which are terminated by newlines βοΈ other than the statement-terminating newline, white space has no syntactic meaning. so go ahead and format it however, it's not that deep π
π Comments π
a comment starts with the # character and extends until the end of the line. classic π¬
π¦ Variables π¦
a variable can contain a value of any type, and does not need to be predeclared π«Ά
var1 = 'hello'
var2 = 102
one important difference in how variables work in the dsl is that all objects are immutable π when you see an operation which appears like a mutation, actually a new object is created and assigned to the name. it's giving "new me, who dis" π
var1 = [1, 2, 3]
var2 = var1
var2 += [4]
# var2 is now [1, 2, 3, 4]
# var1 is still [1, 2, 3]
π Function and method calls π
builtin functions are called by their name followed by parenthesis containing optional, comma-separated arguments πΈ arguments are either positional or keyword. keyword arguments are expressed using the keyword without quotes, followed by a colon.
foo()
foo('bar')
foo('bar', baz: true)
method calls are expressed by a . followed by the same function call syntax as above β¨
foo.bar()
foo.bar('baz', qux: false)
for a complete list of functions and methods, please see meson-reference(3) π
π₯ If statements π₯
start an if statement with the if keyword followed by a boolean expression. further conditions can be expressed using the elif keyword followed by a boolean expression. the else keyword can be used to handle the case when no conditions are matched. an if statement is terminated with the endif keyword β
if conditon1
...
elif condition2
...
else condition3
...
endif
π§ Foreach statements π§
to loop over values in an iterable, use the foreach keyword followed by a comma separated list of names to assign the values of the iterable to, a colon, and an iterable expression π only arrays and dictionaries are iterable. a foreach statement is terminated with the endforeach keyword.
arrays have one value to assign to.
foreach value : array
foo(value)
endforeach
dictionaries have one two values to assign to.
foreach key, value : dictionary
foo(key)
bar(value)
endforeach
inside a foreach block you may use the break and continue keywords π
break exits the loop immediately. continue skips the rest of the current iteration.
no cap, those two are your besties when you need out early or need to skip ahead π
π SEE ALSO π
and that's the whole page, bestie π«Ά this was meson.build(5) from the File Formats Manual, dated 2026-02-23 β go forth and build something iconic πβ¨π
π¦ where this page comes from
- ubuntu resolute: muon-meson 0.5.0-1.1 Β· GPL-3.0-only
- ubuntu stonking: muon-meson 0.5.0-1.1 Β· GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms