summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-06-16 08:44:10 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-10-08 10:42:41 -0700
commita5094a134aa8b2a971153ed8446f27d986f476e7 (patch)
tree821380b5b6f801d66181abad34ef17f499999f8f
parent8d69552dbd61144cdeab4ac93137db672c62fd52 (diff)
downloadmeson-a5094a134aa8b2a971153ed8446f27d986f476e7.tar.gz
vala: add a method to get a generated vala header
This allows targets that don't link with a vala target to rely on the header generation.
-rw-r--r--docs/markdown/Vala.md13
-rw-r--r--docs/markdown/snippets/vala-target-extra-methods.md12
-rw-r--r--docs/yaml/objects/build_tgt.yaml8
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py13
4 files changed, 46 insertions, 0 deletions
diff --git a/docs/markdown/Vala.md b/docs/markdown/Vala.md
index fdc4fbae4..23ff57018 100644
--- a/docs/markdown/Vala.md
+++ b/docs/markdown/Vala.md
@@ -304,6 +304,19 @@ 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.
### GObject Introspection and language bindings
diff --git a/docs/markdown/snippets/vala-target-extra-methods.md b/docs/markdown/snippets/vala-target-extra-methods.md
new file mode 100644
index 000000000..1c7867e4f
--- /dev/null
+++ b/docs/markdown/snippets/vala-target-extra-methods.md
@@ -0,0 +1,12 @@
+## Vala BuildTarget dependency enhancements
+
+A BuildTarget that has Vala sources can now get a File dependency for its
+generated header.
+
+```meson
+lib = library('foo', 'foo.vala')
+lib_h = lib.vala_header()
+lib_s = static_lib('static', 'static.c', lib_h)
+```
+
+`static.c` will not start compilation until `lib.h` is generated.
diff --git a/docs/yaml/objects/build_tgt.yaml b/docs/yaml/objects/build_tgt.yaml
index 73b9b5da7..7229de590 100644
--- a/docs/yaml/objects/build_tgt.yaml
+++ b/docs/yaml/objects/build_tgt.yaml
@@ -77,3 +77,11 @@ 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.
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index 17ba989d3..db6782ceb 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -988,6 +988,19 @@ class BuildTargetHolder(ObjectHolder[_BuildTarget]):
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)
+
+
class ExecutableHolder(BuildTargetHolder[build.Executable]):
pass