Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build #1086

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ on:
push:
tags:
- v*
# TODO: fix and re-enable
#pull_request: # Build windows exe and docs, but not release anything
pull_request: # Build windows exe and docs, but not release anything

jobs:
windows-build:
Expand All @@ -14,16 +13,10 @@ jobs:
with:
python-version: "3.8" # last version supporting windows 7
- run: pip install -r requirements.txt -r requirements-dev.txt
- uses: egor-tensin/setup-mingw@v2
with:
platform: x64
- name: Install scoop
run: |
(New-Object System.Net.WebClient).DownloadFile('https://get.scoop.sh', 'scoop-installer.ps1')
pwsh -File scoop-installer.ps1 -RunAsAdmin
echo "${HOME}\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- run: scoop bucket add extras
- run: scoop install nsis
# FIXME: recompile launcher when this is fixed: https://github.com/egor-tensin/setup-mingw/issues/6
# - uses: egor-tensin/setup-mingw@v2
# with:
# platform: x64
# -u makes print show in real time
- run: python -u scripts/build-exe-installer.py
- uses: actions/upload-artifact@v2
Expand Down
Binary file added launcher/Porcupine.exe
Binary file not shown.
43 changes: 23 additions & 20 deletions scripts/build-exe-installer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import io
import os
import shutil
Expand All @@ -20,19 +21,16 @@
assert 8 * struct.calcsize("P") == 64


def delete(path):
if path.is_file():
path.unlink()
else:
shutil.rmtree(path)


try:
os.mkdir("build")
print("Created directory: build")
except FileExistsError:
print("Found existing build directory, deleting contents")
for path in list(Path("build").glob("*")):
delete(path)
if path.is_file():
path.unlink()
else:
shutil.rmtree(path)


print("Downloading Python")
Expand All @@ -46,6 +44,16 @@ def delete(path):
response.raise_for_status()
zipfile.ZipFile(io.BytesIO(response.content)).extractall("build/python-first")

print("Downloading NSIS")
url = "https://downloads.sourceforge.net/project/nsis/NSIS%203/3.08/nsis-3.08.zip"
print(url)
response = requests.get(url)
response.raise_for_status()
zip_hash = hashlib.sha256(response.content).hexdigest()
assert zip_hash == "1bb9fc85ee5b220d3869325dbb9d191dfe6537070f641c30fbb275c97051fd0c"
zipfile.ZipFile(io.BytesIO(response.content)).extractall("build")


print("Copying files")

if "VIRTUAL_ENV" in os.environ:
Expand Down Expand Up @@ -85,14 +93,11 @@ def delete(path):
print("Converting logo to .ico format")
PIL.Image.open("porcupine/images/logo-200x200.gif").save("build/porcupine-logo.ico")

# If you can't get a C compiler to work (with windres):
# 1. Download a Porcupine installer from GitHub and install Porcupine
# 2. Copy C:\Users\YourName\AppData\Local\Programs\Porcupine\Python\Porcupine.exe
# to where you cloned Porcupine
# 3. Uninstall Porcupine
if os.path.exists("Porcupine.exe"):
print("Porcupine.exe found, no C compiler needed")
shutil.copy("Porcupine.exe", "build/launcher/")
# FIXME: Currently I can't get C compiler to work on github actions.
# I have committed a copy of the Porcupine.exe launcher here.
# Unfortunately the launcher contains an old version number that I can't update...
if os.path.exists("build/launcher/Porcupine.exe"):
print("Found launcher/Porcupine.exe, no C compiler needed")
else:
print("Porcupine.exe was not found, compiling")
subprocess.check_call(
Expand Down Expand Up @@ -120,7 +125,6 @@ def delete(path):
[
"pip",
"install",
"--use-feature=in-tree-build", # TODO: delete once pip new enough to not show warning without this
"--target=build/python-second",
".",
"setuptools", # pyls needs pkg_resources from setuptools, don't know why need explicitly
Expand All @@ -130,7 +134,7 @@ def delete(path):
print("Deleting __pycache__ directories")
for path in list(Path("build/python-second").rglob("__pycache__")):
print(path)
delete(path)
shutil.rmtree(path)

print("Moving files")
shutil.move("build/launcher/Porcupine.exe", "build/python-second/Porcupine.exe")
Expand All @@ -155,8 +159,7 @@ def delete(path):
]
print(extensions)

# makensis is not in PATH when nsis is installed without scoop
makensis = shutil.which("makensis") or r"C:\Program Files (x86)\NSIS\makensis.exe"
makensis = os.path.abspath("build/nsis-3.08/makensis.exe")
print(f"Running {makensis}")
subprocess.check_call(
[
Expand Down