From fd673c6a433f03e495ec9b9a0a67a841e5f13c05 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef Date: Wed, 21 Feb 2024 09:07:00 -0600 Subject: [PATCH] add windows cross-build tool chain --- .github/workflows/build-release.yaml | 2 +- Makefile | 4 ++-- pre_build.sh | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml index 5093372c0..ca7740a72 100644 --- a/.github/workflows/build-release.yaml +++ b/.github/workflows/build-release.yaml @@ -11,7 +11,7 @@ jobs: strategy: matrix: # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 - goos: [ linux, windows ] + goos: [ windows ] goarch: [ amd64, arm64 ] exclude: - goarch: arm64 diff --git a/Makefile b/Makefile index 431837219..2f8d2e26a 100644 --- a/Makefile +++ b/Makefile @@ -107,9 +107,9 @@ generate: install-tools .PHONY: install-cross-build-tools install-cross-build-tools: if [ "$(UNAME)" = "Debian" ] ; then \ - apt-get update && apt-get -y install apt-utils gcc-aarch64-linux-gnu ; \ + apt-get update && apt-get -y install apt-utils gcc-aarch64-linux-gnu gcc-mingw-w64-x86-64 ; \ elif [ "$(UNAME)" = "Linux" ] ; then \ - apt-get update && apt-get -y install apt-utils gcc-aarch64-linux-gnu ; \ + apt-get update && apt-get -y install apt-utils gcc-aarch64-linux-gnu gcc-mingw-w64-x86-64 ; \ else \ echo "this target only works on Debian or Linux, host runs on" $(UNAME) ; \ fi diff --git a/pre_build.sh b/pre_build.sh index 8f8685ba2..9ee1113fc 100644 --- a/pre_build.sh +++ b/pre_build.sh @@ -3,17 +3,34 @@ # Exit as soon as any command fails set -e -# INPUT_GOARCH is a variable set by the wangyoucao577 action +# INPUT_GOARCH and INPUT_GOOS are set by the wangyoucao577 action: # https://github.com/wangyoucao577/go-release-action/blob/v1.40/action.yml#L109 +# it represents the target arch and target os + +export GOOS=${INPUT_GOOS} +export GOARCH=${INPUT_GOARCH} + C_COMP="" -if [ "${INPUT_GOARCH}" = "arm64" ]; then - C_COMP="aarch64-linux-gnu-gcc" -elif [ "${INPUT_GOARCH}" = "amd64" ]; then - C_COMP="x86_64-linux-gnu-gcc" +if [ "${GOOS}" = "linux" ]; then + if [ "${GOARCH}" = "arm64" ]; then + C_COMP="aarch64-linux-gnu-gcc" + elif [ "${GOARCH}" = "amd64" ]; then + C_COMP="x86_64-linux-gnu-gcc" + fi +elif [ "${GOOS}" = "windows" ]; then + if [ "${GOARCH}" = "amd64" ]; then + C_COMP="gcc-mingw-w64-x86-64" + else + { echo "arm64 on windows isn't supported"; exit 1; } + fi fi + export GO111MODULE=on +# enable CGO because it is requiired by the onflow/crypto package export CGO_ENABLED=1 +# set the correct C compiler export CC=${C_COMP} +# this flag disables non-portable code that requires specific CPU features. export CGO_FLAGS=\""-O2 -D__BLST_PORTABLE__"\"