From b775d28c237597a3013e68c09442c9e87b18c565 Mon Sep 17 00:00:00 2001 From: 5ec1cff <56485584+5ec1cff@users.noreply.github.com> Date: Thu, 16 Mar 2023 17:26:29 +0800 Subject: [PATCH] Add CI (#14) * CI Signed-off-by: 5ec1cff * Update gradle.properties * add rustup targets (#1) * Update ci.yml * Update ci.yml * Update ci.yml * Use ccache and rust-cache Signed-off-by: 5ec1cff --------- Signed-off-by: 5ec1cff Co-authored-by: Mufanc <47652878+Mufanc@users.noreply.github.com> --- .github/workflows/ci.yml | 88 ++++++++++++++++++++++++++++ gradle.properties | 2 +- loader/build.gradle.kts | 29 +++++++++ loader/src/external/Android.mk | 1 + loader/src/external/parallel-hashmap | 2 +- 5 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8832f99 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,88 @@ +name: CI + +on: + workflow_dispatch: + push: + branches: [ master ] + tags: [ v* ] + pull_request: + merge_group: + +jobs: + build: + runs-on: ubuntu-latest + env: + CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion" + CCACHE_NOHASHDIR: "true" + CCACHE_HARDLINK: "true" + CCACHE_BASEDIR: "${{ github.workspace }}" + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "recursive" + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: "17" + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: zygiskd/src -> ../build/intermediates/rust + cache-targets: false + + - name: Setup Rust + run: | + rustup target add armv7-linux-androideabi + rustup target add aarch64-linux-android + rustup target add x86_64-linux-android + rustup target add i686-linux-android + + - name: Set up ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + max-size: 2G + key: ${{ runner.os }} + restore-keys: ${{ runner.os }} + save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + + - name: Build with Gradle + run: | + echo 'org.gradle.parallel=true' >> gradle.properties + echo 'org.gradle.vfs.watch=true' >> gradle.properties + echo 'org.gradle.jvmargs=-Xmx2048m' >> gradle.properties + echo 'android.native.buildOutput=verbose' >> gradle.properties + sed -i 's/org.gradle.unsafe.configuration-cache=true//g' gradle.properties + ./gradlew zipRelease + ./gradlew zipDebug + + - name: Prepare artifact + if: success() + id: prepareArtifact + run: | + releaseName=`ls module/build/outputs/release/Zygisk-on-KernelSU-v*-release.zip | awk -F '(/|.zip)' '{print $5}'` && echo "releaseName=$releaseName" >> $GITHUB_OUTPUT + debugName=`ls module/build/outputs/release/Zygisk-on-KernelSU-v*-debug.zip | awk -F '(/|.zip)' '{print $5}'` && echo "debugName=$debugName" >> $GITHUB_OUTPUT + unzip module/build/outputs/release/Zygisk-on-KernelSU-v*-release.zip -d zksu-release + unzip module/build/outputs/release/Zygisk-on-KernelSU-v*-debug.zip -d zksu-debug + + - name: Upload release + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.prepareArtifact.outputs.releaseName }} + path: "./zksu-release/*" + + - name: Upload debug + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.prepareArtifact.outputs.debugName }} + path: "./zksu-debug/*" diff --git a/gradle.properties b/gradle.properties index 3c5031e..2cbd6d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,4 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true diff --git a/loader/build.gradle.kts b/loader/build.gradle.kts index 39d6b0b..3f3d973 100644 --- a/loader/build.gradle.kts +++ b/loader/build.gradle.kts @@ -1,7 +1,26 @@ +import java.nio.file.Paths +import org.gradle.internal.os.OperatingSystem + plugins { id("com.android.library") } +fun Project.findInPath(executable: String, property: String): String? { + val pathEnv = System.getenv("PATH") + return pathEnv.split(File.pathSeparator).map { folder -> + Paths.get("${folder}${File.separator}${executable}${if (OperatingSystem.current().isWindows) ".exe" else ""}") + .toFile() + }.firstOrNull { path -> + path.exists() + }?.absolutePath ?: properties.getOrDefault(property, null) as? String? +} + +val ccachePatch by lazy { + project.findInPath("ccache", "ccache.path")?.also { + println("loader: Use ccache: $it") + } +} + android { buildFeatures { androidResources = false @@ -12,6 +31,16 @@ android { externalNativeBuild.ndkBuild { path("src/Android.mk") } + + defaultConfig { + externalNativeBuild { + ndkBuild { + ccachePatch?.let { + arguments += "NDK_CCACHE=$it" + } + } + } + } } dependencies { diff --git a/loader/src/external/Android.mk b/loader/src/external/Android.mk index b149c04..43e76d1 100644 --- a/loader/src/external/Android.mk +++ b/loader/src/external/Android.mk @@ -16,5 +16,6 @@ include $(BUILD_STATIC_LIBRARY) # Header only library include $(CLEAR_VARS) LOCAL_MODULE:= libphmap +LOCAL_CFLAGS := -Wno-unused-value LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/parallel-hashmap include $(BUILD_STATIC_LIBRARY) diff --git a/loader/src/external/parallel-hashmap b/loader/src/external/parallel-hashmap index 87ece91..55725db 160000 --- a/loader/src/external/parallel-hashmap +++ b/loader/src/external/parallel-hashmap @@ -1 +1 @@ -Subproject commit 87ece91c6e4c457c5faac179dae6e11e2cd39b16 +Subproject commit 55725dbe7047d54e3cbeccf7c4fb27f6603e0f2e