From 9d2b90d1054b6285a75f37d88b9d4c149845ed58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Sat, 4 Nov 2023 23:18:51 +0100 Subject: [PATCH] Build Windows binary using Python script --- .github/workflows/build.yml | 15 ++++--------- scripts/build-openssl.bat | 44 ------------------------------------- scripts/build-openssl.py | 17 +++++++++++--- 3 files changed, 18 insertions(+), 58 deletions(-) delete mode 100644 scripts/build-openssl.bat diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fdae898..054bd44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,24 +26,17 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - name: Install nasm - if: matrix.os == 'windows-latest' - run: choco install -y nasm - - name: Install nmake - if: matrix.os == 'windows-latest' - run: | - & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify ` - --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ` - --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --passive --norestart - shell: powershell - name: Install qemu if: matrix.os == 'ubuntu-latest' uses: docker/setup-qemu-action@v3 + - name: Install nasm + if: matrix.os == 'windows-latest' + run: choco install -y nasm - name: Build OpenSSL env: CIBW_ARCHS: ${{ matrix.arch }} CIBW_BEFORE_BUILD: python scripts/build-openssl.py /tmp/vendor - CIBW_BEFORE_BUILD_WINDOWS: scripts\build-openssl.bat C:\cibw\vendor + CIBW_BEFORE_BUILD_WINDOWS: python scripts\build-openssl.py C:\cibw\vendor CIBW_BUILD: cp38-* CIBW_SKIP: '*-musllinux*' CIBW_TEST_COMMAND: python -c "import dummy" diff --git a/scripts/build-openssl.bat b/scripts/build-openssl.bat deleted file mode 100644 index 5a3355b..0000000 --- a/scripts/build-openssl.bat +++ /dev/null @@ -1,44 +0,0 @@ -set destdir=%1 - -for %%d in (openssl %destdir%) do ( - if exist %%d ( - rmdir /s /q %%d - ) -) - -if %PYTHON_ARCH% == 64 ( - set platform=win_amd64 - set OPENSSL_CONFIG=VC-WIN64A - set VC_ARCH=x64 -) else ( - set platform=win32 - set OPENSSL_CONFIG=VC-WIN32 - set VC_ARCH=x86 -) -set outputfile=output\openssl-%platform%.tar.gz - -call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %VC_ARCH% -SET PATH=%PATH%;C:\Program Files\NASM - -mkdir openssl -curl -L https://www.openssl.org/source/openssl-3.1.4.tar.gz -o openssl.tar.gz -tar xzf openssl.tar.gz -C openssl --strip-components 1 -cd openssl - -perl Configure no-comp no-shared no-tests %OPENSSL_CONFIG% -nmake - -mkdir %destdir% -mkdir %destdir%\include -mkdir %destdir%\lib -xcopy include %destdir%\include\ /E -copy libcrypto.lib %destdir%\lib\ -copy libssl.lib %destdir%\lib\ -cd .. - -if not exist output ( - mkdir output -) -SET PATH=C:\Program Files\Git\usr\bin;%PATH% -tar czvf %outputfile% -C %destdir% include lib -dir output diff --git a/scripts/build-openssl.py b/scripts/build-openssl.py index 444ea31..d492650 100644 --- a/scripts/build-openssl.py +++ b/scripts/build-openssl.py @@ -71,6 +71,13 @@ def run(cmd, *, env=None): run(["yum", "-y", "install", "perl-IPC-Cmd"]) elif platform.system() == "Darwin" and os.environ.get("ARCHFLAGS") == "-arch arm64": configure_args = ["darwin64-arm64"] +elif platform.system() == "Windows": + os.environ["PATH"] = "C:\\Program Files\\NASM;" + os.environ["PATH"] + if get_platform() == "win_amd64": + configure_args = ["VC-WIN64A"] + else: + configure_args = ["VC-WIN32"] + output_tarball = os.path.join(output_dir, f"openssl-{get_platform()}.tar.gz") for d in [build_dir, output_dir, source_dir]: @@ -82,8 +89,12 @@ def run(cmd, *, env=None): # build openssl extract("openssl", "https://www.openssl.org/source/openssl-3.1.4.tar.gz") os.chdir("openssl") - run(["./config"] + configure_args + ["no-comp", "no-shared", "no-tests"]) - run(["make", "-j"]) - run(["make", "install_sw", "INSTALLTOP=" + dest_dir, "LIBDIR=lib"]) + run(["perl", "Configure"] + configure_args + ["no-comp", "no-shared", "no-tests"]) + if platform.system() == "Windows": + run(["nmake"]) + run(["nmake", "install_sw"]) + else: + run(["make", "-j"]) + run(["make", "install_sw", "INSTALLTOP=" + dest_dir, "LIBDIR=lib"]) run(["tar", "czvf", output_tarball, "-C", dest_dir, "include", "lib"])