kiwix / kiwix-build

Kiwix & openZIM build engine
GNU General Public License v3.0
88 stars 42 forks source link

Building on Windows (and Github CI) #729

Open mgautierfr opened 2 weeks ago

mgautierfr commented 2 weeks ago

This issue is a tracking issue about the native compilation of our projects on Windows, including CI/CD on Github CI

Xapian compilation

This big (and most problematic) point is Xapian compilation. Xapian build system is based on autotools. It works well on Unix or Windows with tools like msys2 but we want to compile without msys2.

So a port of the build system has been made to Meson. This can be found in repository https://github.com/openzim/xapian-meson. This build system mostly work but have few issues:

Upstream issue is https://trac.xapian.org/ticket/832

Libmicrohttpd

We are using meson build system coming from wrapdb. It has a small bug about detection of a type length. A patch is applied (and present) in kiwix-build (https://github.com/kiwix/kiwix-build/pull/726). Patch has also be sent upstream and is under discussion (https://github.com/mesonbuild/wrapdb/pull/1625) Edit 2024-09-01 : Patch has been accepted upstream.

Libzim

Libzim compiles correctly (except COMPACT_FULLER thing) on Windows. Both static and dynamic. However, dynamic building generate a lot of warning as we have stl symbols in our class and we must re-export them. See d2d1f68 (#703)

Libkiwix

~~libkiwix was never tested on Windows. Now we can and we have discover some bugs. They are fixed in https://github.com/kiwix/libkiwix/pull/1113. Until then, test are deactivated on kiwix-build windows CI (https://github.com/kiwix/kiwix-build/pull/725/commits/04d0ba6a9212511cc0599d0f1d73c1b17c4b1255)~~ Tests are fixed on libkiwix.

Libkiwix build only statically as we don't export symbol (see "About dllexport symbols")

zim-tools

zimwriterfs is using libmagic to detect the mimetype of the file to add. libmagic is also using autotool as build system and we have to port it to meson as made for xapian (but should be simpler)

However, it not need as top priority as zimwriterfs is deactivated by zim-tools meson if we are compiling to/on Windows. https://github.com/kiwix/kiwix-build/pull/728 is building zim-tools on github windows CI.

Edit 2024-08-27: This is not only about libmagic. zimcheck also uses getopt to parse command line and I have strange error in metadata-test

Edit 2024-0901: zim-tools (without zimwriterfs) is compiled natively on Window using github CI

kiwix-tools

kiwix-tools uses getopt to parse command line. We currently have not build for it on Windows. We have several solutions:

Edit 2024-09-01: kiwix-tools has been ported to docoptcpp and is compiled natively on Window using github CI

kiwix-desktop

Edit 2024-09-01: Kiwix compiles natively on Windows (github CI). It is published as nightly and release will be signed. Appveyor CI has been removed.

About dllexport symbols.

When compiling dynamically (dll) on Windows, we have to declare what symbols are exported in the dll (other symbols are private). This can be done either by using __declspec(dllexport) attribute in our headers or using a .def file which list exported symbols.

Libzim takes the first way. However, as said, it generates a lot of warning as we are declaring/using stl symbols in our class and we are not reexporting them. (See d2d1f68 (#703) and linked links for more information). The importance of those warning are not totally known. But they are annoying anyway. Note that using a .def file to export the same symbols would probably have the same effect.

Another solution is to export ALL symbols in the dll. The consequence of this is not totally known (at least by me). It seems that autotools and CMAKE have an option to generate a .def which contains all the symbols but meson have not (https://github.com/mesonbuild/meson/issues/2132).

I have ported such a script in python (https://gist.github.com/mgautierfr/11eb53379bf063f965614dcc9b6baef7) and propose it to meson to integrate it https://github.com/mesonbuild/meson/issues/2132

Quick testing shows that we could generate a dll and link to it.

Ping @rgaudin @kelson42 @veloman-yunkan

veloman-yunkan commented 2 weeks ago

Are we under a malware distribution attack?

mgautierfr commented 2 weeks ago

Are we under a malware distribution attack?

It seems so

kelson42 commented 1 week ago

@mgautierfr Thank you for the wrap-up, each of the remaining issue, should be put in a dedicated issue.