Skip to content

Instantly share code, notes, and snippets.

@schlomo
Last active September 24, 2020 21:32
Show Gist options
  • Save schlomo/7f3c65969ca06f384e85accb8c88bff4 to your computer and use it in GitHub Desktop.
Save schlomo/7f3c65969ca06f384e85accb8c88bff4 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e -o pipefail -u -x
:
: wenv Python version $WENV_PYTHONVERSION
:
apt-get -qq update &>/dev/null
DEBIAN_FRONTEND=noninteractive apt-get -qq install python3-pip wine jq curl &>/dev/null
pip3 -qq install wenv yamlreader https://github.com/pyinstaller/pyinstaller/archive/develop.zip
wenv init
destdir=/usr/share/wenv/win64/drive_c/python-${PYTHONVERSION}/Include/
mkdir -p $destdir
# pyinstaller needs pyconfig.h, download from source.
# It seems like pyconfig.h doesn't change with Python patch versions, "guess" URL (it is major.minor without patch)
curl -so $destdir/pyconfig.h https://raw.githubusercontent.com/python/cpython/${PYTHONVERSION%.*}/PC/pyconfig.h
# pyinstaller seems to need pywin32 to build an EXE
wenv pip3 -qq install pywin32 yamlreader https://github.com/pyinstaller/pyinstaller/archive/develop.zip
# show wenv setup
wenv --help
# check pyinstaller on Linux
pyinstaller --onefile /usr/local/bin/yamlreader
:
: "Testing Linux binary:"
:
dist/yamlreader <(echo "
key:
hello: world
list: [foo]
") <(echo "
key:
hello: big worlds
list: [bar]
")
# build EXE
if wenv pyinstaller --onefile /usr/local/bin/yamlreader ; then
: "Build OK"
ls -l dist/*.exe
else
echo -e "\n\n*********\n\nPYINSTALLER BUILD FAILED - YOU CAN EXPLORE THE IMAGE\n\n" 1>&2
fi
:
: "Testing Windows binary:"
:
wine dist/yamlreader.exe --help || echo -e "\n\n*********\n\nWINDOWS EXE FAILED - YOU CAN EXPLORE THE IMAGE\n\nEXTRACT RESULTS WITH\n\ndocker run --rm <THIS DOCKER IMAGE> tar -c dist | tar -xv\n" 1>&2
# This is a demo for the problem in https://github.com/pleiszenburg/wenv/issues/14
#
# it builds yamlreader into an executable. First on Linux and then in wine.
#
# Building it in wine fails, I hope that this test case helps to extend wenv to support this sort of "cross building"
# to allow creating Windows executables from Python programs without actually running Windows, e.g. in a CI pipeline.
#
# Build like this: docker build .
#
# Optionally set the Pyhon version like this: docker build --build-arg PYTHONVERSION=3.8.1 .
FROM ubuntu
ARG PYTHONVERSION=3.8.4
ENV WENV_PYTHONVERSION=${PYTHONVERSION}
ENV WENV_ARCH=win64
ADD demo.sh /work/demo.sh
WORKDIR /work
RUN bash demo.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment