Skip to content

Commit

Permalink
feat: build Mieru plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dyhkwong authored and xchacha20-poly1305 committed Jul 11, 2024
1 parent 91dcef4 commit f4cf6c2
Show file tree
Hide file tree
Showing 35 changed files with 379 additions and 2 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/release_mieru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Mieru Plugin Build
on:
workflow_dispatch:
inputs:
tag:
description: "Release Tag"
required: true
publish:
description: "Publish: If want ignore"
required: false
jobs:
native:
name: Native Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Fetch Status
run: git submodule status 'plugin/mieru/*' > mieru_status
- name: Mieru Cache
id: cache
uses: actions/cache@v4
with:
path: |
plugin/mieru/src/main/jniLibs
key: ${{ hashFiles('.github/workflows/*', 'bin/lib/mieru/*', 'mieru_status') }}
- name: Gradle cache
uses: actions/cache@v4
with:
path: ~/.gradle
key: gradle-${{ hashFiles('**/*.gradle.kts') }}
- name: Golang Version
if: steps.cache.outputs.cache-hit != 'true'
id: version
run: |
source buildScript/init/version.sh
echo go_version=$GO_VERSION >> $GITHUB_OUTPUT
- name: Install Golang
uses: actions/setup-go@v5
if: steps.cache.outputs.cache-hit != 'true'
with:
go-version: ${{ steps.version.outputs.go_version }}
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: ./run plugin mieru
build:
name: Gradle Build
runs-on: ubuntu-latest
needs:
- native
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Fetch Status
run: git submodule status 'plugin/mieru/*' > mieru_status
- name: Mieru Cache
uses: actions/cache@v4
with:
path: |
plugin/mieru/src/main/jniLibs
key: ${{ hashFiles('.github/workflows/*', 'bin/lib/mieru/*', 'mieru_status') }}
- name: Gradle cache
uses: actions/cache@v4
with:
path: ~/.gradle
key: gradle-${{ hashFiles('**/*.gradle.kts') }}
- uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
- name: Release Build
env:
SKIP_BUILD: on
BUILD_PLUGIN: mieru
run: |
echo "sdk.dir=${ANDROID_HOME}" > local.properties
# export LOCAL_PROPERTIES="${{ secrets.LOCAL_PROPERTIES }}"
KEYSTORE_PASS="${{ secrets.KEYSTORE_PASS }}" ALIAS_NAME="${{ secrets.ALIAS_NAME }}" ALIAS_PASS="${{ secrets.ALIAS_PASS}}" ./gradlew :plugin:mieru:assembleFossRelease
APK=$(find plugin/mieru/build/outputs/apk -name '*arm64-v8a*.apk')
APK=$(dirname "$APK")
echo "APK=$APK" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: APKs
path: ${{ env.APK }}
publish:
name: Publish Release
if: github.event.inputs.publish != 'y'
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Donwload Artifacts
uses: actions/download-artifact@v4
with:
name: APKs
path: artifacts
- name: Release
run: |
wget -O ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.16.2/ghr_v0.16.2_linux_amd64.tar.gz
tar -xvf ghr.tar.gz
mv ghr*linux_amd64/ghr .
mkdir apks
find artifacts -name "*.apk" -exec cp {} apks \;
find artifacts -name "*.sha256sum.txt" -exec cp {} apks \;
./ghr -delete -prerelease -t "${{ github.token }}" -n "${{ github.event.inputs.tag }}" "${{ github.event.inputs.tag }}" apks
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "plugin/naive/src/main/jni/naiveproxy"]
path = plugin/naive/src/main/jni/naiveproxy
url = https://github.com/klzgrad/naiveproxy.git
[submodule "plugin/mieru/src/main/go/mieru"]
path = plugin/mieru/src/main/go/mieru
url = https://github.com/enfein/mieru.git
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Plugin name list:
* `hysteria2`
* `juicity`
* `naive`
* `mieru`

## ☠️ End users

Expand Down
7 changes: 7 additions & 0 deletions buildScript/plugin/mieru.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

buildScript/plugin/mieru/init.sh && set -x &&
buildScript/plugin/mieru/armeabi-v7a.sh &&
buildScript/plugin/mieru/arm64-v8a.sh &&
buildScript/plugin/mieru/x86.sh &&
buildScript/plugin/mieru/x86_64.sh
8 changes: 8 additions & 0 deletions buildScript/plugin/mieru/arm64-v8a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source "buildScript/init/env.sh"
source "buildScript/plugin/mieru/build.sh"

DIR="$ROOT/arm64-v8a"
mkdir -p $DIR
env CC="$ANDROID_ARM64_CC" GOARCH="arm64" go build -v -o $DIR/$LIB_OUTPUT -buildvcs=false -trimpath -ldflags "-s -w -buildid=" ./cmd/mieru
10 changes: 10 additions & 0 deletions buildScript/plugin/mieru/armeabi-v7a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# set -x

source "buildScript/init/env.sh"
source "buildScript/plugin/mieru/build.sh"

DIR="$ROOT/armeabi-v7a"
mkdir -p $DIR
env CC="$ANDROID_ARM_CC" GOARCH=arm GOARM=7 go build -v -o $DIR/$LIB_OUTPUT -buildvcs=false -trimpath -ldflags "-s -w -buildid=" ./cmd/mieru
17 changes: 17 additions & 0 deletions buildScript/plugin/mieru/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

#set -x

source "buildScript/init/env.sh"

export CGO_ENABLED=1
export GOOS=android

CURR="plugin/mieru"
CURR_PATH="$SRC_ROOT/$CURR"

ROOT="$CURR_PATH/src/main/jniLibs"
OUTPUT="mieru"
LIB_OUTPUT="lib$OUTPUT.so"

cd $CURR_PATH/src/main/go/mieru
13 changes: 13 additions & 0 deletions buildScript/plugin/mieru/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

source "buildScript/init/env.sh"

export CGO_ENABLED=1
export GOOS=android

CURR="plugin/mieru"
CURR_PATH="$SRC_ROOT/$CURR"

#git submodule update --init "$CURR/*"
cd $CURR_PATH/src/main/go/mieru
go mod download -x
8 changes: 8 additions & 0 deletions buildScript/plugin/mieru/x86.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source "buildScript/init/env.sh"
source "buildScript/plugin/mieru/build.sh"

DIR="$ROOT/x86"
mkdir -p $DIR
env CC="$ANDROID_X86_CC" GOARCH=386 go build -v -o $DIR/$LIB_OUTPUT -buildvcs=false -trimpath -ldflags "-s -w -buildid=" ./cmd/mieru
8 changes: 8 additions & 0 deletions buildScript/plugin/mieru/x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source "buildScript/init/env.sh"
source "buildScript/plugin/mieru/build.sh"

DIR="$ROOT/x86_64"
mkdir -p $DIR
env CC="$ANDROID_X86_64_CC" GOARCH=amd64 go build -v -o $DIR/$LIB_OUTPUT -buildvcs=false -trimpath -ldflags "-s -w -buildid=" ./cmd/mieru
7 changes: 5 additions & 2 deletions husi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ HYSTERIA2_VERSION=8
JUICITY_VERSION_NAME=0.4.3-1
JUICITY_VERSION=2

NAIVE_VERSION_NAME=v126.0.6478.40-1
NAIVE_VERSION=1
NAIVE_VERSION_NAME=126.0.6478.40-1
NAIVE_VERSION=2

MIERU_VERSION_NAME=3.2.1
MIERU_VERSION=1
12 changes: 12 additions & 0 deletions plugin/mieru/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("com.android.application")
}

android {
defaultConfig {
applicationId = "fr.husi.plugin.mieru"
}
namespace = "fr.husi.plugin.mieru"
}

setupPlugin("mieru")
45 changes: 45 additions & 0 deletions plugin/mieru/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="internalOnly"
tools:ignore="MissingLeanbackLauncher">

<uses-feature
android:name="android.software.leanback"
android:required="false"/>
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false"/>

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="Mieru Plugin"
android:roundIcon="@mipmap/ic_launcher_round">
<provider
android:name="fr.husi.plugin.mieru.BinaryProvider"
android:authorities="fr.husi.plugin.mieru.BinaryProvider"
android:directBootAware="true"
android:exported="true"
tools:ignore="ExportedContentProvider">
<intent-filter>
<action android:name="io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN"/>
</intent-filter>
<intent-filter>
<action android:name="io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN"/>
<data
android:host="fr.husi"
android:path="/mieru-plugin"
android:scheme="plugin"/>
</intent-filter>

<meta-data
android:name="io.nekohasekai.sagernet.plugin.id"
android:value="mieru-plugin"/>
<meta-data
android:name="io.nekohasekai.sagernet.plugin.executable_path"
android:value="libmieru.so"/>
</provider>
</application>

</manifest>
1 change: 1 addition & 0 deletions plugin/mieru/src/main/go/mieru
Submodule mieru added at e080a7
Binary file added plugin/mieru/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions plugin/mieru/src/main/java/fr/husi/plugin/mieru/BinaryProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* *
* Copyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
******************************************************************************/

package fr.husi.plugin.mieru

import android.net.Uri
import android.os.ParcelFileDescriptor
import io.nekohasekai.sagernet.plugin.NativePluginProvider
import io.nekohasekai.sagernet.plugin.PathProvider
import java.io.File
import java.io.FileNotFoundException

class BinaryProvider : NativePluginProvider() {
override fun populateFiles(provider: PathProvider) {
provider.addPath("mieru-plugin", 0b111101101)
}

override fun getExecutable() = context!!.applicationInfo.nativeLibraryDir + "/libmieru.so"
override fun openFile(uri: Uri): ParcelFileDescriptor = when (uri.path) {
"/mieru-plugin" -> ParcelFileDescriptor.open(
File(getExecutable()),
ParcelFileDescriptor.MODE_READ_ONLY
)

else -> throw FileNotFoundException()
}
}
Loading

0 comments on commit f4cf6c2

Please sign in to comment.