From fcdd8ce7c15a874e8ab40100105c266779b2c4d1 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:49:53 +0800 Subject: [PATCH] windows: script for building the lib (#3340) * windows: script for building the lib * changes * change * change --- .github/workflows/build.yml | 19 ++++++-- apps/multiplatform/desktop/build.gradle.kts | 6 +-- .../kotlin/chat/simplex/desktop/Main.kt | 7 +-- scripts/desktop/build-lib-windows.sh | 47 +++++++++++++++++-- scripts/desktop/download-lib-windows.sh | 30 ------------ 5 files changed, 63 insertions(+), 46 deletions(-) delete mode 100644 scripts/desktop/download-lib-windows.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b4301dcb3..6687f4797 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -293,13 +293,26 @@ jobs: body: | ${{ steps.windows_build.outputs.bin_hash }} + - name: 'Setup MSYS2' + if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'windows-latest' + uses: msys2/setup-msys2@v2 + with: + msystem: ucrt64 + update: true + install: >- + git + perl + make + pacboy: >- + toolchain:p + cmake:p + - name: Windows build desktop id: windows_desktop_build if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'windows-latest' - env: - SIMPLEX_CI_REPO_URL: ${{ secrets.SIMPLEX_CI_REPO_URL }} - shell: bash + shell: msys2 {0} run: | + export PATH=$PATH:/c/ghcup/bin scripts/desktop/build-lib-windows.sh cd apps/multiplatform ./gradlew packageMsi diff --git a/apps/multiplatform/desktop/build.gradle.kts b/apps/multiplatform/desktop/build.gradle.kts index ea808a32d..672b5f871 100644 --- a/apps/multiplatform/desktop/build.gradle.kts +++ b/apps/multiplatform/desktop/build.gradle.kts @@ -141,9 +141,9 @@ cmake { val main by creating { cmakeLists.set(file("$cppPath/desktop/CMakeLists.txt")) targetMachines.addAll(compileMachineTargets.toSet()) - if (machines.host.name.contains("win")) { - cmakeArgs.add("-G MinGW Makefiles") - } + //if (machines.host.name.contains("win")) { + // cmakeArgs.add("-G MinGW Makefiles") + //} } } } diff --git a/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt b/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt index ff92b08ff..787e41fd8 100644 --- a/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt +++ b/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt @@ -35,12 +35,7 @@ private fun initHaskell() { private fun windowsLoadRequiredLibs(libsTmpDir: File, vlcDir: File) { val mainLibs = arrayOf( - "libcrypto-3-x64.dll", - "mcfgthread-12.dll", - "libgcc_s_seh-1.dll", - "libstdc++-6.dll", - "libffi-8.dll", - "libgmp-10.dll", + "libcrypto-1_1-x64.dll", "libsimplex.dll", "libapp-lib.dll" ) diff --git a/scripts/desktop/build-lib-windows.sh b/scripts/desktop/build-lib-windows.sh index ef39ef868..881e0aea2 100755 --- a/scripts/desktop/build-lib-windows.sh +++ b/scripts/desktop/build-lib-windows.sh @@ -8,22 +8,61 @@ function readlink() { root_dir="$(dirname "$(dirname "$(readlink "$0")")")" OS=windows -ARCH="x86_64" -JOB_REPO=${1:-$SIMPLEX_CI_REPO_URL} - +ARCH=${1:-x86_64} if [ "$ARCH" == "aarch64" ]; then COMPOSE_ARCH=arm64 else COMPOSE_ARCH=x64 fi +BUILD_DIR=dist-newstyle/build/$ARCH-$OS/ghc-*/simplex-chat-* + +# IMPORTANT: in order to get a working build you should use x86_64 MinGW with make, cmake, gcc. +# 100% working MinGW is https://github.com/brechtsanders/winlibs_mingw/releases/download/13.1.0-16.0.5-11.0.0-ucrt-r5/winlibs-x86_64-posix-seh-gcc-13.1.0-mingw-w64ucrt-11.0.0-r5.zip +# Many other distributions I tested don't work in some cases or don't have required tools. +# Also, standalone Cmake installed globally via .msi package does not produce working library, you should use MinGW's Cmake. +# Example of export: +# export PATH=/c/MinGW/bin:/c/ghcup/bin:/c/Program\ Files/Amazon\ Corretto/jdk17.0.9_8/bin/:$PATH +# If you use Msys2, use UCRT64 (NOT Mingw64, because it will crash on launch because of non-posix threads), install these packages: +# pacman -S perl make mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-gcc +# and export path to ghcup/bin and java + cd $root_dir +mkdir dist-newstyle 2>/dev/null || true + +if [ ! -f dist-newstyle/openssl-1.1.1w/libcrypto-1_1-x64.dll ]; then + cd dist-newstyle + curl https://www.openssl.org/source/openssl-1.1.1w.tar.gz -o openssl.tar.gz + $WINDIR\\System32\\tar.exe -xvzf openssl.tar.gz + cd openssl-1.1.1w + ./Configure mingw64 + make + cd ../../ +fi +openssl_windows_style_path=$(echo `pwd`/dist-newstyle/openssl-1.1.1w | sed 's#/\([a-z]\)#\1:#' | sed 's#/#\\#g') +rm -rf $BUILD_DIR 2>/dev/null || true +# Existence of this directory produces build error: cabal's bug +rm -rf dist-newstyle/src/direct-sq* 2>/dev/null || true +rm cabal.project.local 2>/dev/null || true +echo "ignore-project: False" >> cabal.project.local +echo "package direct-sqlcipher" >> cabal.project.local +echo " flags: +openssl" >> cabal.project.local +echo " extra-include-dirs: $openssl_windows_style_path\include" >> cabal.project.local +echo " extra-lib-dirs: $openssl_windows_style_path" >> cabal.project.local +echo "package simplex-chat" >> cabal.project.local +echo " ghc-options: -shared -threaded -optl-L$openssl_windows_style_path -optl-lcrypto-1_1-x64 -o libsimplex.dll libsimplex.dll.def" >> cabal.project.local +# Very important! Without it the build fails on linking step since the linker can't find exported symbols. +# It looks like GHC bug because with such random path the build ends successfully +sed -i "s/ld.lld.exe/abracadabra.exe/" `ghc --print-libdir`/settings +cabal build lib:simplex-chat rm -rf apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS-$ARCH/ rm -rf apps/multiplatform/desktop/build/cmake mkdir -p apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS-$ARCH/ -scripts/desktop/download-lib-windows.sh $JOB_REPO +cp dist-newstyle/openssl-1.1.1w/libcrypto-1_1-x64.dll apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS-$ARCH/ +cp libsimplex.dll apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS-$ARCH/ + scripts/desktop/prepare-vlc-windows.sh links_dir=apps/multiplatform/build/links diff --git a/scripts/desktop/download-lib-windows.sh b/scripts/desktop/download-lib-windows.sh deleted file mode 100644 index 7f2e3c387..000000000 --- a/scripts/desktop/download-lib-windows.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -set -e - -function readlink() { - echo "$(cd "$(dirname "$1")"; pwd -P)" -} - -if [ -z "${1}" ]; then - echo "Job repo is unset. Provide it via first argument like: $(readlink "$0")/download-lib-windows.sh https://something.com/job/something/{master,stable}" - exit 1 -fi - -job_repo=$1 -arch=x86_64 -root_dir="$(dirname "$(dirname "$(readlink "$0")")")" -output_dir="$root_dir/apps/multiplatform/common/src/commonMain/cpp/desktop/libs/windows-$arch/" - -mkdir -p "$output_dir" 2> /dev/null - -curl --location -o libsimplex.zip $job_repo/$arch-windows:lib:simplex-chat.$arch-linux/latest/download/1 && \ -$WINDIR\\System32\\tar.exe -xf libsimplex.zip && \ -mv libsimplex.dll "$output_dir" && \ -mv libcrypto*.dll "$output_dir" && \ -mv libffi*.dll "$output_dir" && \ -mv libgmp*.dll "$output_dir" && \ -mv mcfgthread*.dll "$output_dir" && \ -mv libgcc_s_seh*.dll "$output_dir" && \ -mv libstdc++*.dll "$output_dir" && \ -rm libsimplex.zip