Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/markdown/Vala.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,40 @@ In this example, the second and third elements of the `install_dir`
array indicate the destination with `true` to use default directories
(i.e. `include` and `share/vala/vapi`).

### Depending on C header

*(since 1.10.0)*

Given the previous example,

```meson
foo_lib = shared_library(...)
foo_h = foo_lib.vala_header()
```

This header can now be used like any other generated header to create an
order-only dependency.


### Depending on VAPI header

*(since 1.10.0)*

Given the previous example,

```meson
foo_lib = shared_library(...)
foo_vapi = foo_lib.vala_vapi()
```

### Depending on generated GIR

*(since 1.10.0)*

```meson
foo_lib = shared_library(..., vala_gir : 'foo.gir')
foo_gir = foo_lib.vala_gir()
```

### GObject Introspection and language bindings

Expand Down Expand Up @@ -339,6 +373,21 @@ directory (i.e. `share/gir-1.0` for GIRs). The fourth element in the
To then generate a typelib file use a custom target with the
`g-ir-compiler` program and a dependency on the library:

*Since Meson 1.10*, use the `.vala_gir()` method to get a handle to the generated `.gir` file:

```meson
g_ir_compiler = find_program('g-ir-compiler')
custom_target('foo typelib', command: [g_ir_compiler, '--output', '@OUTPUT@', '@INPUT@'],
input: foo_lib.vala_gir(),
output: 'Foo-1.0.typelib',
install: true,
install_dir: get_option('libdir') / 'girepository-1.0')
```


*Before Meson 1.10*, calculating the path to the input is required, as is adding a
manual dependency to the vala target:

```meson
g_ir_compiler = find_program('g-ir-compiler')
custom_target('foo typelib', command: [g_ir_compiler, '--output', '@OUTPUT@', '@INPUT@'],
Expand Down
21 changes: 21 additions & 0 deletions docs/markdown/snippets/vala-target-extra-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Vala BuildTarget dependency enhancements

A BuildTarget that has Vala sources can now get a File dependency for its
generated header, vapi, and gir files.

```meson
lib = library('foo', 'foo.vala')
lib_h = lib.vala_header()
lib_s = static_lib('static', 'static.c', lib_h)

lib_vapi = lib.vala_vapi()

custom_target(
'foo-typelib',
command : ['g-ir-compiler', '--output', '@OUTPUT@', '@INPUT@'],
input : lib.vala_gir(),
output : 'Foo-1.0.typelib'
)
```

`static.c` will not start compilation until `lib.h` is generated.
24 changes: 24 additions & 0 deletions docs/yaml/objects/build_tgt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,27 @@ methods:
objects feature compatible with [[@external_program]] objects. This
simplifies use-cases where an executable is used instead of
an [[@external_program]].

- name: vala_header
returns: file
since: 1.10.0
description: |
Returns a [[@file]] object pointing to a C compatible header generated by
the vala compiler, if this target does not generate a vala header then it is
an error to call this method.

- name: vala_vapi
returns: file
since: 1.10.0
description: |
Returns a [[@file]] object pointing to a VAPI header generated by the vala
compiler, if this target does not generate a VAPI file then it is an error
to call this method.

- name: vala_gir
returns: file
since: 1.10.0
description: |
Returns a [[@file]] object pointing to a GIR file generated by the vala
compiler, if this target does not generate a GIR file then it is an error
to call this method.
37 changes: 37 additions & 0 deletions mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,43 @@ def get_id_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
def name_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
return self._target_object.name

@FeatureNew('vala_header', '1.10.0')
@noPosargs
@noKwargs
@InterpreterObject.method('vala_header')
def vala_header_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> mesonlib.File:
if not hasattr(self._target_object, 'vala_header'):
raise mesonlib.MesonException("Attempted to get a Vala header from a target that doesn't generate one")

assert self.interpreter.backend is not None, 'for mypy'
return mesonlib.File.from_built_file(
self.interpreter.backend.get_target_dir(self._target_object), self._target_object.vala_header)

@FeatureNew('vala_vapi', '1.10.0')
@noPosargs
@noKwargs
@InterpreterObject.method('vala_vapi')
def vala_vapi_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> mesonlib.File:
if not hasattr(self._target_object, 'vala_vapi'):
raise mesonlib.MesonException("Attempted to get a Vala VAPI from a target that doesn't generate one")

assert self.interpreter.backend is not None, 'for mypy'
return mesonlib.File.from_built_file(
self.interpreter.backend.get_target_dir(self._target_object), self._target_object.vala_vapi)

@FeatureNew('vala_gir', '1.10.0')
@noPosargs
@noKwargs
@InterpreterObject.method('vala_gir')
def vala_gir_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> mesonlib.File:
if not hasattr(self._target_object, 'vala_gir'):
raise mesonlib.MesonException("Attempted to get a Vala GIR from a target that doesn't generate one")

assert self.interpreter.backend is not None, 'for mypy'
return mesonlib.File.from_built_file(
self.interpreter.backend.get_target_dir(self._target_object), self._target_object.vala_gir)


class ExecutableHolder(BuildTargetHolder[build.Executable]):
pass

Expand Down
7 changes: 5 additions & 2 deletions test cases/vala/9 gir/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2025 Intel Corporation

project('foo', 'c', 'vala')

glib = dependency('glib-2.0')
Expand All @@ -12,6 +15,6 @@ foo = shared_library('foo', 'foo.vala',

custom_target('foo-typelib',
command: [g_ir_compiler, '--output', '@OUTPUT@', '@INPUT@'],
input: meson.current_build_dir() + '/Foo-1.0.gir',
input: foo.vala_gir(),
output: 'Foo-1.0.typelib',
depends: foo)
build_by_default : true)
Loading