Skip to content

Commit

Permalink
fix tcp-tunneling feature; support android CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Heap-Hop committed Aug 31, 2024
1 parent ef5f618 commit c3469d2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Android Release"

on:
workflow_dispatch:
push:
branches: ["main"]
tags:
- "v*"

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
android-release_build_and_publish:
name: Android release build and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26d
add-to-path: false

- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable && rustup target add x86_64-linux-android aarch64-linux-android

- run: cargo install cargo-ndk

- name: Build
run: ./scripts/build-android.sh
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: GH publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload -R ${{ github.repository }} --clobber ${{ github.ref_name }} dist/fungi-android.tar.gz
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "Release"

on:
workflow_dispatch:
push:
branches: ["main"]
tags:
Expand Down
2 changes: 2 additions & 0 deletions fungi-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["tcp-tunneling"]
tcp-tunneling = []
cli = ["clap"]

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions fungi-daemon/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ fn apply_tcp_tunneling(swarm: &mut TSwarm, config: &FungiConfig) {
.set_addresses(&target_peer, rule.remote.multiaddrs.clone());

let target_protocol =
StreamProtocol::try_from_owned(rule.remote.protocol.clone()).unwrap(); // TODO unwrap
libp2p::StreamProtocol::try_from_owned(rule.remote.protocol.clone()).unwrap(); // TODO unwrap
let stream_control = swarm.behaviour().stream.new_control();
println!(
"Forwarding local port {} to {}/{}",
rule.local_socket.port, target_peer, target_protocol
);
tokio::spawn(tcp_tunneling::forward_port_to_peer(
tokio::spawn(fungi_util::tcp_tunneling::forward_port_to_peer(
stream_control,
(&rule.local_socket).try_into().unwrap(), // TOOD unwrap
target_peer,
Expand All @@ -135,10 +135,10 @@ fn apply_tcp_tunneling(swarm: &mut TSwarm, config: &FungiConfig) {
for rule in config.tcp_tunneling.listening.rules.iter() {
let local_addr = (&rule.local_socket).try_into().unwrap(); // TODO unwrap
let listening_protocol =
StreamProtocol::try_from_owned(rule.listening_protocol.clone()).unwrap(); // TODO unwrap
libp2p::StreamProtocol::try_from_owned(rule.listening_protocol.clone()).unwrap(); // TODO unwrap
let stream_control = swarm.behaviour().stream.new_control();
println!("Listening on {} for {}", local_addr, listening_protocol);
tokio::spawn(tcp_tunneling::listen_p2p_to_port(
tokio::spawn(fungi_util::tcp_tunneling::listen_p2p_to_port(
stream_control,
listening_protocol,
local_addr,
Expand Down
3 changes: 1 addition & 2 deletions fungi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ name = "fungi-daemon"
path = "src/bins/fungi-daemon.rs"

[features]
default = ["tcp-tunneling", "daemon"]
tcp-tunneling = []
default = ["daemon"]
daemon = ["fungi-daemon"]

[dependencies]
Expand Down
25 changes: 17 additions & 8 deletions scripts/build-android.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
set -e

if [ "$1" == "debug" ]; then
if [ "$2" == "x86" ]; then
target_folder="i686-linux-android"
elif [ "$2" == "x86_64" ]; then
if [ "$2" == "x86_64" ]; then
target_folder="x86_64-linux-android"
elif [ "$2" == "armeabi-v7a" ]; then
target_folder="armv7-linux-androideabi"
elif [ "$2" == "arm64-v8a" ]; then
target_folder="aarch64-linux-android"
else
Expand All @@ -24,20 +20,33 @@ if [ "$1" == "debug" ]; then
--language kotlin \
--out-dir dist/android-binding/

cargo ndk -t $2 build -p fungi --no-default-features

cp target/$target_folder/debug/fungi dist/android-output/jniLibs/$2/libfungi.so

exit 0
fi

# default release build

cargo ndk \
-t x86 \
-t x86_64 \
-t armeabi-v7a \
-t arm64-v8a \
-o dist/android-output/jniLibs build \
-p fungi-daemon-uniffi-binding --release

cargo run -p uniffi-bindgen generate \
--library target/i686-linux-android/release/libfungi_daemon_binding.so \
--library target/x86_64-linux-android/release/libfungi_daemon_binding.so \
--language kotlin \
--out-dir dist/android-binding/

cargo ndk \
-t x86_64 \
-t arm64-v8a \
build \
-p fungi --no-default-features --release

cp target/x86_64-linux-android/release/fungi dist/android-output/jniLibs/x86_64/libfungi.so
cp target/aarch64-linux-android/release/fungi dist/android-output/jniLibs/arm64-v8a/libfungi.so

tar -czvf dist/fungi-android.tar.gz dist/android-output dist/android-binding

0 comments on commit c3469d2

Please sign in to comment.