Skip to content

Commit

Permalink
Merge pull request #719 from kiwix/win-kiwix-desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr authored Aug 26, 2024
2 parents 9c7f963 + d8b4d24 commit 4ff5132
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/build_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# On Windows, we build only libzim for now. And only native_mixed as xapian doesn't compile as dll
| windows | native_static | Bd | d | | d | | win-x86_64 | win-x86_64-static |
| windows | native_dyn | Bd | | | | | win-x86_64 | win-x86_64-dyn |
| windows | native_mixed | BPd | d | | | d | win-x86_64 | win-x86_64-mixed |
| windows | native_mixed | BPd | d | | | Bd | win-x86_64 | win-x86_64-mixed |
----------------------------------------------------------------------------------------------------------------------------------------------
# Osx builds, build binaries on native_dyn and native_static. On anyother things, build only the libraries
| macos | native_dyn | d | d | dB | B | | | macos-x86_64-dyn |
Expand Down
41 changes: 34 additions & 7 deletions .github/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ def get_build_dir(config) -> Path:
ARCHIVE_DIR = HOME / "ARCHIVE"
TOOLCHAIN_DIR = BASE_DIR / "TOOLCHAINS"
INSTALL_DIR = BASE_DIR / "INSTALL"
default_tmp_dir = os.getenv("TEMP") if platform.system() == 'Windows' else "/tmp"
default_tmp_dir = os.getenv("TEMP") if platform.system() == "Windows" else "/tmp"
TMP_DIR = Path(os.getenv("TMP_DIR", default_tmp_dir))
KBUILD_SOURCE_DIR = HOME / "kiwix-build"
if platform.system() == "Windows":
KBUILD_SOURCE_DIR = Path(_environ["GITHUB_WORKSPACE"])
else:
KBUILD_SOURCE_DIR = HOME / "kiwix-build"


_ref = _environ.get("GITHUB_REF", "").split("/")[-1]
MAKE_RELEASE = re.fullmatch(r"r_[0-9]+", _ref) is not None
Expand Down Expand Up @@ -204,6 +208,7 @@ def run_kiwix_build(
subprocess.check_call(command, cwd=str(HOME), env=env)
print_message("Build ended")


try:
import paramiko

Expand All @@ -216,8 +221,8 @@ def upload(file_to_upload, host, dest_path):
host, port = host.split(":", 1)
else:
port = "22"
if '@' in host:
user, host = host.split('@', 1)
if "@" in host:
user, host = host.split("@", 1)
else:
user = None

Expand All @@ -228,7 +233,14 @@ def get_client():
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.client.WarningPolicy)
print_message(f"Connect to {host}:{port}")
client.connect(host, port=port, username=user, key_filename=_environ.get("SSH_KEY"), look_for_keys=False, compress=True)
client.connect(
host,
port=port,
username=user,
key_filename=_environ.get("SSH_KEY"),
look_for_keys=False,
compress=True,
)
try:
yield client
finally:
Expand Down Expand Up @@ -257,7 +269,6 @@ def get_sftp():
print_message(f"Sending archive {file_to_upload} to {remote_file}")
sftp.put(str(file_to_upload), str(remote_file), confirm=True)


except ModuleNotFoundError:
# On old system (bionic) paramiko is really complex to install
# Keep the old implementaion on sush system.
Expand Down Expand Up @@ -473,11 +484,27 @@ def create_desktop_image(make_release):
build_path = BASE_DIR / "org.kiwix.desktop.flatpak"
app_name = "org.kiwix.desktop.{}.flatpak".format(postfix)
print_message("archive is {}", build_path)
elif platform.system() == "Windows":
archive_basename = "Kiwix-{}-win-amd64".format(postfix)
working_dir = INSTALL_DIR / archive_basename
build_path = working_dir.with_suffix(".zip")
app_name = build_path.name
command = [
"python",
KBUILD_SOURCE_DIR / "scripts" / "package_kiwix-desktop_windows.py",
str(INSTALL_DIR),
str(working_dir),
str(build_path),
]
if make_release:
command += ["-s"]
print_message("Package archive of kiwix-desktop")
subprocess.check_call(command, cwd=str(HOME))
else:
build_path = HOME / "Kiwix-{}-x86_64.AppImage".format(postfix)
app_name = "kiwix-desktop_x86_64_{}.appimage".format(postfix)
command = [
"kiwix-build/scripts/create_kiwix-desktop_appImage.sh",
KBUILD_SOURCE_DIR / "scripts" / "create_kiwix-desktop_appImage.sh",
str(INSTALL_DIR),
str(src_dir),
str(HOME / "AppDir"),
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup python 3.8
- name: Setup python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.8'
python-version: '3.12'
- name: Install packages
run: |
choco.exe install pkgconfiglite ninja
Expand All @@ -34,6 +34,12 @@ jobs:
run: |
pip3 install meson pytest requests distro paramiko
pip3 install --no-deps $GITHUB_WORKSPACE
- 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:
Expand Down
5 changes: 4 additions & 1 deletion kiwixbuild/buildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def __init__(self, dummy_run):
self.mesontest_command = [*self.meson_command, "test"]
self.patch_command = self._detect_command("patch")
self.git_command = self._detect_command("git")
self.make_command = self._detect_command("make")
if platform.system() == "Windows":
self.make_command = self._detect_command("nmake", options=["/?", "/NOLOGO"])
else:
self.make_command = self._detect_command("make")
self.cmake_command = self._detect_command("cmake")
self.qmake_command = self._detect_command(
"qmake", required=False, default=[["qmake"], ["qmake-qt5"]]
Expand Down
68 changes: 43 additions & 25 deletions kiwixbuild/dependencies/all_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,50 @@ class AllBaseDependencies(Dependency):
class Builder(NoopBuilder):
@classmethod
def get_dependencies(cls, configInfo, allDeps):
if neutralEnv("distname") == "Windows":
return ["zlib", "zstd", "icu4c", "zim-testing-suite", "xapian-core"]
if configInfo.build == "wasm" or environ.get("OS_NAME") == "manylinux":
return ["zlib", "lzma", "zstd", "icu4c", "xapian-core"]

base_deps = [
"zlib",
"lzma",
"zstd",
"xapian-core",
"pugixml",
"libcurl",
"icu4c",
"mustache",
"libmicrohttpd",
"zim-testing-suite",
]
# Add specific dependencies depending of the config
if configInfo.build not in ("android", "iOS"):
# For zimtools
base_deps += ["docoptcpp"]
if configInfo.build != "win32":
# zimwriterfs
base_deps += ["libmagic", "gumbo"]
if configInfo.build == "native" and neutralEnv("distname") != "Darwin":
# We compile kiwix-desktop only on native and not on `Darwin`
# So we need aria2 only there
base_deps += ["aria2"]
if neutralEnv("distname") == "Windows":
base_deps = [
"zlib",
"zstd",
"xapian-core",
"zim-testing-suite",
"icu4c",
]

if not configInfo.name.endswith("_dyn"):
base_deps += [
"pugixml",
"libcurl",
"mustache",
"libmicrohttpd",
]
else:
base_deps = [
"zlib",
"lzma",
"zstd",
"xapian-core",
"pugixml",
"libcurl",
"icu4c",
"mustache",
"libmicrohttpd",
"zim-testing-suite",
]
# Add specific dependencies depending of the config
if configInfo.build not in ("android", "iOS"):
# For zimtools
base_deps += ["docoptcpp"]
if configInfo.build != "win32":
# zimwriterfs
base_deps += ["libmagic", "gumbo"]
if (
configInfo.build == "native"
and neutralEnv("distname") != "Darwin"
):
# We compile kiwix-desktop only on native and not on `Darwin`
# So we need aria2 only there
base_deps += ["aria2"]
return base_deps
10 changes: 8 additions & 2 deletions kiwixbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import shutil
import time
import platform

from kiwixbuild.utils import (
pj,
Expand Down Expand Up @@ -379,7 +380,7 @@ class MakeBuilder(Builder):
configure_options = []
dynamic_configure_options = ["--enable-shared", "--disable-static"]
static_configure_options = ["--enable-static", "--disable-shared"]
make_options = []
make_options = ["-j4"]
install_options = []
configure_script = "configure"
configure_env = {
Expand Down Expand Up @@ -435,7 +436,6 @@ def _compile(self, context):
command = [
*self.buildEnv.make_wrapper,
*neutralEnv("make_command"),
"-j4",
*self.make_targets,
*self.make_options,
]
Expand Down Expand Up @@ -492,6 +492,12 @@ class QMakeBuilder(MakeBuilder):
qmake_targets = []
flatpak_buildsystem = "qmake"

@property
def make_options(self):
if platform.system() == "Windows":
return []
return super().make_options

@property
def env_options(self):
if "QMAKE_CC" in os.environ:
Expand Down
17 changes: 16 additions & 1 deletion kiwixbuild/dependencies/kiwix_desktop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from kiwixbuild._global import option
from .base import Dependency, GitClone, QMakeBuilder
import platform


class KiwixDesktop(Dependency):
Expand All @@ -11,11 +13,24 @@ class Source(GitClone):

class Builder(QMakeBuilder):
dependencies = ["qt", "qtwebengine", "libkiwix", "aria2"]
make_install_targets = ["install"]
configure_env = None

flatpack_build_options = {"env": {"QMAKEPATH": "/app/lib"}}

@property
def make_targets(self):
if platform.system() == "Windows":
yield "release-all" if option("make_release") else "debug-all"
else:
yield from super().make_targets

@property
def make_install_targets(self):
if platform.system() == "Windows":
yield "release-install" if option("make_release") else "debug-install"
else:
yield "install"

@property
def configure_options(self):
if self.buildEnv.configInfo.name != "flatpak":
Expand Down
2 changes: 1 addition & 1 deletion kiwixbuild/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# This is the "version" of the whole base_deps_versions dict.
# Change this when you change base_deps_versions.
base_deps_meta_version = "04"
base_deps_meta_version = "05"

base_deps_versions = {
"zlib": "1.2.12",
Expand Down
63 changes: 63 additions & 0 deletions scripts/package_kiwix-desktop_windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3

import sys, subprocess, shutil, argparse
from pathlib import Path

parser = argparse.ArgumentParser()

parser.add_argument("install_dir")
parser.add_argument("out_dir")
parser.add_argument("--static_dir")
parser.add_argument("archive_path", help="The full path of the archive to create")
parser.add_argument("-s", "--sign", action="store_true")

args = parser.parse_args()

install_dir = Path(args.install_dir)
if args.static_dir:
static_dir = Path(args.static_dir)
else:
static_dir = install_dir

out_dir = Path(args.out_dir)
archive_path = Path(args.archive_path)

out_dir.mkdir(parents=True, exist_ok=True)

print(
f"""Packaging kiwix-desktop
- From {install_dir}
- Static dir is {static_dir}
- Working dir {out_dir}
- Archive path is {archive_path}
- Python version {sys.version}"""
)

shutil.copy2(install_dir / "bin" / "kiwix-desktop.exe", out_dir)
subprocess.run(["windeployqt", "--compiler-runtime", str(out_dir)], check=True)


shutil.copy2(static_dir / "bin" / "aria2c.exe", out_dir)

for dll in (static_dir / "bin").glob("*.dll"):
shutil.copy2(dll, out_dir)


# Copy ssl stuff
ssl_directory = Path("C:/") / "Program Files" / "OpenSSL"
shutil.copy2(ssl_directory / "libcrypto-1_1-x64.dll", out_dir)
shutil.copy2(ssl_directory / "libssl-1_1-x64.dll", out_dir)

# [TODO] Sign binary
if args.sign:
pass

print(
f"""Create archive
- {archive_path.with_suffix('')}
- From {out_dir.parent}
- With {out_dir.name}"""
)
shutil.make_archive(
archive_path.with_suffix(""), "zip", root_dir=out_dir.parent, base_dir=out_dir.name
)

0 comments on commit 4ff5132

Please sign in to comment.