The current code is broken (maybe worked with a past version). Here is the new code:
project('valaprog', ['c', 'vala'])
glib = dependency('glib-2.0')
gobject = dependency('gobject-2.0')
executable('valaprog', 'prog.vala',
dependencies: [glib, gobject])
Referencing this page: https://github.com/mesonbuild/meson/wiki/Vala
Fixed, thanks!
@nirbheek looks like it is not fixed. Maybe you forgot to push =)
I pushed it to the wrong repository. Fixed now. ;)
I didn't add ['c'] to the list of project languages. I don't think that should be needed for a vala-only project. If it is, that's a bug and should be fixed. I can't test that, so please tell me if that's broken too.
Yes I needed to add 'c' to the project languages otherwise it threw the following error.
(I think that is because first meson pre-compiles to C and then compiles the C files)
$ ninja-build
[1/1] Regenerating build files
The Meson build system
Version: 0.31.0
Source dir: /home/megh/projects/gnome/mesonbuild/vala-sample
Build dir: /home/megh/projects/gnome/mesonbuild/vala-sample/build
Build type: native build
Build machine cpu family: x86_64
Build machine cpu: x86_64
Project name: valaprog
Native vala compiler: valac (unknown 0.32.1)
Build targets in project: 1
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/mesonbuild/mesonmain.py", line 254, in run
app.generate()
File "/usr/lib/python3.5/site-packages/mesonbuild/mesonmain.py", line 158, in generate
g.generate(intr)
File "/usr/lib/python3.5/site-packages/mesonbuild/backend/ninjabackend.py", line 178, in generate
[self.generate_target(t, outfile) for t in self.build.get_targets().values()]
File "/usr/lib/python3.5/site-packages/mesonbuild/backend/ninjabackend.py", line 178, in <listcomp>
[self.generate_target(t, outfile) for t in self.build.get_targets().values()]
File "/usr/lib/python3.5/site-packages/mesonbuild/backend/ninjabackend.py", line 313, in generate_target
obj_list.append(self.generate_single_compile(target, outfile, src, True, [], header_deps))
File "/usr/lib/python3.5/site-packages/mesonbuild/backend/ninjabackend.py", line 1436, in generate_single_compile
compiler = self.get_compiler_for_source(src)
File "/usr/lib/python3.5/site-packages/mesonbuild/backend/backends.py", line 80, in get_compiler_for_source
raise RuntimeError('No specified compiler can handle file ' + src)
RuntimeError: No specified compiler can handle file valaprog@exe/prog.c
FAILED: '/usr/bin/python3' '/usr/bin/meson' --internal regenerate '/home/megh/projects/gnome/mesonbuild/vala-sample' '/home/megh/projects/gnome/mesonbuild/vala-sample/build' --backend ninja
ninja: error: rebuilding 'build.ninja': subcommand failed
I can see why this would happen, but Meson should automatically add 'c' to the list of languages. I'm re-purposing this bug for this issue.
IMHO temporarily you should add 'c' to the wiki page. But it may not matter much as the error is quite expressive
Also currently if you run meson build (the initial command) it gives a super-clear error:
The Meson build system
Version: 0.31.0
Source dir: /home/megh/projects/gnome/mesonbuild/vala-sample
Build dir: /home/megh/projects/gnome/mesonbuild/vala-sample/build
Build type: native build
Build machine cpu family: x86_64
Build machine cpu: x86_64
Project name: valaprog
Native vala compiler: valac (unknown 0.32.1)
Meson encountered an error in file meson.build, line 1, column 0:
Compiling Vala requires C. Add C to your project languages and rerun Meson.
I'll leave the decision to @jpakkane, but I don't see why an error should be thrown for this. If C is always needed for compiling Vala, why not always add it when 'vala' is in languages? :)
@nirbheek I guess that since Meson is very explicit by nature, it's a better thing to state that. Especially since a Vala build is typically mixed with C-specific directives.
Eventually, it could be possible to support standalone Vala build (exclusively with valac) and resolve dependencies from VAPIs.
This is not just a question of Vala + C but of adding languages automatically in general. Meson aims to be explicit and non-surprising. Adding a language to a project is a big thing with implications, we should not do that behing the user's backs.