Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for Android arm using CGO and NDK #949

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,19 @@ jobs:
check-latest: ${{ env.CHECK_LATEST }}
cache: false
-
name: Build binaries
name: Build binary for arm
env:
VERSION: ${{ needs.version.outputs.semver_tag }}
shell: bash
# 2 is the number of virtual cpus for Linux. macOS is 3.
run: make -j2 build-android-arm CC="{{ $ANDROID_NDK_LATEST_HOME }}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang"
-
name: Build binary for arm64
env:
VERSION: ${{ needs.version.outputs.semver_tag }}
shell: bash
# 2 is the number of virtual cpus for Linux. macOS is 3.
run: make -j2 build-all-android
run: make -j2 build-android-arm64
-
name: Upload artifacts
uses: actions/upload-artifact@v2
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# globals
BINARY_NAME?=wakatime-cli
BUILD_DIR?="./build"
CGO_ENABLED?=0
COMMIT?=$(shell git rev-parse --short HEAD)
DATE?=$(shell date -u '+%Y-%m-%dT%H:%M:%S %Z')
REPO=github.com/wakatime/wakatime-cli
Expand Down Expand Up @@ -41,8 +42,11 @@ build-all: build-all-android build-darwin build-freebsd build-linux build-netbsd

build-all-android: build-android-arm build-android-arm64

# to build for android arm, you need to have the android ndk installed, enable CGO and
# set CC to the path of the android ndk toolchain
# example: CC=/path/to/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi34-clang
build-android-arm:
GOOS=android GOARCH=arm make build
GOOS=android GOARCH=arm CGO_ENABLED=1 make build

build-android-arm64:
GOOS=android GOARCH=arm64 make build
Expand Down Expand Up @@ -121,13 +125,13 @@ build-windows-arm64:

.PHONY: build
build:
CGO_ENABLED="0" GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
-ldflags "${LD_FLAGS} -X ${REPO}/pkg/version.OS=$(GOOS) -X ${REPO}/pkg/version.Arch=$(GOARCH)" \
-o ${BUILD_DIR}/$(BINARY_NAME)-$(GOOS)-$(GOARCH)

.PHONY: build-windows
build-windows:
CGO_ENABLED="0" GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
-ldflags "${LD_FLAGS} -X ${REPO}/pkg/version.OS=$(GOOS) -X ${REPO}/pkg/version.Arch=$(GOARCH)" \
-o ${BUILD_DIR}/$(BINARY_NAME)-$(GOOS)-$(GOARCH).exe

Expand Down
4 changes: 4 additions & 0 deletions bin/prepare_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if [ "$(which zip)" = "" ]; then
fi

# add execution permission
chmod 750 ./build/wakatime-cli-android-arm
chmod 750 ./build/wakatime-cli-android-arm64
chmod 750 ./build/wakatime-cli-freebsd-386
chmod 750 ./build/wakatime-cli-freebsd-amd64
chmod 750 ./build/wakatime-cli-freebsd-arm
Expand All @@ -33,6 +35,8 @@ chmod 750 ./build/wakatime-cli-windows-amd64.exe
chmod 750 ./build/wakatime-cli-windows-arm64.exe

# create archives
zip -j ./release/wakatime-cli-android-arm.zip ./build/wakatime-cli-android-arm
zip -j ./release/wakatime-cli-android-arm64.zip ./build/wakatime-cli-android-arm64
zip -j ./release/wakatime-cli-freebsd-386.zip ./build/wakatime-cli-freebsd-386
zip -j ./release/wakatime-cli-freebsd-amd64.zip ./build/wakatime-cli-freebsd-amd64
zip -j ./release/wakatime-cli-freebsd-arm.zip ./build/wakatime-cli-freebsd-arm
Expand Down
Loading