Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Commit e89e090

Browse files
authored
ci: add auto-release on push (#3)
* init android relaese * fix ndk url * build with commit * improve build
1 parent e684800 commit e89e090

3 files changed

Lines changed: 236 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build tun2socks for Android
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Release version"
8+
required: true
9+
default: "v1.0.0"
10+
11+
push:
12+
branches:
13+
- '**'
14+
15+
jobs:
16+
build-and-upload:
17+
runs-on: ubuntu-latest
18+
19+
env:
20+
NDK_VERSION: 26b
21+
NDK_HOME: ${{ github.workspace }}/android-ndk
22+
23+
steps:
24+
- name: Checkout repo
25+
uses: actions/checkout@v3
26+
27+
- name: Get current date tag
28+
id: get_date
29+
run: |
30+
TAG="v$(date +'%y.%m.%d')"
31+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
32+
33+
- name: Install NDK
34+
run: |
35+
wget https://dl.google.com/android/repository/android-ndk-r${NDK_VERSION}-linux.zip
36+
unzip android-ndk-r${NDK_VERSION}-linux.zip
37+
mv android-ndk-r${NDK_VERSION} $NDK_HOME
38+
echo "$NDK_HOME" >> $GITHUB_PATH
39+
40+
- name: Build tun2socks
41+
run: |
42+
bash ./build-android-lib.sh
43+
44+
- name: Create and push tag if not exists
45+
run: |
46+
git config user.name "github-actions"
47+
git config user.email "github-actions@github.com"
48+
git tag -f ${{ steps.get_date.outputs.tag }}
49+
git push origin ${{ steps.get_date.outputs.tag }} --force
50+
51+
- name: Upload .tgz to release
52+
uses: softprops/action-gh-release@v2
53+
with:
54+
tag_name: ${{ steps.get_date.outputs.tag }}
55+
name: Release ${{ steps.get_date.outputs.tag }}
56+
files: libtun2socks.so.tgz
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

android-tun2socks.mk

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Copyright (C) 2009 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
#
16+
LOCAL_PATH := $(call my-dir)
17+
ROOT_PATH := $(LOCAL_PATH)
18+
19+
########################################################
20+
## libancillary
21+
########################################################
22+
23+
include $(CLEAR_VARS)
24+
25+
ANCILLARY_SOURCE := fd_recv.c fd_send.c
26+
27+
LOCAL_MODULE := libancillary
28+
#LOCAL_CFLAGS += -I$(LOCAL_PATH)/libancillary
29+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libancillary
30+
LOCAL_SRC_FILES := $(addprefix libancillary/, $(ANCILLARY_SOURCE))
31+
32+
include $(BUILD_STATIC_LIBRARY)
33+
34+
########################################################
35+
## tun2socks
36+
########################################################
37+
38+
include $(CLEAR_VARS)
39+
40+
LOCAL_CFLAGS := -std=gnu99
41+
LOCAL_CFLAGS += -DBADVPN_THREADWORK_USE_PTHREAD -DBADVPN_LINUX -DBADVPN_BREACTOR_BADVPN -D_GNU_SOURCE
42+
LOCAL_CFLAGS += -DBADVPN_USE_SIGNALFD -DBADVPN_USE_EPOLL
43+
LOCAL_CFLAGS += -DBADVPN_LITTLE_ENDIAN -DBADVPN_THREAD_SAFE
44+
LOCAL_CFLAGS += -DNDEBUG -DANDROID
45+
LOCAL_CFLAGS += -I
46+
47+
LOCAL_STATIC_LIBRARIES := libancillary
48+
49+
LOCAL_C_INCLUDES := \
50+
$(LOCAL_PATH)/badvpn/libancillary \
51+
$(LOCAL_PATH)/badvpn/lwip/src/include/ipv4 \
52+
$(LOCAL_PATH)/badvpn/lwip/src/include/ipv6 \
53+
$(LOCAL_PATH)/badvpn/lwip/src/include \
54+
$(LOCAL_PATH)/badvpn/lwip/custom \
55+
$(LOCAL_PATH)/badvpn \
56+
$(LOCAL_PATH)/libancillary
57+
58+
TUN2SOCKS_SOURCES := \
59+
base/BLog_syslog.c \
60+
system/BReactor_badvpn.c \
61+
system/BSignal.c \
62+
system/BConnection_common.c \
63+
system/BConnection_unix.c \
64+
system/BTime.c \
65+
system/BUnixSignal.c \
66+
system/BNetwork.c \
67+
flow/StreamRecvInterface.c \
68+
flow/PacketRecvInterface.c \
69+
flow/PacketPassInterface.c \
70+
flow/StreamPassInterface.c \
71+
flow/SinglePacketBuffer.c \
72+
flow/BufferWriter.c \
73+
flow/PacketBuffer.c \
74+
flow/PacketStreamSender.c \
75+
flow/PacketPassConnector.c \
76+
flow/PacketProtoFlow.c \
77+
flow/PacketPassFairQueue.c \
78+
flow/PacketProtoEncoder.c \
79+
flow/PacketProtoDecoder.c \
80+
socksclient/BSocksClient.c \
81+
tuntap/BTap.c \
82+
lwip/src/core/udp.c \
83+
lwip/src/core/memp.c \
84+
lwip/src/core/init.c \
85+
lwip/src/core/pbuf.c \
86+
lwip/src/core/tcp.c \
87+
lwip/src/core/tcp_out.c \
88+
lwip/src/core/netif.c \
89+
lwip/src/core/def.c \
90+
lwip/src/core/ip.c \
91+
lwip/src/core/mem.c \
92+
lwip/src/core/tcp_in.c \
93+
lwip/src/core/stats.c \
94+
lwip/src/core/inet_chksum.c \
95+
lwip/src/core/timeouts.c \
96+
lwip/src/core/ipv4/icmp.c \
97+
lwip/src/core/ipv4/igmp.c \
98+
lwip/src/core/ipv4/ip4_addr.c \
99+
lwip/src/core/ipv4/ip4_frag.c \
100+
lwip/src/core/ipv4/ip4.c \
101+
lwip/src/core/ipv4/autoip.c \
102+
lwip/src/core/ipv6/ethip6.c \
103+
lwip/src/core/ipv6/inet6.c \
104+
lwip/src/core/ipv6/ip6_addr.c \
105+
lwip/src/core/ipv6/mld6.c \
106+
lwip/src/core/ipv6/dhcp6.c \
107+
lwip/src/core/ipv6/icmp6.c \
108+
lwip/src/core/ipv6/ip6.c \
109+
lwip/src/core/ipv6/ip6_frag.c \
110+
lwip/src/core/ipv6/nd6.c \
111+
lwip/custom/sys.c \
112+
tun2socks/tun2socks.c \
113+
base/DebugObject.c \
114+
base/BLog.c \
115+
base/BPending.c \
116+
system/BDatagram_unix.c \
117+
flowextra/PacketPassInactivityMonitor.c \
118+
tun2socks/SocksUdpGwClient.c \
119+
udpgw_client/UdpGwClient.c \
120+
socks_udp_client/SocksUdpClient.c
121+
122+
LOCAL_MODULE := tun2socks
123+
124+
LOCAL_LDLIBS := -ldl -llog
125+
126+
LOCAL_SRC_FILES := $(addprefix badvpn/, $(TUN2SOCKS_SOURCES))
127+
128+
LOCAL_BUILD_SCRIPT := BUILD_EXECUTABLE
129+
LOCAL_MAKEFILE := $(local-makefile)
130+
$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT))
131+
$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE))
132+
$(call check-LOCAL_MODULE_FILENAME)
133+
# we are building target objects
134+
my := TARGET_
135+
$(call handle-module-filename,lib,$(TARGET_SONAME_EXTENSION))
136+
$(call handle-module-built)
137+
LOCAL_MODULE_CLASS := EXECUTABLE
138+
include $(BUILD_SYSTEM)/build-module.mk

build-android-lib.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
# Set magic variables for current file & dir
8+
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
10+
__base="$(basename ${__file} .sh)"
11+
12+
if [[ ! -d $NDK_HOME ]]; then
13+
echo "Android NDK: NDK_HOME not found. please set env \$NDK_HOME"
14+
exit 1
15+
fi
16+
17+
TMPDIR=$(mktemp -d)
18+
clear_tmp () {
19+
rm -rf $TMPDIR
20+
}
21+
22+
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; clear_tmp; exit 1' ERR INT
23+
install -m644 $__dir/android-tun2socks.mk $TMPDIR/
24+
25+
pushd $TMPDIR
26+
git clone --depth=1 https://github.com/XTLS/badvpn.git
27+
git clone --depth=1 https://github.com/shadowsocks/libancillary.git
28+
$NDK_HOME/ndk-build \
29+
NDK_PROJECT_PATH=. \
30+
APP_BUILD_SCRIPT=./android-tun2socks.mk \
31+
APP_ABI=all \
32+
APP_PLATFORM=android-21 \
33+
NDK_LIBS_OUT=$TMPDIR/libs \
34+
NDK_OUT=$TMPDIR/tmp \
35+
APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -j4
36+
37+
tar cvfz $__dir/libtun2socks.so.tgz libs
38+
popd
39+
40+
rm -rf $TMPDIR

0 commit comments

Comments
 (0)