Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a custom VAPI does not generate a -pkg foo flag #2103

Open
wblaszcz opened this issue Jul 22, 2017 · 6 comments
Open

Using a custom VAPI does not generate a -pkg foo flag #2103

wblaszcz opened this issue Jul 22, 2017 · 6 comments

Comments

@wblaszcz
Copy link

The current 'Using a custom VAPI' (with pkg-config file) example on the wiki does not work for me.
I need to explicitly add a --pkg=foo to the executable line. I can only assume that this is a bug?
e.g.
change


add_project_arguments(['--vapidir', join_paths(meson.current_source_dir(), 'vapi')], 
                      language: 'vala')
                      
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
foo_dep = dependency('foo') # 'foo.vapi' will be resolved in './vapi/foo.vapi'

executable('app', 'app.vala', dependencies: [glib_dep, gobject_dep, foo_dep])

to


add_project_arguments(['--vapidir', join_paths(meson.current_source_dir(), 'vapi')], 
                      language: 'vala')
                      
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
foo_dep = dependency('foo') # 'foo.vapi' will be resolved in './vapi/foo.vapi'

executable('app', 'app.vala', dependencies: [glib_dep, gobject_dep, foo_dep], vala_args: ['--pkg=foo'])

BTW, on the 'Using a custom VAPI' (with no pkg-config file) example, the foo_vapi line is missing a closing parentheses.

@arteymix
Copy link
Contributor

The example assumes that there's a pkg-config file named foo.pc. I've tested it with libuv and it works as expected.

Could you provide a failing sample?

@wblaszcz
Copy link
Author

wblaszcz commented Jul 24, 2017

The follow is my meson.build file:

project('model3d', 'vala', 'c')

add_project_arguments(['--vapidir', join_paths(meson.current_source_dir(), 'vapi')],
        language: 'vala')

m_dep = meson.get_compiler('c').find_library('m', required : false)
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
gl_dep = dependency('gl')
sdl2_dep = dependency('sdl2')

executable('model3d', ['src/model3d.vala', 'src/vector.vala'],
        dependencies : [m_dep, glib_dep, gobject_dep, gl_dep, sdl2_dep])

The vapi directory contains the gl.vapi and sdl2.vapi files.
The following files are located on my system.
/usr/lib/pkgconfig/gl.pc
/usr/lib/pkgconfig/sdl2.pc

The following is the output of meson build:

The Meson build system
Version: 0.41.1
Source dir: /home/wblaszcz/MyVala/model3d
Build dir: /home/wblaszcz/MyVala/model3d/build
Build type: native build
Project name: model3d
Native c compiler: cc (gcc 6.3.0)
Native vala compiler: valac (valac 0.36.1)
Build machine cpu family: x86_64
Build machine cpu: x86_64
Library m found: YES
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Native dependency glib-2.0 found: YES 2.52.1
Native dependency gobject-2.0 found: YES 2.52.1
Native dependency gl found: YES 17.0.3
Native dependency sdl2 found: YES 2.0.5
Build targets in project: 1

The following is the output of ninja:

[1/4] Compiling Vala source ../src/model3d.vala ../src/vector.vala.
FAILED: model3d@exe/model3d.c model3d@exe/vector.c 
valac -C --debug --vapidir /home/wblaszcz/MyVala/model3d/vapi --pkg gobject-2.0 --pkg glib-2.0 -d model3d@exe ../src/model3d.vala ../src/vector.vala
../src/model3d.vala:1.7-1.8: error: The namespace name `GL' could not be found
using GL;
      ^^
../src/model3d.vala:2.7-2.9: error: The namespace name `SDL' could not be found
using SDL;
      ^^^
../src/model3d.vala:5.22-5.26: error: The symbol `Video' could not be found
    protected static Video.Window window;
...

As you can see, the valac line does not contain the --pkg=gl --pkg=sdl2 flags.
If I add vala_args : ['--pkg=gl', '--pkg=sdl2'] to the executable line, ninja builds successfully.
I think it is due to the fact that both these libraries are in uppercase? (-lGL and -lSDL2)
I've just tried adding libcurl as a dependency, I that worked fine, e.g.:

[1/4] Compiling Vala source ../src/model3d.vala ../src/vector.vala.
FAILED: model3d@exe/model3d.c model3d@exe/vector.c 
valac -C --debug --vapidir /home/wblaszcz/MyVala/model3d/vapi --pkg libcurl --pkg gobject-2.0 --pkg glib-2.0 -d model3d@exe ../src/model3d.vala ../src/vector.vala
../src/model3d.vala:1.7-1.8: error: The namespace name `GL' could not be found
using GL;
      ^^

@arteymix
Copy link
Contributor

It's definately a bug, both sdl2 and gl are treated with a specific dependency objects and --pkg are only emitted for PkgConfigDependecy objects.

hrxi added a commit to hrxi/dino that referenced this issue Aug 17, 2023
hrxi added a commit to hrxi/dino that referenced this issue Oct 10, 2023
@hrxi
Copy link

hrxi commented Oct 11, 2023

I'm also affected by this bug, hitting this while trying to port Dino to Windows.

Workaround for vapi files shipped with Vala:

dep_gtk4 = [dep_gtk4, meson.get_compiler('vala').find_library('gtk4')]

General workaround:

executable(sources, vala_args: ['--pkg', 'icu-uc'], dependencies: dependencies)

hrxi added a commit to hrxi/dino that referenced this issue Oct 27, 2023
@v1993
Copy link
Contributor

v1993 commented Dec 6, 2023

This is probably caused by

if compiler.language == 'vala':
if dep.type_name == 'pkgconfig':
assert isinstance(dep, dependencies.ExternalDependency)
if dep.name == 'glib-2.0' and dep.version_reqs is not None:
for req in dep.version_reqs:
if req.startswith(('>=', '==')):
commands += ['--target-glib', req[2:]]
break
commands += ['--pkg', dep.name]
elif isinstance(dep, dependencies.ExternalLibrary):
commands += dep.get_link_args('vala')

Line 1058 probably should be replaced with if isinstance(dep, dependencies.ExternalDependency): and elif block removed completely.

Edit: an extra check in form of and (dep.language is None or dep.language == 'vala') may also be needed; I have not checked.

@hrxi
Copy link

hrxi commented Dec 6, 2023

I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants