From 55b058d10e89e2188b3313efe7bfaca88637efab Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 21 Aug 2024 16:40:45 +0200 Subject: [PATCH 1/3] Fix static linking on Windows On Windows, static libraries are using "foo.lib" naming. On Unix, they are in the form of "libfoo.a" On Windows, "foo.lib" can also the definition of symbols in a foo.dll. So you can link to "foo.lib", whatever you are doing static or dynamic linking and you are good. However, meson is always creating static library as "libfoo.a" 'to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.' [1] On top of that, qmake is replacing all `-lfoo` in LIBS by `foo.lib` (on Windows). So at the end, we try to link with `foo.lib` but we have `libfoo.a` Solution could be : - Rename `libfoo.a` to `foo.lib`, but it would mean modify deps libraries on the FS - Don't use LIBS and directly set QMAKE_LFLAGS but we would have to handle different command line option format between g++/clang and msvc - Update meson build system of each projet to explicitly set the library naming. - Replace `-lfoo` with absolute path to static library. This is what meson is doing internally and what we are doing here Any `-lfoo` is replace with absolute path to static library (`libfoo.a`) if we found one. Else, it is keep unchanged. [1] https://mesonbuild.com/Reference-manual_functions.html#library_name_suffix --- kiwix-desktop.pro | 9 ++++-- scripts/pkg-config-wrapper.py | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 scripts/pkg-config-wrapper.py diff --git a/kiwix-desktop.pro b/kiwix-desktop.pro index f96d805..e326e2c 100644 --- a/kiwix-desktop.pro +++ b/kiwix-desktop.pro @@ -193,14 +193,19 @@ unix { INSTALLS += mime_file } -PKGCONFIG_CFLAGS = $$system(pkg-config --cflags $$PKGCONFIG_OPTION \"kiwix >= 13.0.0 kiwix < 14.0.0 libzim >= 9.0.0 libzim < 10.0.0\") +DEPS_DEFINITION = \"kiwix >= 13.0.0 kiwix < 14.0.0 libzim >= 9.0.0 libzim < 10.0.0\" + +PKGCONFIG_CFLAGS = $$system(pkg-config --cflags $$PKGCONFIG_OPTION $$DEPS_DEFINITION) QMAKE_CXXFLAGS += $$PKGCONFIG_CFLAGS QMAKE_CFLAGS += $$PKGCONFIG_CFLAGS -LIBS += $$system(pkg-config --libs $$PKGCONFIG_OPTION \"kiwix >= 13.0.0 kiwix < 14.0.0 libzim >= 9.0.0 libzim < 10.0.0\") +!win32 { + LIBS += $$system(pkg-config --libs $$PKGCONFIG_OPTION $$DEPS_DEFINITION) +} win32 { + LIBS += $$system(python scripts/pkg-config-wrapper.py --libs $$PKGCONFIG_OPTION $$DEPS_DEFINITION) LIBS += -lUser32 } diff --git a/scripts/pkg-config-wrapper.py b/scripts/pkg-config-wrapper.py new file mode 100644 index 0000000..37a3ddd --- /dev/null +++ b/scripts/pkg-config-wrapper.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +# On Windows, static libraries are using "foo.lib" naming. +# On Unix, they are in the form of "libfoo.a" +# On Windows, "foo.lib" can also the definition of symbols in a foo.dll. +# So you can link to "foo.lib", whatever you are doing static or dynamic linking and you are good. +# However, meson is always creating static library as "libfoo.a" +# 'to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.' [1] +# On top of that, qmake is replacing all `-lfoo` in LIBS by `foo.lib` (on Windows). +# So at the end, we try to link with `foo.lib` but we have `libfoo.a` +# Solution could be : +# - Rename `libfoo.a` to `foo.lib`, but it would mean modify deps libraries on the FS +# - Don't use LIBS and direction set QMAKE_LFLAGS but we would have to handle different command line option format +# between g++/clang and msvc +# - Update meson build system of each projet to explicitly set the library naming. +# - Replace `-lfoo` with absolute path to static library. This is what meson is doing internally and what +# we are doing here +# +# Any `-lfoo` is replace with absolute path to static library (`libfoo.a`) if we found one. +# Else, it is keep unchanged. +# +# [1] https://mesonbuild.com/Reference-manual_functions.html#library_name_suffix + +import sys, subprocess +from pathlib import Path + +def forward_to_pkg_config(): + completeProcess = subprocess.run(["pkg-config", *sys.argv[1:]], capture_output=True, check=True, text=True) + return completeProcess.stdout + +def search_static_lib(lib_name, search_pathes): + for path in search_pathes: + lib_path = path/f"lib{lib_name}.a" + if lib_path.exists(): + return f"lib{lib_name}.a" + return None + + +def replace_static_lib(pkg_output): + search_pathes = [] + for option in pkg_output.split(): + if option.startswith("-L"): + search_pathes.append(Path(option[2:])) + yield option + if option.startswith("-l"): + static_lib = search_static_lib(option[2:], search_pathes) + if static_lib: + yield static_lib + else: + yield option + +if __name__ == "__main__": + pkg_output = forward_to_pkg_config() + print(" ".join(replace_static_lib(pkg_output))) + + + + From 87c7449262c7ebd40c34ca6e852d73d12553e409 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 21 Aug 2024 17:11:11 +0200 Subject: [PATCH 2/3] [CI] Build kiwix-desktop on Windows --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++++++++++ scripts/pkg-config-wrapper.py | 33 +++++++++++++------------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59f89ff..ef931f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,50 @@ on: - main jobs: + Windows: + strategy: + fail-fast: false + matrix: + config: + - native_mixed + runs-on: windows-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup python 3.8 + uses: actions/setup-python@v3 + with: + python-version: '3.8' + + - name: Install packages + run: | + choco.exe install pkgconfiglite + + - name: Install QT + uses: jurplel/install-qt-action@v4 + with: + version: 5.15.2 + modules: "qtwebengine" + setup-python: false + + - name: Setup MSVC compiler + uses: bus1/cabuild/action/msdevshell@v1 + with: + architecture: x64 + + - name: Install dependencies + uses: kiwix/kiwix-build/actions/dl_deps_archive@main + with: + target_platform: win-x86_64-mixed + + - name: Compile + shell: cmd + run: | + set PKG_CONFIG_PATH=%cd%\BUILD_win-amd64\INSTALL\lib\pkgconfig + qmake PREFIX=%cd%\BUILD_win-amd64\INSTALL + nmake debug-all + Linux: strategy: fail-fast: false diff --git a/scripts/pkg-config-wrapper.py b/scripts/pkg-config-wrapper.py index 37a3ddd..cb89b85 100644 --- a/scripts/pkg-config-wrapper.py +++ b/scripts/pkg-config-wrapper.py @@ -10,7 +10,7 @@ # So at the end, we try to link with `foo.lib` but we have `libfoo.a` # Solution could be : # - Rename `libfoo.a` to `foo.lib`, but it would mean modify deps libraries on the FS -# - Don't use LIBS and direction set QMAKE_LFLAGS but we would have to handle different command line option format +# - Don't use LIBS and directly set QMAKE_LFLAGS but we would have to handle different command line option format # between g++/clang and msvc # - Update meson build system of each projet to explicitly set the library naming. # - Replace `-lfoo` with absolute path to static library. This is what meson is doing internally and what @@ -24,35 +24,36 @@ import sys, subprocess from pathlib import Path + def forward_to_pkg_config(): - completeProcess = subprocess.run(["pkg-config", *sys.argv[1:]], capture_output=True, check=True, text=True) + completeProcess = subprocess.run( + ["pkg-config", *sys.argv[1:]], capture_output=True, check=True, text=True + ) return completeProcess.stdout - -def search_static_lib(lib_name, search_pathes): - for path in search_pathes: - lib_path = path/f"lib{lib_name}.a" + + +def search_static_lib(lib_name, search_paths): + for path in search_paths: + lib_path = path / f"lib{lib_name}.a" if lib_path.exists(): - return f"lib{lib_name}.a" + return str(lib_path) return None - + def replace_static_lib(pkg_output): - search_pathes = [] + search_paths = [] for option in pkg_output.split(): if option.startswith("-L"): - search_pathes.append(Path(option[2:])) + search_paths.append(Path(option[2:])) yield option if option.startswith("-l"): - static_lib = search_static_lib(option[2:], search_pathes) + static_lib = search_static_lib(option[2:], search_paths) if static_lib: yield static_lib else: yield option - + + if __name__ == "__main__": pkg_output = forward_to_pkg_config() print(" ".join(replace_static_lib(pkg_output))) - - - - From 76d5e4c33625d4cb2746fb1661c96cee6721568c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 22 Aug 2024 10:52:48 +0200 Subject: [PATCH 3/3] Use last version of github actions --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef931f6..d3f4d1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,10 @@ jobs: runs-on: windows-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup python 3.8 - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: '3.8' @@ -74,7 +74,7 @@ jobs: target_platform: linux-x86_64-dyn - name: Retrieve source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Compile source code shell: bash