Skip to content

Commit

Permalink
Package kiwix-desktop on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Aug 26, 2024
1 parent 1d93c35 commit 45ad417
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
24 changes: 22 additions & 2 deletions .github/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def get_build_dir(config) -> Path:
INSTALL_DIR = BASE_DIR / "INSTALL"
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 @@ -480,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
4 changes: 2 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 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 45ad417

Please sign in to comment.