diff mbox series

[v2,1/2] meson: build contrib/plugins with meson

Message ID 20240925204845.390689-2-pierrick.bouvier@linaro.org (mailing list archive)
State New, archived
Headers show
Series build contrib/plugins using meson | expand

Commit Message

Pierrick Bouvier Sept. 25, 2024, 8:48 p.m. UTC
Tried to unify this meson.build with tests/tcg/plugins/meson.build but
the resulting modules are not output in the right directory.

Originally proposed by Anton Kochkov, thank you!

Solves: https://gitlab.com/qemu-project/qemu/-/issues/1710
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 meson.build                 |  4 ++++
 contrib/plugins/meson.build | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 contrib/plugins/meson.build

Comments

Alex Bennée Oct. 21, 2024, 9:38 a.m. UTC | #1
Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:

> Tried to unify this meson.build with tests/tcg/plugins/meson.build but
> the resulting modules are not output in the right directory.
>
> Originally proposed by Anton Kochkov, thank you!
>
> Solves: https://gitlab.com/qemu-project/qemu/-/issues/1710
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>  meson.build                 |  4 ++++
>  contrib/plugins/meson.build | 23 +++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
>  create mode 100644 contrib/plugins/meson.build
>
> diff --git a/meson.build b/meson.build
> index ceee6b22c8d..b18c2a54ab5 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -3655,6 +3655,10 @@ subdir('accel')
>  subdir('plugins')
>  subdir('ebpf')
>  
> +if 'CONFIG_TCG' in config_all_accel
> +  subdir('contrib/plugins')
> +endif
> +
>  common_user_inc = []
>  
>  subdir('common-user')
> diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
> new file mode 100644
> index 00000000000..a0e026d25e2
> --- /dev/null
> +++ b/contrib/plugins/meson.build
> @@ -0,0 +1,23 @@
> +t = []
> +if get_option('plugins')
> +  foreach i : ['cache', 'drcov', 'execlog', 'hotblocks', 'hotpages', 'howvec',
> +               'hwprofile', 'ips', 'lockstep', 'stoptrigger']
> +    if host_os == 'windows'
> +      t += shared_module(i, files(i + '.c') + 'win32_linker.c',
> +                        include_directories: '../../include/qemu',
> +                        link_depends: [win32_qemu_plugin_api_lib],
> +                        link_args: ['-Lplugins', '-lqemu_plugin_api'],
> +                        dependencies: glib)
> +
> +    else
> +      t += shared_module(i, files(i + '.c'),
> +                        include_directories: '../../include/qemu',
> +                        dependencies: glib)

I was trying to work out where the include dirs come from to make sure
Brad's fix (see Zu4063fjfHC5hHUl@humpty.home.comstyle.com) also applies.
It does but:

  ➜  make contrib/plugins/libexeclog.so V=1
  /usr/bin/ninja -v   -j1 -d keepdepfile contrib/plugins/libexeclog.so | cat
  [1/2] cc -m64 -Icontrib/plugins/libexeclog.so.p -Icontrib/plugins -I../../contrib/plugins -I../../include/qemu -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote /home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote /home/alex/lsrc/qemu.git/host/include/x86_64 -iquote /home/alex/lsrc/qemu.git/host/include/generic -iquote /home/alex/lsrc/qemu.git/tcg/i386 -pthread -mcx16 -mpopcnt -mneeded -mmovbe -mabm -mbmi -mbmi2 -mfma -mf16c -mavx2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -fPIC -MD -MQ contrib/plugins/libexeclog.so.p/execlog.c.o -MF contrib/plugins/libexeclog.so.p/execlog.c.o.d -o contrib/plugins/libexeclog.so.p/execlog.c.o -c ../../contrib/plugins/execlog.c
  [2/2] cc -m64  -o contrib/plugins/libexeclog.so contrib/plugins/libexeclog.so.p/execlog.c.o -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -fstack-protector-strong -Wl,-z,relro -Wl,-z,now -Wl,--start-group /usr/lib/x86_64-linux-gnu/libglib-2.0.so /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so -Wl,--end-group -pthread

I'm not sure why we see "-Icontrib/plugins -I../../contrib/plugins".
It's probably a harmless redundancy but I'm curious as to where the path
comes from, any idea?

> +    endif
> +  endforeach
> +endif
> +if t.length() > 0
> +  alias_target('contrib-plugins', t)
> +else
> +  run_target('contrib-plugins', command: find_program('true'))
> +endif
Pierrick Bouvier Oct. 21, 2024, 3:45 p.m. UTC | #2
On 10/21/24 02:38, Alex Bennée wrote:
> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
> 
>> Tried to unify this meson.build with tests/tcg/plugins/meson.build but
>> the resulting modules are not output in the right directory.
>>
>> Originally proposed by Anton Kochkov, thank you!
>>
>> Solves: https://gitlab.com/qemu-project/qemu/-/issues/1710
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>   meson.build                 |  4 ++++
>>   contrib/plugins/meson.build | 23 +++++++++++++++++++++++
>>   2 files changed, 27 insertions(+)
>>   create mode 100644 contrib/plugins/meson.build
>>
>> diff --git a/meson.build b/meson.build
>> index ceee6b22c8d..b18c2a54ab5 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -3655,6 +3655,10 @@ subdir('accel')
>>   subdir('plugins')
>>   subdir('ebpf')
>>   
>> +if 'CONFIG_TCG' in config_all_accel
>> +  subdir('contrib/plugins')
>> +endif
>> +
>>   common_user_inc = []
>>   
>>   subdir('common-user')
>> diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
>> new file mode 100644
>> index 00000000000..a0e026d25e2
>> --- /dev/null
>> +++ b/contrib/plugins/meson.build
>> @@ -0,0 +1,23 @@
>> +t = []
>> +if get_option('plugins')
>> +  foreach i : ['cache', 'drcov', 'execlog', 'hotblocks', 'hotpages', 'howvec',
>> +               'hwprofile', 'ips', 'lockstep', 'stoptrigger']
>> +    if host_os == 'windows'
>> +      t += shared_module(i, files(i + '.c') + 'win32_linker.c',
>> +                        include_directories: '../../include/qemu',
>> +                        link_depends: [win32_qemu_plugin_api_lib],
>> +                        link_args: ['-Lplugins', '-lqemu_plugin_api'],
>> +                        dependencies: glib)
>> +
>> +    else
>> +      t += shared_module(i, files(i + '.c'),
>> +                        include_directories: '../../include/qemu',
>> +                        dependencies: glib)
> 
> I was trying to work out where the include dirs come from to make sure
> Brad's fix (see Zu4063fjfHC5hHUl@humpty.home.comstyle.com) also applies.
> It does but:
> 
>    ➜  make contrib/plugins/libexeclog.so V=1
>    /usr/bin/ninja -v   -j1 -d keepdepfile contrib/plugins/libexeclog.so | cat
>    [1/2] cc -m64 -Icontrib/plugins/libexeclog.so.p -Icontrib/plugins -I../../contrib/plugins -I../../include/qemu -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote /home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote /home/alex/lsrc/qemu.git/host/include/x86_64 -iquote /home/alex/lsrc/qemu.git/host/include/generic -iquote /home/alex/lsrc/qemu.git/tcg/i386 -pthread -mcx16 -mpopcnt -mneeded -mmovbe -mabm -mbmi -mbmi2 -mfma -mf16c -mavx2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -fPIC -MD -MQ contrib/plugins/libexeclog.so.p/execlog.c.o -MF contrib/plugins/libexeclog.so.p/execlog.c.o.d -o contrib/plugins/libexeclog.so.p/execlog.c.o -c ../../contrib/plugins/execlog.c
>    [2/2] cc -m64  -o contrib/plugins/libexeclog.so contrib/plugins/libexeclog.so.p/execlog.c.o -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -fstack-protector-strong -Wl,-z,relro -Wl,-z,now -Wl,--start-group /usr/lib/x86_64-linux-gnu/libglib-2.0.so /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so -Wl,--end-group -pthread
> 
> I'm not sure why we see "-Icontrib/plugins -I../../contrib/plugins".
> It's probably a harmless redundancy but I'm curious as to where the path
> comes from, any idea?
> 

It comes from meson itself.
You can see the same kind of include scheme is used for any source file 
in the QEMU tree.
I guess the rationale is to provide include directory either from root 
tree, or from build directory (in case a generated source depends on it?).

It's harmless indeed, because as you noticed, QEMU never had any build 
failure related to this since meson was introduced.

>> +    endif
>> +  endforeach
>> +endif
>> +if t.length() > 0
>> +  alias_target('contrib-plugins', t)
>> +else
>> +  run_target('contrib-plugins', command: find_program('true'))
>> +endif
>
Pierrick Bouvier Oct. 21, 2024, 3:53 p.m. UTC | #3
On 10/21/24 02:38, Alex Bennée wrote:
> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
> 
>> Tried to unify this meson.build with tests/tcg/plugins/meson.build but
>> the resulting modules are not output in the right directory.
>>
>> Originally proposed by Anton Kochkov, thank you!
>>
>> Solves: https://gitlab.com/qemu-project/qemu/-/issues/1710
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>   meson.build                 |  4 ++++
>>   contrib/plugins/meson.build | 23 +++++++++++++++++++++++
>>   2 files changed, 27 insertions(+)
>>   create mode 100644 contrib/plugins/meson.build
>>
>> diff --git a/meson.build b/meson.build
>> index ceee6b22c8d..b18c2a54ab5 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -3655,6 +3655,10 @@ subdir('accel')
>>   subdir('plugins')
>>   subdir('ebpf')
>>   
>> +if 'CONFIG_TCG' in config_all_accel
>> +  subdir('contrib/plugins')
>> +endif
>> +
>>   common_user_inc = []
>>   
>>   subdir('common-user')
>> diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
>> new file mode 100644
>> index 00000000000..a0e026d25e2
>> --- /dev/null
>> +++ b/contrib/plugins/meson.build
>> @@ -0,0 +1,23 @@
>> +t = []
>> +if get_option('plugins')
>> +  foreach i : ['cache', 'drcov', 'execlog', 'hotblocks', 'hotpages', 'howvec',
>> +               'hwprofile', 'ips', 'lockstep', 'stoptrigger']
>> +    if host_os == 'windows'
>> +      t += shared_module(i, files(i + '.c') + 'win32_linker.c',
>> +                        include_directories: '../../include/qemu',
>> +                        link_depends: [win32_qemu_plugin_api_lib],
>> +                        link_args: ['-Lplugins', '-lqemu_plugin_api'],
>> +                        dependencies: glib)
>> +
>> +    else
>> +      t += shared_module(i, files(i + '.c'),
>> +                        include_directories: '../../include/qemu',
>> +                        dependencies: glib)
> 
> I was trying to work out where the include dirs come from to make sure
> Brad's fix (see Zu4063fjfHC5hHUl@humpty.home.comstyle.com) also applies.

In the meson.build, I don't think we need such a fix, as it does the 
right thing out of the box.
Ideally, we should remove the Makefile to avoid having to maintain it 
when we'll introduce other deps/plugins in the future.

Users who want to compile out of tree can still get the compilation 
command from ninja, and adapt it to their needs.

> It does but:
> 
>    ➜  make contrib/plugins/libexeclog.so V=1
>    /usr/bin/ninja -v   -j1 -d keepdepfile contrib/plugins/libexeclog.so | cat
>    [1/2] cc -m64 -Icontrib/plugins/libexeclog.so.p -Icontrib/plugins -I../../contrib/plugins -I../../include/qemu -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote /home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote /home/alex/lsrc/qemu.git/host/include/x86_64 -iquote /home/alex/lsrc/qemu.git/host/include/generic -iquote /home/alex/lsrc/qemu.git/tcg/i386 -pthread -mcx16 -mpopcnt -mneeded -mmovbe -mabm -mbmi -mbmi2 -mfma -mf16c -mavx2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -fPIC -MD -MQ contrib/plugins/libexeclog.so.p/execlog.c.o -MF contrib/plugins/libexeclog.so.p/execlog.c.o.d -o contrib/plugins/libexeclog.so.p/execlog.c.o -c ../../contrib/plugins/execlog.c
>    [2/2] cc -m64  -o contrib/plugins/libexeclog.so contrib/plugins/libexeclog.so.p/execlog.c.o -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -fstack-protector-strong -Wl,-z,relro -Wl,-z,now -Wl,--start-group /usr/lib/x86_64-linux-gnu/libglib-2.0.so /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so -Wl,--end-group -pthread
> 
> I'm not sure why we see "-Icontrib/plugins -I../../contrib/plugins".
> It's probably a harmless redundancy but I'm curious as to where the path
> comes from, any idea?
> 
>> +    endif
>> +  endforeach
>> +endif
>> +if t.length() > 0
>> +  alias_target('contrib-plugins', t)
>> +else
>> +  run_target('contrib-plugins', command: find_program('true'))
>> +endif
>
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index ceee6b22c8d..b18c2a54ab5 100644
--- a/meson.build
+++ b/meson.build
@@ -3655,6 +3655,10 @@  subdir('accel')
 subdir('plugins')
 subdir('ebpf')
 
+if 'CONFIG_TCG' in config_all_accel
+  subdir('contrib/plugins')
+endif
+
 common_user_inc = []
 
 subdir('common-user')
diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
new file mode 100644
index 00000000000..a0e026d25e2
--- /dev/null
+++ b/contrib/plugins/meson.build
@@ -0,0 +1,23 @@ 
+t = []
+if get_option('plugins')
+  foreach i : ['cache', 'drcov', 'execlog', 'hotblocks', 'hotpages', 'howvec',
+               'hwprofile', 'ips', 'lockstep', 'stoptrigger']
+    if host_os == 'windows'
+      t += shared_module(i, files(i + '.c') + 'win32_linker.c',
+                        include_directories: '../../include/qemu',
+                        link_depends: [win32_qemu_plugin_api_lib],
+                        link_args: ['-Lplugins', '-lqemu_plugin_api'],
+                        dependencies: glib)
+
+    else
+      t += shared_module(i, files(i + '.c'),
+                        include_directories: '../../include/qemu',
+                        dependencies: glib)
+    endif
+  endforeach
+endif
+if t.length() > 0
+  alias_target('contrib-plugins', t)
+else
+  run_target('contrib-plugins', command: find_program('true'))
+endif