compiler.links command for vala crashes
meson crashes with:
AttributeError: 'NoneType' object has no attribute 'get_option_args' meson.build:20:20: ERROR: Unhandled python exception
My meson.build file: **# Project & version number project('vala-test', ['c', 'vala'], license: 'GPL3+', meson_version: '>= 0.62.0', version: '0.1' )
gee_dep = dependency('gee-0.8') gio_dep = dependency('gio-2.0', version: '>= 2.78.0') glib_dep = dependency('glib-2.0', version: '>= 2.78.0')
valac = meson.get_compiler('vala') posix_dep = valac.find_library('posix')
code0 = '''private const string [] strings = {"a","b"}; private static string test_string (string [] s) {return s[0];} void main() {stdout.printf ("%s\n",test_string (strings));}'''
this next line crashes
code0_links = valac.links(code0, args : '--define=VALA_STRICT_C', name : 'if an array of strings needs casting?') if not code0_links message ('VALA_NEEDS_ARRAY_STRING_CASTING') endif**
I run this in the directory with meson.build to cause the crash: meson setup ../builddir
Expected behavior I see the message VALA_NEEDS_ARRAY_STRING_CASTING.
system parameters
- native build (for the same computer)?
- debian testing operating system
- Python 3.11.6
- meson --version: 1.2.1
- ninja --version: 1.11.1
- vala --version: Vala 0.56.13
- gcc --version: gcc (GCC) 14.0.1 20240131
The bug still happens in meson release 1.4.0
Reproduced.
Fixed formatting and reduced a little bit:
project(
'vala-test',
['c', 'vala'],
license: 'GPL3+',
meson_version: '>= 0.62.0',
version: '0.1',
)
valac = meson.get_compiler('vala')
code0 = '''private const string [] strings = {"a","b"};
private static string test_string (string [] s) {return s[0];}
void main() {stdout.printf ("%s\n",test_string (strings));}'''
code0_links = valac.links(
code0,
args: '--define=VALA_STRICT_C',
name: 'if an array of strings needs casting?',
)
if not code0_links
message('VALA_NEEDS_ARRAY_STRING_CASTING')
endif
Full backtrace:
$ meson setup builddir
The Meson build system
Version: 1.4.0.rc2
Source dir: /tmp/vala
Build dir: /tmp/vala/builddir
Build type: native build
Project name: vala-test
Project version: 0.1
C compiler for the host machine: ccache cc (gcc 14.0.1 "cc (Gentoo Hardened 14.0.9999 p, commit 66ed76361b07f18610a134dca21c6945f03c6a6b) 14.0.1 20240311 (experimental) 31ce2e993d09dcad1ce139a2848a28de5931056d")
C linker for the host machine: cc ld.bfd 2.42.50.20240310
Vala compiler for the host machine: valac (valac 0.56.15)
Host machine cpu family: x86_64
Host machine cpu: x86_64
Traceback (most recent call last):
File "/usr/lib/python3.12/site-packages/mesonbuild/mesonmain.py", line 186, in run
return options.run_func(options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/msetup.py", line 363, in run
app.generate()
File "/usr/lib/python3.12/site-packages/mesonbuild/msetup.py", line 187, in generate
return self._generate(env, capture, vslite_ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/msetup.py", line 226, in _generate
intr.run()
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreter/interpreter.py", line 3007, in run
super().run()
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 162, in run
self.evaluate_codeblock(self.ast, start=1)
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 188, in evaluate_codeblock
raise e
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 180, in evaluate_codeblock
self.evaluate_statement(cur)
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 198, in evaluate_statement
self.assignment(cur)
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 634, in assignment
value = self.evaluate_statement(node.value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
return self.method_call(cur)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 549, in method_call
res = obj.method_call(method_name, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/baseobjects.py", line 81, in method_call
return method(args, kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/decorators.py", line 250, in wrapper
return f(*nargs, **wrapped_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreterbase/decorators.py", line 569, in wrapper
return f(*wrapped_args, **wrapped_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreter/compiler.py", line 559, in links_method
result, cached = self.compiler.links(code, self.environment,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/compilers/compilers.py", line 1280, in links
return self.compiles(code, env, extra_args=extra_args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/compilers/compilers.py", line 1266, in compiles
with self._build_wrapper(code, env, extra_args, dependencies, mode, disable_cache=disable_cache) as p:
File "/usr/lib/python3.12/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/compilers/compilers.py", line 1247, in _build_wrapper
args = self.build_wrapper_args(env, extra_args, dependencies, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/compilers/compilers.py", line 1211, in build_wrapper_args
extra_args = extra_args(mode)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/interpreter/compiler.py", line 274, in _determine_args
args.extend(self.compiler.get_option_link_args(opts))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/mesonbuild/compilers/compilers.py", line 587, in get_option_link_args
return self.linker.get_option_args(options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_option_args'
meson.build:15:20: ERROR: Unhandled python exception
This is a Meson bug and should be reported!
Does vala.compiles() similarly crash?
It’s an interesting question with languages like vala that are transpilers what these even mean, does compiles mean vala->c? Vala->obj?
vala.compiles() doesn’t crash. I don’t know the answer to your latter question.
Good to know, I'll have to go look at the implementation of vala.compiles and see what it's doing.
It’s an interesting question with languages like vala that are transpilers what these even mean, does compiles mean vala->c? Vala->obj?
In meson it is possible to transparently use vala or cython sources to generate libraries or executables, even mixing in other sources that get directly compiled to object code. This somehow implies that the transpiler step is implicit, from a user point of view. Therefore, I think that the less surprising thing for vala's compiles() is to check whether it is possible to turn the given code into object code, and similarly for links().
dcbaker, with respect to your question vala→c or vala→obj.
When I pass args : ['--Xcc=-DVALA_STRICT_C'] to valac.compiles
I get:
warning: -X has no effect when -C or --ccode is set
Passing -C or --ccode to valac ensures it only compiles the vala code to C code. I’m not sure why you would want to do this. Unless there is a way to pass the C code to gcc.
It seems that the meson code for vala has been nobbled to stop it linking even when mode==CompileCheckMode.LINK So I have come up with a solution, could someone please review my patch? meson.patch.txt