Skip to content

Commit

Permalink
do not create universal2 wheels before compiling, fix #186
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Aug 3, 2024
1 parent b951389 commit 87955d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ jobs:
- os: macos-14
TARGET: macos-x86_64
CMD_BUILD: |
SC_COMPILE_ARCH=x86_64 python ./compile.py
python ./compile.py
cp ./scripts/hold_control_and_click_open_me_first.command ./
zip -r9 sticker-convert-macos-x86_64.zip sticker-convert.app hold_control_and_click_open_me_first.command
OUT_FILE_NAME: ./sticker-convert-macos-x86_64.zip
- os: macos-14
TARGET: macos-arm64
CMD_BUILD: |
SC_COMPILE_ARCH=arm64 python ./compile.py
python ./compile.py
cp ./scripts/hold_control_and_click_open_me_first.command ./
zip -r9 sticker-convert-macos-arm64.zip sticker-convert.app hold_control_and_click_open_me_first.command
OUT_FILE_NAME: ./sticker-convert-macos-arm64.zip
Expand Down
86 changes: 6 additions & 80 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,7 @@ def search_wheel_in_dir(package: str, dir: Path) -> Path:
raise RuntimeError(f"Cannot find wheel for {package}")


def copy_if_universal(wheel_name: Path, in_dir: Path, out_dir: Path) -> bool:
if wheel_name.name.endswith("universal2.whl") or wheel_name.name.endswith(
"any.whl"
):
src_path = Path(in_dir, wheel_name.name)
dst_path = Path(
out_dir,
wheel_name.name.replace("x86_64", "universal2").replace(
"arm64", "universal2"
),
)

shutil.copy(src_path, dst_path)
return True
else:
return False


def create_universal_wheels(in_dir1: Path, in_dir2: Path, out_dir: Path) -> None:
for wheel_name_1 in in_dir1.iterdir():
package = wheel_name_1.name.split("-")[0]
wheel_name_2 = search_wheel_in_dir(package, in_dir2)
if copy_if_universal(wheel_name_1, in_dir1, out_dir):
continue
if copy_if_universal(wheel_name_2, in_dir2, out_dir):
continue

wheel_path_1 = Path(in_dir1, wheel_name_1.name)
wheel_path_2 = Path(in_dir2, wheel_name_2.name)
subprocess.run(
["delocate-fuse", wheel_path_1, wheel_path_2, "-w", str(out_dir)]
)
print(f"Created universal wheel {wheel_path_1} {wheel_path_2}")

for wheel_path in out_dir.iterdir():
wheel_name_new = wheel_path.name.replace("x86_64", "universal2").replace(
"arm64", "universal2"
)

src_path = Path(out_dir, wheel_path.name)
dst_path = Path(out_dir, wheel_name_new)

src_path.rename(dst_path)
print(f"Renamed universal wheel {dst_path}")


def osx_install_universal2_dep() -> None:
shutil.rmtree("wheel_arm", ignore_errors=True)
shutil.rmtree("wheel_x64", ignore_errors=True)
shutil.rmtree("wheel_universal2", ignore_errors=True)

Path("wheel_arm").mkdir()
Path("wheel_x64").mkdir()
Path("wheel_universal2").mkdir()

osx_run_in_venv(
"python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_arm64 --only-binary=:all: -d wheel_arm"
)
osx_run_in_venv(
"python -m pip download --require-virtualenv -r requirements.txt --platform macosx_11_0_x86_64 --only-binary=:all: -d wheel_x64"
)

create_universal_wheels(
Path("./wheel_arm"), Path("./wheel_x64"), Path("wheel_universal2")
)
osx_run_in_venv("python -m pip install --require-virtualenv ./wheel_universal2/*")


def nuitka(python_bin: str, arch: Optional[str] = None) -> None:
def nuitka(python_bin: str) -> None:
cmd_list = [
python_bin,
"-m",
Expand All @@ -130,8 +62,6 @@ def nuitka(python_bin: str, arch: Optional[str] = None) -> None:
cmd_list.append("--disable-console")
cmd_list.append("--macos-create-app-bundle")
cmd_list.append("--macos-app-icon=src/sticker_convert/resources/appicon.icns")
if arch is not None:
cmd_list.append(f"--macos-target-arch={arch}")
cmd_list.append(f"--macos-app-version={__version__}")
else:
cmd_list.append("--linux-icon=src/sticker_convert/resources/appicon.png")
Expand Down Expand Up @@ -165,7 +95,6 @@ def osx_patch() -> None:


def compile() -> None:
arch = os.getenv("SC_COMPILE_ARCH")
python_bin = str(Path(sys.executable).resolve())

ios_stickers_path = "src/sticker_convert/ios-message-stickers-template"
Expand All @@ -191,14 +120,11 @@ def compile() -> None:
subprocess.run(f"{python_bin} -m venv venv".split(" "))
python_bin = "python"
osx_run_in_venv("python -m pip install -r requirements-build.txt")
if arch is None:
osx_run_in_venv(
"python -m pip install --require-virtualenv -r requirements.txt"
)
else:
osx_install_universal2_dep()

nuitka(python_bin, arch)
osx_run_in_venv(
"python -m pip install --require-virtualenv -r requirements.txt"
)

nuitka(python_bin)

if platform.system() == "Windows":
win_patch()
Expand Down

0 comments on commit 87955d9

Please sign in to comment.