From 569f2eb3fa4deb68fd6f3000bd0f2a638c17e8c1 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 12:53:48 +0200 Subject: [PATCH 01/11] Change build-macos script to support cross-compiling for arm64 --- script/build-macos.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/script/build-macos.sh b/script/build-macos.sh index f8da069b..ee3f387e 100755 --- a/script/build-macos.sh +++ b/script/build-macos.sh @@ -7,6 +7,16 @@ set -eu -o pipefail MACOSX_BUILD_VERSION="10.9" +if [ "$TARGET_ARCH" = "64" ]; then + HOST_CPU=x86_64 + TARGET_CFLAGS="-target x86_64-apple-darwin" + GOARCH=amd64 +else + HOST_CPU=arm64 + TARGET_CFLAGS="-target arm64-apple-darwin" + GOARCH=arm64 +fi + if [[ -z "${SOURCE}" ]]; then echo "Required environment variable SOURCE was not set" exit 1 @@ -43,7 +53,13 @@ echo "-- Building git at $SOURCE to $DESTINATION" # Reason: image not found # # For this reason we set CURL_CONFIG to the system version explicitly here. + # + # HACK: There is no way of adding additional CFLAGS without running the + # configure script. However the Makefile prepends some developer CFLAGS that + # we could use to select the right target CPU to cross-compile git. DESTDIR="$DESTINATION" make strip install prefix=/ \ + DEVELOPER_CFLAGS="$TARGET_CFLAGS" \ + HOST_CPU="$HOST_CPU" \ CURL_CONFIG=/usr/bin/curl-config \ NO_PERL=1 \ NO_TCLTK=1 \ @@ -60,7 +76,7 @@ if [[ "$GIT_LFS_VERSION" ]]; then git clone -b "v$GIT_LFS_VERSION" "https://github.com/git-lfs/git-lfs" ( cd git-lfs - make CGO_CFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" CGO_LDFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" BUILTIN_LD_FLAGS="-linkmode external" + make GOARCH="$GOARCH" CGO_CFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" CGO_LDFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" BUILTIN_LD_FLAGS="-linkmode external" ) GIT_LFS_BINARY_PATH="git-lfs/bin/git-lfs" if test -f "$GIT_LFS_BINARY_PATH"; then From a5cea25a9e20e948dd4e7dbbfc1b39b823d42024 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 12:54:21 +0200 Subject: [PATCH 02/11] Change CI workflow to generate arm64 builds --- .github/workflows/ci.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac9cc99e..3e5dae99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,10 @@ jobs: - os: macos-10.15 friendlyName: macOS targetPlatform: macOS + - os: macos-10.15 + friendlyName: macOS + targetPlatform: macOS + arch: arm64 - os: windows-2019 friendlyName: Windows targetPlatform: win32 @@ -44,9 +48,9 @@ jobs: arch: 32 timeout-minutes: 20 steps: - # We need to use Xcode 10.3 for maximum compatibility with older macOS + # We need to use Xcode 10.3 for maximum compatibility with older macOS (x64) - name: Switch to Xcode 10.3 - if: matrix.targetPlatform == 'macOS' + if: matrix.targetPlatform == 'macOS' && matrix.arch == 64 run: | sudo xcode-select -s /Applications/Xcode_10.3.app/Contents/Developer/ # Delete the command line tools to make sure they don't get our builds @@ -66,12 +70,22 @@ jobs: - name: Install extra dependencies for building Git on Ubuntu if: matrix.targetPlatform == 'ubuntu' run: sudo apt-get install libcurl4-openssl-dev libexpat1-dev gettext - - name: Build + - name: Build (except macOS arm64) + if: matrix.targetPlatform != 'macOS' || matrix.arch != arm64 + shell: bash + run: script/build.sh + env: + TARGET_PLATFORM: ${{ matrix.targetPlatform }} + TARGET_ARCH: ${{ matrix.arch }} + - name: Build (macOS arm64) + if: matrix.targetPlatform == 'macOS' && matrix.arch == arm64 shell: bash run: script/build.sh env: TARGET_PLATFORM: ${{ matrix.targetPlatform }} TARGET_ARCH: ${{ matrix.arch }} + # Needed for macOS arm64 until hosted macos-11.0 runners become available + SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk - name: Package shell: bash run: script/package.sh From a8f7eb86ae9b36bf79fd43613e86ca66001ac940 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 12:57:34 +0200 Subject: [PATCH 03/11] Make sure packaged macOS build include the architecture --- script/package.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script/package.sh b/script/package.sh index 236db9c9..f37f9bb0 100755 --- a/script/package.sh +++ b/script/package.sh @@ -37,8 +37,9 @@ if [ "$TARGET_PLATFORM" == "ubuntu" ]; then GZIP_FILE="dugite-native-$VERSION-$BUILD_HASH-ubuntu.tar.gz" LZMA_FILE="dugite-native-$VERSION-$BUILD_HASH-ubuntu.lzma" elif [ "$TARGET_PLATFORM" == "macOS" ]; then - GZIP_FILE="dugite-native-$VERSION-$BUILD_HASH-macOS.tar.gz" - LZMA_FILE="dugite-native-$VERSION-$BUILD_HASH-macOS.lzma" + if [ "$TARGET_ARCH" -eq "64" ]; then ARCH="x64"; else ARCH="arm64"; fi + GZIP_FILE="dugite-native-$VERSION-$BUILD_HASH-macOS-$ARCH.tar.gz" + LZMA_FILE="dugite-native-$VERSION-$BUILD_HASH-macOS-$ARCH.lzma" elif [ "$TARGET_PLATFORM" == "win32" ]; then if [ "$TARGET_ARCH" -eq "64" ]; then ARCH="x64"; else ARCH="x86"; fi GZIP_FILE="dugite-native-$VERSION-$BUILD_HASH-windows-$ARCH.tar.gz" From 70dc204a484f721aa9d12cc877fb0e02213e9ff7 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 12:58:59 +0200 Subject: [PATCH 04/11] Quotes are important --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e5dae99..b475b925 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,14 +71,14 @@ jobs: if: matrix.targetPlatform == 'ubuntu' run: sudo apt-get install libcurl4-openssl-dev libexpat1-dev gettext - name: Build (except macOS arm64) - if: matrix.targetPlatform != 'macOS' || matrix.arch != arm64 + if: matrix.targetPlatform != 'macOS' || matrix.arch != 'arm64' shell: bash run: script/build.sh env: TARGET_PLATFORM: ${{ matrix.targetPlatform }} TARGET_ARCH: ${{ matrix.arch }} - name: Build (macOS arm64) - if: matrix.targetPlatform == 'macOS' && matrix.arch == arm64 + if: matrix.targetPlatform == 'macOS' && matrix.arch == 'arm64' shell: bash run: script/build.sh env: From f8d6252e02a65f046d165484f45bdb3146620a40 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 13:46:31 +0200 Subject: [PATCH 05/11] Run go generate using the host CPU --- script/build-macos.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/build-macos.sh b/script/build-macos.sh index ee3f387e..92c68c55 100755 --- a/script/build-macos.sh +++ b/script/build-macos.sh @@ -76,6 +76,8 @@ if [[ "$GIT_LFS_VERSION" ]]; then git clone -b "v$GIT_LFS_VERSION" "https://github.com/git-lfs/git-lfs" ( cd git-lfs + GO_GENERATE_STRING='$(GO) generate github.com\/git-lfs\/git-lfs\/commands' + sed -i -e "s/$GO_GENERATE_STRING/GOARCH= $GO_GENERATE_STRING/" Makefile make GOARCH="$GOARCH" CGO_CFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" CGO_LDFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" BUILTIN_LD_FLAGS="-linkmode external" ) GIT_LFS_BINARY_PATH="git-lfs/bin/git-lfs" From b2dc85a3a379e527e7d4255f6783088a8b5fc756 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 13:01:32 +0200 Subject: [PATCH 06/11] Remove smimesign dependency It seems we didn't even use it --- dependencies.json | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/dependencies.json b/dependencies.json index 8f224b9e..ced86551 100644 --- a/dependencies.json +++ b/dependencies.json @@ -40,28 +40,5 @@ "checksum": "0e13b411ca6c2b2cfb3d82b67ae747ca5d055734d0ab2030d0823fc37ad48902" } ] - }, - "smimesign": { - "version": "0.0.6", - "files": [ - { - "platform": "darwin", - "arch": "amd64", - "name": "smimesign-0.0.6-macos.tgz", - "checksum": "771790f685176b132cb287302a9374120184f7f7973038a0232efee145781906" - }, - { - "platform": "windows", - "arch": "amd64", - "name": "smimesign-windows-amd64-0.0.6.zip", - "checksum": "2a2f946e31f2d74eadcdcd97b7bfc69298cee2f11cf7cb03c604d28fa1b34cd3" - }, - { - "platform": "windows", - "arch": "x86", - "name": "smimesign-windows-386-0.0.6.zip", - "checksum": "9a13d00aa02c0a5d277c030297d09f10a467f31e6740f1520a08e09a23046323" - } - ] } } From 6c61414c0f1838a1a0cf601830dc04433fbe60ac Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 13:59:18 +0200 Subject: [PATCH 07/11] Use newer version of go --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b475b925..945e4130 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: matrix: os: [macos-10.15, windows-2019, ubuntu-18.04] arch: [32, 64] + go: [1.16.3] include: - os: macos-10.15 friendlyName: macOS @@ -61,6 +62,10 @@ jobs: submodules: recursive # Needed for script/package.sh to work fetch-depth: 0 + - name: Use go ${{ matrix.go }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} - name: Install dependencies run: npm install - name: Check formatting From abdb993f7497e5a7a474c4416a1cb0934f9ba7dc Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 14:00:18 +0200 Subject: [PATCH 08/11] Make Shellcheck happy --- script/build-macos.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/build-macos.sh b/script/build-macos.sh index 92c68c55..c2520ac3 100755 --- a/script/build-macos.sh +++ b/script/build-macos.sh @@ -76,7 +76,7 @@ if [[ "$GIT_LFS_VERSION" ]]; then git clone -b "v$GIT_LFS_VERSION" "https://github.com/git-lfs/git-lfs" ( cd git-lfs - GO_GENERATE_STRING='$(GO) generate github.com\/git-lfs\/git-lfs\/commands' + GO_GENERATE_STRING="\$(GO) generate github.com\/git-lfs\/git-lfs\/commands" sed -i -e "s/$GO_GENERATE_STRING/GOARCH= $GO_GENERATE_STRING/" Makefile make GOARCH="$GOARCH" CGO_CFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" CGO_LDFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" BUILTIN_LD_FLAGS="-linkmode external" ) From 57ca6ecc4a0b62252f6b8accab176619e297d921 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 14:04:17 +0200 Subject: [PATCH 09/11] Fix go version for arm64 build --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 945e4130..c77d7903 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: friendlyName: macOS targetPlatform: macOS arch: arm64 + go: 1.16.3 - os: windows-2019 friendlyName: Windows targetPlatform: win32 From aef538afb27edc455fa9d0238ecd364ef09a3487 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 15:20:28 +0200 Subject: [PATCH 10/11] Fix release script updating the count of artifacts --- script/generate-release-notes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/generate-release-notes.ts b/script/generate-release-notes.ts index c2f54adb..37c87b6a 100644 --- a/script/generate-release-notes.ts +++ b/script/generate-release-notes.ts @@ -7,7 +7,7 @@ export default class GenerateReleaseNotes { // five targeted OS/arch combinations // two files for each targeted OS/arch // two checksum files for the previous - private SUCCESSFUL_RELEASE_FILE_COUNT = 4 * 2 * 2 + private SUCCESSFUL_RELEASE_FILE_COUNT = 5 * 2 * 2 private args = process.argv.slice(2) private expectedArgs = [ { From 3d467be52e30aa1eca4191fad9367510da819cb0 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 28 Apr 2021 15:50:25 +0200 Subject: [PATCH 11/11] Add comment to clarify git-lfs build hack --- script/build-macos.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/script/build-macos.sh b/script/build-macos.sh index c2520ac3..d2b99202 100755 --- a/script/build-macos.sh +++ b/script/build-macos.sh @@ -76,8 +76,15 @@ if [[ "$GIT_LFS_VERSION" ]]; then git clone -b "v$GIT_LFS_VERSION" "https://github.com/git-lfs/git-lfs" ( cd git-lfs + + # HACK: When cross-compiling, there seems to be an issue when git-lfs attempts + # to generate the manpage contents, and it seems that preffixing that command + # with `GOARCH=` to use the host architecture fixes the issue. + # This hack can be removed once the issue is fixed via the PR + # https://github.com/git-lfs/git-lfs/pull/4492 or some other solution. GO_GENERATE_STRING="\$(GO) generate github.com\/git-lfs\/git-lfs\/commands" sed -i -e "s/$GO_GENERATE_STRING/GOARCH= $GO_GENERATE_STRING/" Makefile + make GOARCH="$GOARCH" CGO_CFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" CGO_LDFLAGS="-mmacosx-version-min=$MACOSX_BUILD_VERSION" BUILTIN_LD_FLAGS="-linkmode external" ) GIT_LFS_BINARY_PATH="git-lfs/bin/git-lfs"