TUN-8520: add macos arm64 build

- refactor build script for macos to include arm64 build
- refactor Makefile to upload all the artifacts instead of issuing one by one
- update cfsetup due to 2.
- place build files in specific folders
- cleanup build directory before/after creating build artifacts
This commit is contained in:
lneto 2024-07-05 19:39:22 +01:00
parent 75752b681b
commit c95959e845
2 changed files with 48 additions and 40 deletions

View File

@ -12,8 +12,6 @@ export GO111MODULE=on
# build 'cloudflared-darwin-amd64.tgz' # build 'cloudflared-darwin-amd64.tgz'
mkdir -p artifacts mkdir -p artifacts
FILENAME="$(pwd)/artifacts/cloudflared-darwin-amd64.tgz"
PKGNAME="$(pwd)/artifacts/cloudflared-amd64.pkg"
TARGET_DIRECTORY=".build" TARGET_DIRECTORY=".build"
BINARY_NAME="cloudflared" BINARY_NAME="cloudflared"
VERSION=$(git describe --tags --always --dirty="-dev") VERSION=$(git describe --tags --always --dirty="-dev")
@ -28,7 +26,6 @@ export PATH="$PATH:/usr/local/bin"
mkdir -p ../src/github.com/cloudflare/ mkdir -p ../src/github.com/cloudflare/
cp -r . ../src/github.com/cloudflare/cloudflared cp -r . ../src/github.com/cloudflare/cloudflared
cd ../src/github.com/cloudflare/cloudflared cd ../src/github.com/cloudflare/cloudflared
GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
# Add code signing private key to the key chain # Add code signing private key to the key chain
if [[ ! -z "$CFD_CODE_SIGN_KEY" ]]; then if [[ ! -z "$CFD_CODE_SIGN_KEY" ]]; then
@ -138,6 +135,16 @@ else
fi fi
fi fi
# cleanup the build directory because the previous execution might have failed without cleaning up.
rm -rf "${TARGET_DIRECTORY}"
archs=("amd64" "arm64")
export TARGET_OS=darwin
for arch in ${archs[@]}; do
FILENAME="$(pwd)/artifacts/cloudflared-darwin-$arch.tgz"
PKGNAME="$(pwd)/artifacts/cloudflared-$arch.pkg"
TARGET_ARCH=$arch GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
# sign the cloudflared binary # sign the cloudflared binary
if [[ ! -z "$CODE_SIGN_NAME" ]]; then if [[ ! -z "$CODE_SIGN_NAME" ]]; then
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME} codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
@ -146,14 +153,15 @@ if [[ ! -z "$CODE_SIGN_NAME" ]]; then
# TODO: TUN-5789 # TODO: TUN-5789
fi fi
ARCH_TARGET_DIRECTORY="${TARGET_DIRECTORY}/${arch}-build"
# creating build directory # creating build directory
rm -rf $TARGET_DIRECTORY rm -rf $ARCH_TARGET_DIRECTORY
mkdir "${TARGET_DIRECTORY}" mkdir "${ARCH_TARGET_DIRECTORY}"
mkdir "${TARGET_DIRECTORY}/contents" mkdir "${ARCH_TARGET_DIRECTORY}/contents"
cp -r ".mac_resources/scripts" "${TARGET_DIRECTORY}/scripts" cp -r ".mac_resources/scripts" "${ARCH_TARGET_DIRECTORY}/scripts"
# copy cloudflared into the build directory # copy cloudflared into the build directory
cp ${BINARY_NAME} "${TARGET_DIRECTORY}/contents/${PRODUCT}" cp ${BINARY_NAME} "${ARCH_TARGET_DIRECTORY}/contents/${PRODUCT}"
# compress cloudflared into a tar and gzipped file # compress cloudflared into a tar and gzipped file
tar czf "$FILENAME" "${BINARY_NAME}" tar czf "$FILENAME" "${BINARY_NAME}"
@ -162,8 +170,8 @@ tar czf "$FILENAME" "${BINARY_NAME}"
if [[ ! -z "$PKG_SIGN_NAME" ]]; then if [[ ! -z "$PKG_SIGN_NAME" ]]; then
pkgbuild --identifier com.cloudflare.${PRODUCT} \ pkgbuild --identifier com.cloudflare.${PRODUCT} \
--version ${VERSION} \ --version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/scripts \ --scripts ${ARCH_TARGET_DIRECTORY}/scripts \
--root ${TARGET_DIRECTORY}/contents \ --root ${ARCH_TARGET_DIRECTORY}/contents \
--install-location /usr/local/bin \ --install-location /usr/local/bin \
--sign "${PKG_SIGN_NAME}" \ --sign "${PKG_SIGN_NAME}" \
${PKGNAME} ${PKGNAME}
@ -173,12 +181,13 @@ if [[ ! -z "$PKG_SIGN_NAME" ]]; then
else else
pkgbuild --identifier com.cloudflare.${PRODUCT} \ pkgbuild --identifier com.cloudflare.${PRODUCT} \
--version ${VERSION} \ --version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/scripts \ --scripts ${ARCH_TARGET_DIRECTORY}/scripts \
--root ${TARGET_DIRECTORY}/contents \ --root ${ARCH_TARGET_DIRECTORY}/contents \
--install-location /usr/local/bin \ --install-location /usr/local/bin \
${PKGNAME} ${PKGNAME}
fi fi
done
# cleanup build the build directory because this script is not ran within containers,
# cleaning up the build directory # which might lead to future issues in subsequent runs.
rm -rf $TARGET_DIRECTORY rm -rf "${TARGET_DIRECTORY}"

View File

@ -241,8 +241,7 @@ github-message:
.PHONY: github-mac-upload .PHONY: github-mac-upload
github-mac-upload: github-mac-upload:
python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz python3 github_release.py --path artifacts --release-version $(VERSION)
python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
.PHONY: github-windows-upload .PHONY: github-windows-upload
github-windows-upload: github-windows-upload: