diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index 0afd348c..1ba214af 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -246,6 +246,54 @@ jobs: sha: context.sha }) + build-android: + name: Build Android + runs-on: ubuntu-latest + needs: [version] + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: ${{ env.GO_VERSION_FILE }} + check-latest: ${{ env.CHECK_LATEST }} + cache: false + - + 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-android-arm64 + - + name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: binaries + path: build/ + - + name: Remove tag if failure + if: ${{ failure() }} + uses: actions/github-script@v6 + with: + github-token: ${{ github.token }} + script: | + github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "tags/${{ needs.version.outputs.semver_tag }}" + }) + build-linux: name: Build Linux runs-on: ubuntu-latest @@ -266,8 +314,8 @@ jobs: env: VERSION: ${{ needs.version.outputs.semver_tag }} shell: bash - # 3 is the number of virtual cpus for macOS. Linux is only 2. - run: make -j3 build-all-linux + # 2 is the number of virtual cpus for Linux. macOS is 3. + run: make -j2 build-all-linux - name: Upload artifacts uses: actions/upload-artifact@v2 @@ -307,8 +355,8 @@ jobs: env: VERSION: ${{ needs.version.outputs.semver_tag }} shell: bash - # 3 is the number of virtual cpus for macOS. Linux is only 2. - run: make -j3 build-all-freebsd + # 2 is the number of virtual cpus for Linux. macOS is 3. + run: make -j2 build-all-freebsd - name: Upload artifacts uses: actions/upload-artifact@v2 @@ -348,8 +396,8 @@ jobs: env: VERSION: ${{ needs.version.outputs.semver_tag }} shell: bash - # 3 is the number of virtual cpus for macOS. Linux is only 2. - run: make -j3 build-all-netbsd + # 2 is the number of virtual cpus for Linux. macOS is 3. + run: make -j2 build-all-netbsd - name: Upload artifacts uses: actions/upload-artifact@v2 @@ -389,8 +437,8 @@ jobs: env: VERSION: ${{ needs.version.outputs.semver_tag }} shell: bash - # 3 is the number of virtual cpus for macOS. Linux is only 2. - run: make -j3 build-all-openbsd + # 2 is the number of virtual cpus for Linux. macOS is 3. + run: make -j2 build-all-openbsd - name: Upload artifacts uses: actions/upload-artifact@v2 @@ -453,7 +501,7 @@ jobs: build-windows: name: Build Windows - runs-on: ubuntu-latest + runs-on: windows-latest needs: [version] steps: - @@ -471,8 +519,8 @@ jobs: env: VERSION: ${{ needs.version.outputs.semver_tag }} shell: bash - # 3 is the number of virtual cpus for macOS. Linux is only 2. - run: make -j3 build-all-windows + # 2 is the number of virtual cpus for Windows. macOS is 3. + run: make -j2 build-all-windows - name: Upload artifacts uses: actions/upload-artifact@v2 @@ -552,6 +600,7 @@ jobs: runs-on: ubuntu-latest needs: [ version, + build-android, build-linux, build-freebsd, build-netbsd, diff --git a/Makefile b/Makefile index 6f0aacc9..d27bdff3 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -37,89 +38,100 @@ else endif # targets -build-all: build-darwin build-freebsd build-linux build-netbsd build-openbsd build-windows +build-all: build-all-android build-darwin build-freebsd build-linux build-netbsd build-openbsd build-windows + +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 CGO_ENABLED=1 $(MAKE) build + +build-android-arm64: + GOOS=android GOARCH=arm64 $(MAKE) build build-all-darwin: build-darwin-amd64 build-darwin-arm64 build-darwin-amd64: - GOOS=darwin GOARCH=amd64 make build + GOOS=darwin GOARCH=amd64 $(MAKE) build build-darwin-arm64: - GOOS=darwin GOARCH=arm64 make build + GOOS=darwin GOARCH=arm64 $(MAKE) build build-all-freebsd: build-freebsd-386 build-freebsd-amd64 build-freebsd-arm build-freebsd-386: - GOOS=freebsd GOARCH=386 make build + GOOS=freebsd GOARCH=386 $(MAKE) build build-freebsd-amd64: - GOOS=freebsd GOARCH=amd64 make build + GOOS=freebsd GOARCH=amd64 $(MAKE) build build-freebsd-arm: - GOOS=freebsd GOARCH=arm make build + GOOS=freebsd GOARCH=arm $(MAKE) build build-all-linux: build-linux-386 build-linux-amd64 build-linux-arm build-linux-arm64 build-linux-riscv64 build-linux-386: - GOOS=linux GOARCH=386 make build + GOOS=linux GOARCH=386 $(MAKE) build build-linux-amd64: - GOOS=linux GOARCH=amd64 make build + GOOS=linux GOARCH=amd64 $(MAKE) build build-linux-arm: - GOOS=linux GOARCH=arm make build + GOOS=linux GOARCH=arm $(MAKE) build build-linux-arm64: - GOOS=linux GOARCH=arm64 make build + GOOS=linux GOARCH=arm64 $(MAKE) build build-linux-riscv64: - GOOS=linux GOARCH=riscv64 make build + GOOS=linux GOARCH=riscv64 $(MAKE) build build-all-netbsd: build-netbsd-386 build-netbsd-amd64 build-netbsd-arm build-netbsd-386: - GOOS=netbsd GOARCH=386 make build + GOOS=netbsd GOARCH=386 $(MAKE) build build-netbsd-amd64: - GOOS=netbsd GOARCH=amd64 make build + GOOS=netbsd GOARCH=amd64 $(MAKE) build build-netbsd-arm: - GOOS=netbsd GOARCH=arm make build + GOOS=netbsd GOARCH=arm $(MAKE) build build-all-openbsd: build-openbsd-386 build-openbsd-amd64 build-openbsd-arm build-openbsd-arm64 build-openbsd-386: - GOOS=openbsd GOARCH=386 make build + GOOS=openbsd GOARCH=386 $(MAKE) build build-openbsd-amd64: - GOOS=openbsd GOARCH=amd64 make build + GOOS=openbsd GOARCH=amd64 $(MAKE) build build-openbsd-arm: - GOOS=openbsd GOARCH=arm make build + GOOS=openbsd GOARCH=arm $(MAKE) build build-openbsd-arm64: - GOOS=openbsd GOARCH=arm64 make build + GOOS=openbsd GOARCH=arm64 $(MAKE) build build-all-windows: build-windows-386 build-windows-amd64 build-windows-arm64 build-windows-386: - GOOS=windows GOARCH=386 make build-windows + GOOS=windows GOARCH=386 $(MAKE) build-windows build-windows-amd64: - GOOS=windows GOARCH=amd64 make build-windows + GOOS=windows GOARCH=amd64 $(MAKE) build-windows build-windows-arm64: - GOOS=windows GOARCH=arm64 make build-windows + GOOS=windows GOARCH=arm64 $(MAKE) build-windows .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 diff --git a/bin/prepare_assets.sh b/bin/prepare_assets.sh index a2cdf0cb..6efb8378 100755 --- a/bin/prepare_assets.sh +++ b/bin/prepare_assets.sh @@ -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 @@ -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