[PATCH] configure: Support modules for Windows

LIU Zhiwei posted 1 patch 2 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211105032002.83792-1-zhiwei_liu@c-sky.com
configure   |  7 +------
meson.build | 34 ++++++++++++++++++++++++----------
2 files changed, 25 insertions(+), 16 deletions(-)
[PATCH] configure: Support modules for Windows
Posted by LIU Zhiwei 2 years, 6 months ago
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
 configure   |  7 +------
 meson.build | 34 ++++++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/configure b/configure
index 33682cb971..6280e412a9 100755
--- a/configure
+++ b/configure
@@ -1422,7 +1422,7 @@ cat << EOF
   bsd-user        all BSD usermode emulation targets
   guest-agent     build the QEMU Guest Agent
   pie             Position Independent Executables
-  modules         modules support (non-Windows)
+  modules         modules support
   module-upgrades try to load modules from alternate paths for upgrades
   debug-tcg       TCG debugging (default is disabled)
   debug-info      debugging information
@@ -1698,11 +1698,6 @@ else
   QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
 fi
 
-# Our module code doesn't support Windows
-if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
-  error_exit "Modules are not available for Windows"
-fi
-
 # module_upgrades is only reasonable if modules are enabled
 if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
   error_exit "Can't enable module-upgrades as Modules are not enabled"
diff --git a/meson.build b/meson.build
index 47df10afc2..26195cb24f 100644
--- a/meson.build
+++ b/meson.build
@@ -2625,7 +2625,7 @@ block_mods = []
 softmmu_mods = []
 foreach d, list : modules
   foreach m, module_ss : list
-    if enable_modules and targetos != 'windows'
+    if enable_modules
       module_ss = module_ss.apply(config_all, strict: false)
       sl = static_library(d + '-' + m, [genh, module_ss.sources()],
                           dependencies: [modulecommon, module_ss.dependencies()], pic: true)
@@ -2658,7 +2658,7 @@ endforeach
 
 foreach d, list : target_modules
   foreach m, module_ss : list
-    if enable_modules and targetos != 'windows'
+    if enable_modules
       foreach target : target_dirs
         if target.endswith('-softmmu')
           config_target = config_target_mak[target]
@@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
 ###########
 # Targets #
 ###########
-
-foreach m : block_mods + softmmu_mods
-  shared_module(m.name(),
-                name_prefix: '',
-                link_whole: m,
-                install: true,
-                install_dir: qemu_moddir)
-endforeach
+if targetos != 'windows'
+  foreach m : block_mods + softmmu_mods
+    shared_module(m.name(),
+                  name_prefix: '',
+                  link_whole: m,
+                  install: true,
+                  install_dir: qemu_moddir)
+  endforeach
+endif
 
 softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
 common_ss.add(qom, qemuutil)
@@ -2826,6 +2827,7 @@ common_all = static_library('common',
 feature_to_c = find_program('scripts/feature_to_c.sh')
 
 emulators = {}
+emulator = 0
 foreach target : target_dirs
   config_target = config_target_mak[target]
   target_name = config_target['TARGET_NAME']
@@ -2966,6 +2968,7 @@ foreach target : target_dirs
                link_language: link_language,
                link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
                link_args: link_args,
+               implib: true,
                win_subsystem: exe['win_subsystem'])
 
     if targetos == 'darwin'
@@ -3023,6 +3026,17 @@ foreach target : target_dirs
     endif
   endforeach
 endforeach
+if (targetos == 'windows')
+  foreach m : block_mods + softmmu_mods
+    shared_module(m.name(),
+	    name_prefix: '',
+	    link_whole: m,
+	    install: true,
+	    dependencies: glib,
+	    link_with: emulator,
+	    install_dir: qemu_moddir)
+  endforeach
+endif
 
 # Other build targets
 
-- 
2.25.1


Re: [PATCH] configure: Support modules for Windows
Posted by Daniel P. Berrangé 2 years, 6 months ago
On Fri, Nov 05, 2021 at 11:20:02AM +0800, LIU Zhiwei wrote:

Generally we expect a commit message describing what is being solved
and any reasons for the approach taken.

> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
> ---
>  configure   |  7 +------
>  meson.build | 34 ++++++++++++++++++++++++----------
>  2 files changed, 25 insertions(+), 16 deletions(-)
> 
> diff --git a/configure b/configure
> index 33682cb971..6280e412a9 100755
> --- a/configure
> +++ b/configure
> @@ -1422,7 +1422,7 @@ cat << EOF
>    bsd-user        all BSD usermode emulation targets
>    guest-agent     build the QEMU Guest Agent
>    pie             Position Independent Executables
> -  modules         modules support (non-Windows)
> +  modules         modules support
>    module-upgrades try to load modules from alternate paths for upgrades
>    debug-tcg       TCG debugging (default is disabled)
>    debug-info      debugging information
> @@ -1698,11 +1698,6 @@ else
>    QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
>  fi
>  
> -# Our module code doesn't support Windows
> -if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
> -  error_exit "Modules are not available for Windows"
> -fi
> -
>  # module_upgrades is only reasonable if modules are enabled
>  if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
>    error_exit "Can't enable module-upgrades as Modules are not enabled"
> diff --git a/meson.build b/meson.build
> index 47df10afc2..26195cb24f 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2625,7 +2625,7 @@ block_mods = []
>  softmmu_mods = []
>  foreach d, list : modules
>    foreach m, module_ss : list
> -    if enable_modules and targetos != 'windows'
> +    if enable_modules
>        module_ss = module_ss.apply(config_all, strict: false)
>        sl = static_library(d + '-' + m, [genh, module_ss.sources()],
>                            dependencies: [modulecommon, module_ss.dependencies()], pic: true)
> @@ -2658,7 +2658,7 @@ endforeach
>  
>  foreach d, list : target_modules
>    foreach m, module_ss : list
> -    if enable_modules and targetos != 'windows'
> +    if enable_modules
>        foreach target : target_dirs
>          if target.endswith('-softmmu')
>            config_target = config_target_mak[target]
> @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
>  ###########
>  # Targets #
>  ###########
> -
> -foreach m : block_mods + softmmu_mods
> -  shared_module(m.name(),
> -                name_prefix: '',
> -                link_whole: m,
> -                install: true,
> -                install_dir: qemu_moddir)
> -endforeach
> +if targetos != 'windows'
> +  foreach m : block_mods + softmmu_mods
> +    shared_module(m.name(),
> +                  name_prefix: '',
> +                  link_whole: m,
> +                  install: true,
> +                  install_dir: qemu_moddir)
> +  endforeach
> +endif
>  
>  softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
>  common_ss.add(qom, qemuutil)
> @@ -2826,6 +2827,7 @@ common_all = static_library('common',
>  feature_to_c = find_program('scripts/feature_to_c.sh')
>  
>  emulators = {}
> +emulator = 0
>  foreach target : target_dirs
>    config_target = config_target_mak[target]
>    target_name = config_target['TARGET_NAME']
> @@ -2966,6 +2968,7 @@ foreach target : target_dirs
>                 link_language: link_language,
>                 link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
>                 link_args: link_args,
> +               implib: true,
>                 win_subsystem: exe['win_subsystem'])
>  
>      if targetos == 'darwin'
> @@ -3023,6 +3026,17 @@ foreach target : target_dirs
>      endif
>    endforeach
>  endforeach
> +if (targetos == 'windows')
> +  foreach m : block_mods + softmmu_mods
> +    shared_module(m.name(),
> +	    name_prefix: '',
> +	    link_whole: m,
> +	    install: true,
> +	    dependencies: glib,
> +	    link_with: emulator,

AFAIK from the docs meson wants "link_with" to be a list of
libraries. This is passing a literal '0' which doesn't
make sense. Is this really needed ?

What is the reason for the "dependencies" addition ?

Can we not just use the existing shared_module() rules
we already have. It might be ok to just add dependencies
to the existing rule even for non-windows.

> +	    install_dir: qemu_moddir)
> +  endforeach
> +endif



Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH] configure: Support modules for Windows
Posted by LIU Zhiwei 2 years, 6 months ago
On 2021/11/5 下午5:30, Daniel P. Berrangé wrote:
> On Fri, Nov 05, 2021 at 11:20:02AM +0800, LIU Zhiwei wrote:
>
> Generally we expect a commit message describing what is being solved
> and any reasons for the approach taken.

This patch relaxes all constraints on modules for Windows.  It firstly 
exports  all symbols of the
target executable to an import library. Then  all modules link with the 
import library .

>> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
>> ---
>>   configure   |  7 +------
>>   meson.build | 34 ++++++++++++++++++++++++----------
>>   2 files changed, 25 insertions(+), 16 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 33682cb971..6280e412a9 100755
>> --- a/configure
>> +++ b/configure
>> @@ -1422,7 +1422,7 @@ cat << EOF
>>     bsd-user        all BSD usermode emulation targets
>>     guest-agent     build the QEMU Guest Agent
>>     pie             Position Independent Executables
>> -  modules         modules support (non-Windows)
>> +  modules         modules support
>>     module-upgrades try to load modules from alternate paths for upgrades
>>     debug-tcg       TCG debugging (default is disabled)
>>     debug-info      debugging information
>> @@ -1698,11 +1698,6 @@ else
>>     QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
>>   fi
>>   
>> -# Our module code doesn't support Windows
>> -if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
>> -  error_exit "Modules are not available for Windows"
>> -fi
>> -
>>   # module_upgrades is only reasonable if modules are enabled
>>   if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
>>     error_exit "Can't enable module-upgrades as Modules are not enabled"
>> diff --git a/meson.build b/meson.build
>> index 47df10afc2..26195cb24f 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -2625,7 +2625,7 @@ block_mods = []
>>   softmmu_mods = []
>>   foreach d, list : modules
>>     foreach m, module_ss : list
>> -    if enable_modules and targetos != 'windows'
>> +    if enable_modules
>>         module_ss = module_ss.apply(config_all, strict: false)
>>         sl = static_library(d + '-' + m, [genh, module_ss.sources()],
>>                             dependencies: [modulecommon, module_ss.dependencies()], pic: true)
>> @@ -2658,7 +2658,7 @@ endforeach
>>   
>>   foreach d, list : target_modules
>>     foreach m, module_ss : list
>> -    if enable_modules and targetos != 'windows'
>> +    if enable_modules
>>         foreach target : target_dirs
>>           if target.endswith('-softmmu')
>>             config_target = config_target_mak[target]
>> @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
>>   ###########
>>   # Targets #
>>   ###########
>> -
>> -foreach m : block_mods + softmmu_mods
>> -  shared_module(m.name(),
>> -                name_prefix: '',
>> -                link_whole: m,
>> -                install: true,
>> -                install_dir: qemu_moddir)
>> -endforeach
>> +if targetos != 'windows'
>> +  foreach m : block_mods + softmmu_mods
>> +    shared_module(m.name(),
>> +                  name_prefix: '',
>> +                  link_whole: m,
>> +                  install: true,
>> +                  install_dir: qemu_moddir)
>> +  endforeach
>> +endif
>>   
>>   softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
>>   common_ss.add(qom, qemuutil)
>> @@ -2826,6 +2827,7 @@ common_all = static_library('common',
>>   feature_to_c = find_program('scripts/feature_to_c.sh')
>>   
>>   emulators = {}
>> +emulator = 0
>>   foreach target : target_dirs
>>     config_target = config_target_mak[target]
>>     target_name = config_target['TARGET_NAME']
>> @@ -2966,6 +2968,7 @@ foreach target : target_dirs
>>                  link_language: link_language,
>>                  link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
>>                  link_args: link_args,
>> +               implib: true,
>>                  win_subsystem: exe['win_subsystem'])
>>   
>>       if targetos == 'darwin'
>> @@ -3023,6 +3026,17 @@ foreach target : target_dirs
>>       endif
>>     endforeach
>>   endforeach
>> +if (targetos == 'windows')
>> +  foreach m : block_mods + softmmu_mods
>> +    shared_module(m.name(),
>> +	    name_prefix: '',
>> +	    link_whole: m,
>> +	    install: true,
>> +	    dependencies: glib,
>> +	    link_with: emulator,
> AFAIK from the docs meson wants "link_with" to be a list of
> libraries.

The emulator is an import library.

There has been an executable variable named emulator in origin meson.build.
An implib keyword args has been  added in this patch when the executable 
generates.
And I declare it to the out-most level  to make it visible for modules 
after the build of targets.

> This is passing a literal '0' which doesn't
> make sense. Is this really needed ?

It will not be a literal '0'

> What is the reason for the "dependencies" addition ?

I don't think the import library will include the symbols of glib.  And 
many modules need
link with glib. So I add the dependencies.

> Can we not just use the existing shared_module() rules
> we already have. It might be ok to just add dependencies
> to the existing rule even for non-windows.

I think you are right. It is difficult for me to add all dependencies to 
modules.
I use a rough method that export all symbols in the executable.

I am not clear about the right way to support this feature. Look forward 
to you more advice.

Thanks,
Zhiwei

>> +	    install_dir: qemu_moddir)
>> +  endforeach
>> +endif
>
>
> Regards,
> Daniel

Re: [PATCH] configure: Support modules for Windows
Posted by Daniel P. Berrangé 2 years, 6 months ago
On Fri, Nov 05, 2021 at 08:14:29PM +0800, LIU Zhiwei wrote:
> 
> On 2021/11/5 下午5:30, Daniel P. Berrangé wrote:
> > On Fri, Nov 05, 2021 at 11:20:02AM +0800, LIU Zhiwei wrote:
> > 
> > Generally we expect a commit message describing what is being solved
> > and any reasons for the approach taken.
> 
> This patch relaxes all constraints on modules for Windows.  It firstly
> exports  all symbols of the
> target executable to an import library. Then  all modules link with the
> import library .
> 
> > > Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
> > > ---
> > >   configure   |  7 +------
> > >   meson.build | 34 ++++++++++++++++++++++++----------
> > >   2 files changed, 25 insertions(+), 16 deletions(-)
> > > 
> > > diff --git a/configure b/configure
> > > index 33682cb971..6280e412a9 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -1422,7 +1422,7 @@ cat << EOF
> > >     bsd-user        all BSD usermode emulation targets
> > >     guest-agent     build the QEMU Guest Agent
> > >     pie             Position Independent Executables
> > > -  modules         modules support (non-Windows)
> > > +  modules         modules support
> > >     module-upgrades try to load modules from alternate paths for upgrades
> > >     debug-tcg       TCG debugging (default is disabled)
> > >     debug-info      debugging information
> > > @@ -1698,11 +1698,6 @@ else
> > >     QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
> > >   fi
> > > -# Our module code doesn't support Windows
> > > -if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
> > > -  error_exit "Modules are not available for Windows"
> > > -fi
> > > -
> > >   # module_upgrades is only reasonable if modules are enabled
> > >   if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
> > >     error_exit "Can't enable module-upgrades as Modules are not enabled"
> > > diff --git a/meson.build b/meson.build
> > > index 47df10afc2..26195cb24f 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -2625,7 +2625,7 @@ block_mods = []
> > >   softmmu_mods = []
> > >   foreach d, list : modules
> > >     foreach m, module_ss : list
> > > -    if enable_modules and targetos != 'windows'
> > > +    if enable_modules
> > >         module_ss = module_ss.apply(config_all, strict: false)
> > >         sl = static_library(d + '-' + m, [genh, module_ss.sources()],
> > >                             dependencies: [modulecommon, module_ss.dependencies()], pic: true)
> > > @@ -2658,7 +2658,7 @@ endforeach
> > >   foreach d, list : target_modules
> > >     foreach m, module_ss : list
> > > -    if enable_modules and targetos != 'windows'
> > > +    if enable_modules
> > >         foreach target : target_dirs
> > >           if target.endswith('-softmmu')
> > >             config_target = config_target_mak[target]
> > > @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
> > >   ###########
> > >   # Targets #
> > >   ###########
> > > -
> > > -foreach m : block_mods + softmmu_mods
> > > -  shared_module(m.name(),
> > > -                name_prefix: '',
> > > -                link_whole: m,
> > > -                install: true,
> > > -                install_dir: qemu_moddir)
> > > -endforeach
> > > +if targetos != 'windows'
> > > +  foreach m : block_mods + softmmu_mods
> > > +    shared_module(m.name(),
> > > +                  name_prefix: '',
> > > +                  link_whole: m,
> > > +                  install: true,
> > > +                  install_dir: qemu_moddir)
> > > +  endforeach
> > > +endif
> > >   softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
> > >   common_ss.add(qom, qemuutil)
> > > @@ -2826,6 +2827,7 @@ common_all = static_library('common',
> > >   feature_to_c = find_program('scripts/feature_to_c.sh')
> > >   emulators = {}
> > > +emulator = 0
> > >   foreach target : target_dirs
> > >     config_target = config_target_mak[target]
> > >     target_name = config_target['TARGET_NAME']
> > > @@ -2966,6 +2968,7 @@ foreach target : target_dirs
> > >                  link_language: link_language,
> > >                  link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
> > >                  link_args: link_args,
> > > +               implib: true,
> > >                  win_subsystem: exe['win_subsystem'])
> > >       if targetos == 'darwin'
> > > @@ -3023,6 +3026,17 @@ foreach target : target_dirs
> > >       endif
> > >     endforeach
> > >   endforeach
> > > +if (targetos == 'windows')
> > > +  foreach m : block_mods + softmmu_mods
> > > +    shared_module(m.name(),
> > > +	    name_prefix: '',
> > > +	    link_whole: m,
> > > +	    install: true,
> > > +	    dependencies: glib,
> > > +	    link_with: emulator,
> > AFAIK from the docs meson wants "link_with" to be a list of
> > libraries.
> 
> The emulator is an import library.
> 
> There has been an executable variable named emulator in origin meson.build.
> An implib keyword args has been  added in this patch when the executable
> generates.
> And I declare it to the out-most level  to make it visible for modules after
> the build of targets.

Oh, so the "emulator" variable is already present in the loop body
from existing meson rules.

This still feels odd though - QEMU has 30+ emulator binaries it
can build. This code is linking modules to the implib of whichever
happens to be the last emulator binary built.

Does this really let the modules work against any of the emulator
binaries  at runtime ?


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH] configure: Support modules for Windows
Posted by LIU Zhiwei 2 years, 6 months ago
On 2021/11/5 下午8:22, Daniel P. Berrangé wrote:
> On Fri, Nov 05, 2021 at 08:14:29PM +0800, LIU Zhiwei wrote:
>> On 2021/11/5 下午5:30, Daniel P. Berrangé wrote:
>>> On Fri, Nov 05, 2021 at 11:20:02AM +0800, LIU Zhiwei wrote:
>>>
>>> Generally we expect a commit message describing what is being solved
>>> and any reasons for the approach taken.
>> This patch relaxes all constraints on modules for Windows.  It firstly
>> exports  all symbols of the
>> target executable to an import library. Then  all modules link with the
>> import library .
>>
>>>> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
>>>> ---
>>>>    configure   |  7 +------
>>>>    meson.build | 34 ++++++++++++++++++++++++----------
>>>>    2 files changed, 25 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/configure b/configure
>>>> index 33682cb971..6280e412a9 100755
>>>> --- a/configure
>>>> +++ b/configure
>>>> @@ -1422,7 +1422,7 @@ cat << EOF
>>>>      bsd-user        all BSD usermode emulation targets
>>>>      guest-agent     build the QEMU Guest Agent
>>>>      pie             Position Independent Executables
>>>> -  modules         modules support (non-Windows)
>>>> +  modules         modules support
>>>>      module-upgrades try to load modules from alternate paths for upgrades
>>>>      debug-tcg       TCG debugging (default is disabled)
>>>>      debug-info      debugging information
>>>> @@ -1698,11 +1698,6 @@ else
>>>>      QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
>>>>    fi
>>>> -# Our module code doesn't support Windows
>>>> -if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
>>>> -  error_exit "Modules are not available for Windows"
>>>> -fi
>>>> -
>>>>    # module_upgrades is only reasonable if modules are enabled
>>>>    if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
>>>>      error_exit "Can't enable module-upgrades as Modules are not enabled"
>>>> diff --git a/meson.build b/meson.build
>>>> index 47df10afc2..26195cb24f 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -2625,7 +2625,7 @@ block_mods = []
>>>>    softmmu_mods = []
>>>>    foreach d, list : modules
>>>>      foreach m, module_ss : list
>>>> -    if enable_modules and targetos != 'windows'
>>>> +    if enable_modules
>>>>          module_ss = module_ss.apply(config_all, strict: false)
>>>>          sl = static_library(d + '-' + m, [genh, module_ss.sources()],
>>>>                              dependencies: [modulecommon, module_ss.dependencies()], pic: true)
>>>> @@ -2658,7 +2658,7 @@ endforeach
>>>>    foreach d, list : target_modules
>>>>      foreach m, module_ss : list
>>>> -    if enable_modules and targetos != 'windows'
>>>> +    if enable_modules
>>>>          foreach target : target_dirs
>>>>            if target.endswith('-softmmu')
>>>>              config_target = config_target_mak[target]
>>>> @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
>>>>    ###########
>>>>    # Targets #
>>>>    ###########
>>>> -
>>>> -foreach m : block_mods + softmmu_mods
>>>> -  shared_module(m.name(),
>>>> -                name_prefix: '',
>>>> -                link_whole: m,
>>>> -                install: true,
>>>> -                install_dir: qemu_moddir)
>>>> -endforeach
>>>> +if targetos != 'windows'
>>>> +  foreach m : block_mods + softmmu_mods
>>>> +    shared_module(m.name(),
>>>> +                  name_prefix: '',
>>>> +                  link_whole: m,
>>>> +                  install: true,
>>>> +                  install_dir: qemu_moddir)
>>>> +  endforeach
>>>> +endif
>>>>    softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
>>>>    common_ss.add(qom, qemuutil)
>>>> @@ -2826,6 +2827,7 @@ common_all = static_library('common',
>>>>    feature_to_c = find_program('scripts/feature_to_c.sh')
>>>>    emulators = {}
>>>> +emulator = 0
>>>>    foreach target : target_dirs
>>>>      config_target = config_target_mak[target]
>>>>      target_name = config_target['TARGET_NAME']
>>>> @@ -2966,6 +2968,7 @@ foreach target : target_dirs
>>>>                   link_language: link_language,
>>>>                   link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
>>>>                   link_args: link_args,
>>>> +               implib: true,
>>>>                   win_subsystem: exe['win_subsystem'])
>>>>        if targetos == 'darwin'
>>>> @@ -3023,6 +3026,17 @@ foreach target : target_dirs
>>>>        endif
>>>>      endforeach
>>>>    endforeach
>>>> +if (targetos == 'windows')
>>>> +  foreach m : block_mods + softmmu_mods
>>>> +    shared_module(m.name(),
>>>> +	    name_prefix: '',
>>>> +	    link_whole: m,
>>>> +	    install: true,
>>>> +	    dependencies: glib,
>>>> +	    link_with: emulator,
>>> AFAIK from the docs meson wants "link_with" to be a list of
>>> libraries.
>> The emulator is an import library.
>>
>> There has been an executable variable named emulator in origin meson.build.
>> An implib keyword args has been  added in this patch when the executable
>> generates.
>> And I declare it to the out-most level  to make it visible for modules after
>> the build of targets.
> Oh, so the "emulator" variable is already present in the loop body
> from existing meson rules.
>
> This still feels odd though - QEMU has 30+ emulator binaries it
> can build. This code is linking modules to the implib of whichever
> happens to be the last emulator binary built.
>
> Does this really let the modules work against any of the emulator
> binaries  at runtime ?

Think about the Linux build. There don't exist different modules for 
different emulator binaries.
I guess it doesn't have much connection with the target.

Once again, may be it is not a right way. Hope to get for your guidance 
and help.

Thanks,
Zhiwei

>
>
> Regards,
> Daniel

Re: [PATCH] configure: Support modules for Windows
Posted by Michael Tokarev 2 years, 6 months ago
05.11.2021 06:20, LIU Zhiwei wrote:
...
> diff --git a/meson.build b/meson.build
> index 47df10afc2..26195cb24f 100644
...
> @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
>   ###########
>   # Targets #
>   ###########
> -
> -foreach m : block_mods + softmmu_mods
> -  shared_module(m.name(),
> -                name_prefix: '',
> -                link_whole: m,
> -                install: true,
> -                install_dir: qemu_moddir)
> -endforeach
> +if targetos != 'windows'
> +  foreach m : block_mods + softmmu_mods
> +    shared_module(m.name(),
> +                  name_prefix: '',
> +                  link_whole: m,
> +                  install: true,
> +                  install_dir: qemu_moddir)
> +  endforeach
> +endif
>   
>   softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
>   common_ss.add(qom, qemuutil)
> @@ -2826,6 +2827,7 @@ common_all = static_library('common',
>   feature_to_c = find_program('scripts/feature_to_c.sh')
>   
>   emulators = {}
> +emulator = 0

mm...
...
> @@ -3023,6 +3026,17 @@ foreach target : target_dirs
>       endif
>     endforeach
>   endforeach
> +if (targetos == 'windows')
> +  foreach m : block_mods + softmmu_mods
> +    shared_module(m.name(),
> +	    name_prefix: '',
> +	    link_whole: m,
> +	    install: true,
> +	    dependencies: glib,
> +	    link_with: emulator,
> +	    install_dir: qemu_moddir)
> +  endforeach
> +endif

Now we have two almost-identical blocks in different places.
Can we either move them closer to each other or combine them into one?

Thanks!

/mjt

Re: [PATCH] configure: Support modules for Windows
Posted by LIU Zhiwei 2 years, 6 months ago
On 2021/11/5 下午6:36, Michael Tokarev wrote:
> 05.11.2021 06:20, LIU Zhiwei wrote:
> ...
>> diff --git a/meson.build b/meson.build
>> index 47df10afc2..26195cb24f 100644
> ...
>> @@ -2800,14 +2800,15 @@ common_ss.add(hwcore)
>>   ###########
>>   # Targets #
>>   ###########
>> -
>> -foreach m : block_mods + softmmu_mods
>> -  shared_module(m.name(),
>> -                name_prefix: '',
>> -                link_whole: m,
>> -                install: true,
>> -                install_dir: qemu_moddir)
>> -endforeach
>> +if targetos != 'windows'
>> +  foreach m : block_mods + softmmu_mods
>> +    shared_module(m.name(),
>> +                  name_prefix: '',
>> +                  link_whole: m,
>> +                  install: true,
>> +                  install_dir: qemu_moddir)
>> +  endforeach
>> +endif
>>     softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp)
>>   common_ss.add(qom, qemuutil)
>> @@ -2826,6 +2827,7 @@ common_all = static_library('common',
>>   feature_to_c = find_program('scripts/feature_to_c.sh')
>>     emulators = {}
>> +emulator = 0
>
> mm...
> ...
It is an executable object that is not  visible in this patch.
>> @@ -3023,6 +3026,17 @@ foreach target : target_dirs
>>       endif
>>     endforeach
>>   endforeach
>> +if (targetos == 'windows')
>> +  foreach m : block_mods + softmmu_mods
>> +    shared_module(m.name(),
>> +        name_prefix: '',
>> +        link_whole: m,
>> +        install: true,
>> +        dependencies: glib,
>> +        link_with: emulator,
>> +        install_dir: qemu_moddir)
>> +  endforeach
>> +endif
>
> Now we have two almost-identical blocks in different places.
> Can we either move them closer to each other or combine them into one?

The difference is the next one need to link with an import library which 
is generated by an executable.
If we want to make them closer, I don't know if it influences the build 
on Linux.

I am not familiar with meson and the right way to implement this 
feature. Look forward to your more advice.

Thanks,
Zhiwei

>
> Thanks!
>
> /mjt