GNOME Bugzilla – Bug 785210
meson: Support build on Windows (using Visual Studio at least)
Last modified: 2018-05-02 18:45:42 UTC
Hi, We have some Meson build files that are now usable for building GTK+, but at the moment they only support builds on and for *NIX. This patch series, along with the patches to the sources in bug 773299, attempts to make GTK+-3.9x/4.x buildable and running on Windows. I will attach patches shortly to update the Meson build files to include such support. With blessings, thank you!
Created attachment 356086 [details] [review] Meson: Support builds on Windows/MSVC Hi, This is the patch to support builds of GTK+-3.9x/4.x on Windows using Visual Studio at least. Please see the commit comment for what is covered by the patch. Note that for building introspection files (i.e. Gtk-4.0.gir), this will fail on any Windows builds done on Windows because the command line for g-ir-scanner is too long (Windows has a limit of 8192 characters for each command line). To fix this, we will need to make Meson generate a filelist of the files that we want the introspection scanner to scan, and use the --filelist option for g-ir-scanner in order for the introspection build to complete successfully, but this is not covered here as this is something that needs to be fixed/updated in Meson, IMO. With the patches that I will post in 773299, I was able to build the latest git master using Visual Studio 2015, at least. With blessings, thank you!
Created attachment 356697 [details] [review] gdk/gdkconfig.h.meson: Add configuration variable for Windows Hi, I decided to split up the patch to support Meson builds on Windows... First up is the patch to put GDK_WINDOWING_WIN32 in gdk/gdkconfig.h.meson that can be activated once we know we are building for Windows...
Created attachment 356699 [details] [review] gtk/gentypefuncs.py: Open files with UTF-8 encoding on Python 3.x Hi, I am not sure whether this script will be called by Python 2.x, but in case it does... This makes the script open files in utf-8 encoding, as contents in the files opened may not be supported on the Windows system locale (such as in the case of non-English Windows), on Python 3.x. On Python 2.x, since encodings are not supported, open it as we did before...
Created attachment 356702 [details] [review] meson: Support Windows builds (Visual Studio at least) Hi, This adds the items that we need to support native Windows builds, where: -We disable X11/Wayland support (which is on by default) once we know we are building for Windows, and instead activate the Windows-related items. -Don't build *NIX-only items in gtk/, and don't use *NIX dependencies. -Use GLib's msvc_recommended_pragmas.h, to clean up things a bit... Note that further patches are needed to build the IME support (for CJK Windows) and to link in the resource (.rc) file for Windows builds, as well as embedding the libgtk4.manifest file for obtaining a better-looking print dialog on Windows. Note also that a PR has been opened in Meson [1] to use filelists for g-ir-scanner, as that is needed to build introspection files successfully on Windows, otherwise the command line expands beyond 8192 characters, breaking the introspection builds. With blessings, thank you! [1]: https://github.com/mesonbuild/meson/pull/2125
Created attachment 356703 [details] [review] testsuite/gtk/builder.c: Fix test on Visual Studio builds Hi, For the builder test, we need to decorate the symbols that we need to export using __declspec(dllexport) as Visual Studio does not support things like -Wl,export-dynamic, so we only pass in that flag when not building on Visual Studio, and use a macro that is defined as __declspec(dllexport) on Visual Studio builds instead. With blessings, thank you!
Created attachment 357100 [details] [review] meson: Build the .rc files on Windows Hi, This builds the .rc file on Windows, so that: -One can keep track of the version info of the DLL more easily. -Have a default icon for GTK+ apps -Make the Windows print dialog themed[1] [1]: We move the manifest embedding that is required for this back into the .rc file since this is supported in the Visual Studio versions that we care about in GTK+-4, to make maintenance easier on ourside. With blessings, thank you!
Created attachment 357397 [details] [review] meson: Fix build when including immodules into the main GTK+ .dll/.so Hi, The option to include the immodules during the Meson build process is not done completely, (as it is an option that is actually done in the Visual Studio projects) as we need to do the following as well: -Make sure that each immodule source that we are building into the main GTK+ DLL/.so is built with the corresponding INCLUDE_IM_xxx macro defined -Make sure the GTK+ source (gtkimmodule.c specifically) is built with all the -DINCLUDE_IM_xxx macros that we are enabling as a result. Not doing the first will cause the GTK+ DLL/.so to fail to link, and not doing the second will cause GTK+ not to load the immodules that are built in. With blessings, thank you!
Created attachment 357399 [details] [review] meson: Fix the Vulkan library name on Visual Studio builds Hi, For detecting a LunarG Vulkan SDK installation on Visual Studio, we need to look for vulkan-1.lib, not vulkan.lib, so update the library name in the Meson build files accordingly. Note that I am not sure whether the LunarG SDK will work for MinGW/mingw-w64 builds as only the Visual Studio-style .lib files are provided with the SDK. With blessings, thank you!
Created attachment 357400 [details] [review] meson: Fix Vulkan shader compilation Hi, Meson does not like path separators in its output files, which will cause configuration to fail when Vulkan is enabled and when glslc is found and to be used. Fix this by getting the glslc bits into gsk/resources/vulkan, and including it in gsk/meson.build. With blessings, thank you!
Comment on attachment 357400 [details] [review] meson: Fix Vulkan shader compilation Hi, For records, this issue has been fixed upstream in 4904491. With blessings, thank you!
Created attachment 358113 [details] [review] build: Add fallback dependency discovery for Visual Studio build on Meson Hi, As in the other parts of the stack, we still face a problem where pkg-config files are not generated for some of the dependencies that we need in their Visual Studio build files. As a result, we need to add a fallback mechanism on Visual Studio builds to find the dependencies manually using cc.hsa_header() and cc.find_library() when the respective pkg-config files cannot be found. Note that for the GNOME items, libepoxy and Graphene, since we are building via Meson (or in the case of Visual Studio projects, the pkg-config files *are* generated), this does not attempt to cover these dependencies. This will cover the case for HarfBuzz and Cairo. With blessings, thank you!
Created attachment 358115 [details] [review] meson: Fix the Vulkan library name on Visual Studio builds (take ii) Hi, I am re-uploading this patch as the correct Vulkan library name needs to be in the pkg-config files as well. With blessings, thank you!
Hi, For records... (In reply to Fan, Chun-wei from comment #4) > > Note also that a PR has been opened in Meson [1] to use filelists for > g-ir-scanner, ... > > [1]: https://github.com/mesonbuild/meson/pull/2125 The PR for Meson has been merged upstream, so the next release (or latest master checkout) of Meson will enable one to build the introspection files for GTK+ master on Windows. With blessings, and cheers!
Created attachment 359573 [details] [review] meson: Support Windows builds (Visual Studio at least) (take ii) Hi, I am re-uploading this patch as it has to be rebased, and we don't want to use the fallbacks on non-X11/non-Wayland for PangoFT2 (optional) and for gio-unix (not available on Windows; which is replaced with gio-win32 here). With blessings, thank you!
Created attachment 359574 [details] [review] meson: Fix the Vulkan library name on Visual Studio builds (take iii) Hi, I am re-uploading this patch as it has to be rebased. With blessings, thank you!
Created attachment 359576 [details] [review] build: Correct PangoCairo required version Hi, There is a typo in the version required for PangoCairo, so this corrects this to be the same with Pango. With blessings, thank you!
Created attachment 359578 [details] [review] build: Add fallback dependency discovery for Visual Studio build on Meson (take ii) Hi, This patch is re-uploaded as it has to be rebased. With blessings, thank you! The patches need to go in this order (at least the first 3): 356697 356699 359573 357100 357397 359574 359576 <this patch here in this comment> 356703 With blessings, thank you!
Review of attachment 356697 [details] [review]: Sure
Review of attachment 356699 [details] [review]: Looks good
Review of attachment 356703 [details] [review]: Fine for me
Review of attachment 357100 [details] [review]: Sure
Review of attachment 359573 [details] [review]: See the comments inline ::: gtk/meson.build @@ -242,3 @@ 'gtkpopovermenu.c', 'gtkprintcontext.c', - 'gtkprintoperation-portal.c', what about this file? where does it go? ::: meson.build @@ +343,3 @@ +if host_machine.system() == 'windows' + libgio_dep = giowin32_dep I don't like this name much, it feels to me like we are talking about gio while it is the platform specific gio dep. Let's call it platform_gio_dep?
Review of attachment 359574 [details] [review]: Looks good
Review of attachment 359576 [details] [review]: Looks good
Review of attachment 359578 [details] [review]: Looks good
Review of attachment 356697 [details] [review]: Hi Nacho, Thanks, I pushed this patch as e5a1de1. With blessings, thank you!
Review of attachment 356699 [details] [review]: Hi Nacho, Thanks, I pushed the patch as 0332dbc. With blessings, thank you!
Review of attachment 356703 [details] [review]: Hi Nacho, Thanks, I pushed this patch as 60297b9. With blessings, thank you!
Hi Nacho, Thanks, I pushed the following patches as follows: -Attachment 359574 [details]: 0b783f6 -Attachment 359576 [details]: fc5f391 (had to rebase this a bit, since 359573 needs to be updated) -Attachment 359578 [details]: 84ff9e9 (had to rebase this a bit, since 359573 needs to be updated) With blessings, thank you!
Created attachment 359850 [details] [review] meson: Support Windows builds (Visual Studio at least) (take iii) Hi Nacho, Here's the new patch on supporting building GTK+ master via Meson using Visual Studio with the suggestions. I am deferring pushing attachment 357100 [details] [review] until after this gets in. (In reply to Ignacio Casal Quinteiro (nacho) from comment #22) > - 'gtkprintoperation-portal.c', Well, this file is actually duplicated, in a "if os_unix" block starting at circa line 596, so it is just removed here. With blessings, thank you!
Review of attachment 357100 [details] [review]: ::: gtk/gtk-win32.rc.body.in @@ +21,3 @@ VALUE "FileVersion", "@GTK_VERSION@.0" VALUE "InternalName", "libgtk-win32-@GTK_API_VERSION@-@LT_CURRENT_MINUS_AGE@" + VALUE "LegalCopyright", "Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald. Modified by the GTK+ Team and others 1997-2011." Here you can encode the copyright sign as \xa9. I think InternalName and OriginalFilename should be fixed as the name of the binary will be libgtk-4-0.xxxx.0, not libgtk-win32-xx-xx.
Review of attachment 359850 [details] [review]: Looks good to me
Review of attachment 359850 [details] [review]: Hi Nacho, Thanks for reviewing this. Sorry, I forgot to write back here after pushing the patch, which was pushed as 18abb78. With blessings, thank you!
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/859.