Skip to content

Commit

Permalink
Use prebuilt libraries for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
naveen521kk committed Sep 13, 2024
1 parent d461a46 commit 5bb7784
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ jobs:
# Run 32 and 64 bit version in parallel for Windows
- os: windows-2022
platform_id: win_amd64
architecture: x64
- os: windows-2022
platform_id: win32
architecture: x86
- os: macos-13
platform_id: macosx_x86_64
architecture: x86_64
- os: macos-14
platform_id: macosx_arm64
architecture: arm64
env:
CIBW_BUILD: cp39-${{ matrix.platform_id }} cp310-${{ matrix.platform_id }} cp311-${{ matrix.platform_id }} cp312-${{ matrix.platform_id }} cp313-${{ matrix.platform_id }}
CIBW_SKIP: pp* cp36* cp37* cp38*
CIBW_BEFORE_BUILD_MACOS: "source packing/build_pango_mac.sh"
CIBW_BEFORE_BUILD_MACOS: "python packing/download_pango_macos.py ${{ matrix.architecture }}"
CIBW_BEFORE_BUILD_WINDOWS: "python packing/download_dlls.py"
CIBW_ENVIRONMENT_WINDOWS: "PKG_CONFIG_PATH='C:\\cibw\\vendor\\lib\\pkgconfig'"
CIBW_ENVIRONMENT_MACOS: "PKG_CONFIG_PATH='/Users/runner/pangobuild/lib/pkgconfig'"
Expand Down
67 changes: 67 additions & 0 deletions packing/download_pango_macos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import os
import re
import shutil
import tempfile
import zipfile
from pathlib import Path
import sys
from urllib.request import urlretrieve as download

PANGO_VERSION = "1.54.0-v2"

logging.basicConfig(format="%(levelname)s - %(message)s", level=logging.DEBUG)


plat = sys.argv[1]
logging.debug(f"Platform is {plat}")

download_url = (
"https://github.com/naveen521kk/pango-build/releases"
f"/download/v{PANGO_VERSION}/pango-v{PANGO_VERSION}-mac-{plat}.zip"
)
final_location = Path(r"~/pangobuild").expanduser()
download_location = Path(tempfile.mkdtemp())
if final_location.exists():
logging.info("Final Location already exists clearing it...")
shutil.rmtree(str(final_location))
os.makedirs(final_location)
download_file = download_location / "build.zip"
logging.info("Downloading Pango and Cairo Binaries for macOS...")
logging.info("Url: %s", download_url)
download(url=download_url, filename=download_file)
logging.info(f"Download complete. Saved to {download_file}.")
logging.info(f"Extracting {download_file} to {download_location}...")
with zipfile.ZipFile(
download_file, mode="r", compression=zipfile.ZIP_DEFLATED
) as file: # noqa: E501
file.extractall(download_location)
os.remove(download_file)
logging.info("Completed Extracting.")
logging.info("Moving Files accordingly.")

plat_location = download_location / f"mac-pango-{plat}"
for src_file in plat_location.glob("*"):
logging.debug(f"Moving {src_file} to {final_location}...")
shutil.move(str(src_file), str(final_location))
logging.info("Moving files Completed")
logging.info("Fixing .pc files")


rex = re.compile("^prefix=(.*)")


def new_place(_) -> str:
return f"prefix={str(final_location.as_posix())}"


pc_files = final_location / "lib" / "pkgconfig"
for i in pc_files.glob("*.pc"):
logging.info(f"Writing {i}")
with open(i) as f:
content = f.read()
final = rex.sub(new_place, content)
with open(i, "w") as f:
f.write(final)

0 comments on commit 5bb7784

Please sign in to comment.