Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rust-feature to build without including ffmpeg and/or livekit #170

Merged
merged 9 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ name: Android Build

on:
push:
branches:
- main
# branches:
leanmendoza marked this conversation as resolved.
Show resolved Hide resolved
# - main

leanmendoza marked this conversation as resolved.
Show resolved Hide resolved
jobs:
build:
runs-on: self-hosted-ubuntu
container:
image: docker://kuruk/dcl-godot-android-builder:latest

steps:
- uses: actions/checkout@v4
- name: Setup Rust
Expand All @@ -21,12 +20,12 @@ jobs:
export PATH="/root/.cargo/bin:${PATH}"
rustup default stable
rustup target add aarch64-linux-android
rustup target add x86_64-linux-android
- name: Build
continue-on-error: true
run: |
bash build-android-apk.sh
- uses: actions/upload-artifact@v3
if: always()
if: success() || failure()
with:
name: Android APK
path: |
Expand Down
14 changes: 12 additions & 2 deletions build-android-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ mkdir -p ${HOME}/.local/share/godot/export_templates/
cd ${HOME}/.local/share/godot/export_templates/
ln -sf ${EXPLORER_PATH}/.bin/godot/templates/templates/ 4.2.1.stable

echo "Build for Android"
set -e

echo "Build for Android (arm64)"
cd ${EXPLORER_PATH}/rust/decentraland-godot-lib
bash android-build.sh

echo "Build for Android (x86_64)"
cd ${EXPLORER_PATH}/rust/decentraland-godot-lib
bash android-build.sh x86_64

set +e

echo "Setup Android Debug Keys"
cd /opt/
keytool -keyalg RSA -genkeypair -alias androiddebugkey \
Expand All @@ -38,4 +46,6 @@ echo "Export Godot APK"
cd ${EXPLORER_PATH}/godot/

${EXPLORER_PATH}/.bin/godot/godot4_bin \
-e --headless --export-debug Android ${EXPLORER_PATH}/android.apk
-e --headless --export-debug Android ${EXPLORER_PATH}/android.apk

echo "Finished"
3 changes: 2 additions & 1 deletion godot/decentraland_godot_lib.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linux.debug.x86_64 = "res://lib/libdecentraland_godot_lib.so"
linux.release.x86_64 = "res://lib/libdecentraland_godot_lib.so"
macos.debug = "res://lib/libdecentraland_godot_lib.dylib"
macos.release = "res://lib/libdecentraland_godot_lib.dylib"
android.debug.arm64 = "res://lib/android/libdecentraland_godot_lib.so"
android.debug.arm64 = "res://lib/android/arm64/libdecentraland_godot_lib.so"
android.debug.x86_64 = "res://lib/android/x86_64/libdecentraland_godot_lib.so"
ios.debug.arm64 = "res://lib/ios/libdecentraland_godot_lib.dylib"
ios.release.arm64 = "res://lib/ios/libdecentraland_godot_lib.dylib"
4 changes: 2 additions & 2 deletions godot/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*,*.*"
exclude_filter="lib/android/*.so,lib/*.dll"
exclude_filter="lib/android/arm64/*.so,lib/android/x86_64/*.so,lib/*.dll"
export_path="../../../../Desktop/builds/decentraland-godot-self-hosted-windows/local/decentraland.godot.win64.exe"
encryption_include_filters=""
encryption_exclude_filters=""
Expand Down Expand Up @@ -233,7 +233,7 @@ gradle_build/target_sdk=""
architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
architectures/x86_64=false
architectures/x86_64=true
version/code=1
version/name="1.0"
package/unique_name="org.godotengine.decentralandgodot"
Expand Down
22 changes: 14 additions & 8 deletions rust/decentraland-godot-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ godot = { git = "https://github.com/godot-rust/gdext", rev = "5e18af87a13bf8d40b
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.92", features = ["raw_value"] }
tokio = { version = "1.26.0", features = ["sync", "rt-multi-thread", "net"] }
tokio = { version = "1.26.0", features = ["full"] }
protobuf = "3.2.0"
prost = "0.11.8"
once_cell = "1.16.0"
Expand All @@ -26,8 +26,8 @@ urn = "0.7.0"
ethers = { version = "2.0", features = ["rustls"] }
async-trait = "0.1.68"

cpal = "0.15.2"
ffmpeg-next = { git = "https://github.com/decentraland/rust-ffmpeg/", branch="audioline-and-mobile-fix" }
cpal = { version = "0.15.2", optional = true }
ffmpeg-next = { git = "https://github.com/decentraland/rust-ffmpeg/", branch="audioline-and-mobile-fix", optional = true }

thiserror = "1.0"
anyhow = "1.0.70"
Expand All @@ -37,18 +37,18 @@ tracing-subscriber = "0.3"
poll-promise = "0.2.0"
log-panics = { version = "2", features = ["with-backtrace"]}

v8 = "0.74.3"
deno_core = "0.197"
v8 = { version = "0.74.3", optional = true }
deno_core = { version = "0.197", optional = true }
num-traits = "0.2"
num-derive = "0.3"
num = "0.4"
http = "0.2.9"
bytes = "1.4.0"

tokio-tungstenite = "0.20.1"
futures-util = "*"
futures-util = "0.3.30"

livekit = { git = "https://github.com/robtfm/client-sdk-rust", branch="h264-false", features=["rustls-tls-webpki-roots"] }
livekit = { git = "https://github.com/robtfm/client-sdk-rust", branch="h264-false", features=["rustls-tls-webpki-roots"], optional = true }

taffy = { git = "https://github.com/DioxusLabs/taffy", rev="7eee673c5ea65f64f35c53f5ee2fe5faf62b9c1e" }
tracing-test = "0.2.4"
Expand All @@ -65,10 +65,16 @@ multipart = { version = "0.18.0", default-features = false, features = ["client"
ethers-providers = { version = "2.0", features = ["ws","rustls"] }

[target.'cfg(target_os = "android")'.dependencies]
ffmpeg-next = { git = "https://github.com/decentraland/rust-ffmpeg/", branch = "audioline-and-mobile-fix", features = ["fix_usize_size_t"] }
ffmpeg-next = { git = "https://github.com/decentraland/rust-ffmpeg/", branch = "audioline-and-mobile-fix", features = ["fix_usize_size_t"], optional = true }
jni = { version = "0.21.1", features = ["invocation"] }
paranoid-android = "0.2.1"

[features]
default = ["use_ffmpeg", "use_livekit", "use_deno"]
use_ffmpeg = ["dep:ffmpeg-next", "dep:cpal"]
use_livekit = ["use_ffmpeg", "dep:livekit"]
use_deno = ["dep:deno_core", "dep:v8"]

[build-dependencies]
webrtc-sys-build = "0.2.0"
prost-build = "0.11.8"
Expand Down
55 changes: 35 additions & 20 deletions rust/decentraland-godot-lib/android-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,38 @@ if [[ -z "${FFMPEG_DIR}" ]]; then
FFMPEG_DIR=~/Documents/github/ffmpeg-kit/prebuilt/android-arm64/ffmpeg
fi


# Run the specified commands
export TARGET_CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
export TARGET_CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang++
export TARGET_AR=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
export RUSTY_V8_MIRROR=https://github.com/leanmendoza/rusty_v8/releases/download
export CARGO_FFMPEG_SYS_DISABLE_SIZE_T_IS_USIZE=1
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang


GN_ARGS=use_custom_libcxx=false RUST_BACKTRACE=full cargo build --target aarch64-linux-android -vv --verbose --release

mkdir -p ../../godot/lib/android/
cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/lib/android/libdecentraland_godot_lib.so
mkdir -p ../../godot/android/build/libs/debug/arm64-v8a/
cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/android/build/libs/debug/arm64-v8a/libdecentraland_godot_lib.so

# Dependencies
# - from web-rtc: libwebrtc.jar
# - from ffmpeg: libavcodec, libavfilter, libavdevice, libavformat, libavutil, libswresample, libswscale
# Check if the script is invoked with the x86_64 parameter
if [[ "$1" == "x86_64" ]]; then
export TARGET_CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android33-clang
export TARGET_CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android33-clang++
export TARGET_AR=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android33-clang

GN_ARGS=use_custom_libcxx=false RUST_BACKTRACE=full cargo build --release --no-default-features --target x86_64-linux-android -vv --verbose

mkdir -p ../../godot/lib/android/x86_64/
mkdir -p ../../godot/android/build/libs/debug/x86_64/

cp target/x86_64-linux-android/release/libdecentraland_godot_lib.so ../../godot/lib/android/x86_64/libdecentraland_godot_lib.so
cp target/x86_64-linux-android/release/libdecentraland_godot_lib.so ../../godot/android/build/libs/debug/x86_64/libdecentraland_godot_lib.so

else
# Run the specified commands
export TARGET_CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
export TARGET_CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang++
export TARGET_AR=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
export RUSTY_V8_MIRROR=https://github.com/leanmendoza/rusty_v8/releases/download
export CARGO_FFMPEG_SYS_DISABLE_SIZE_T_IS_USIZE=1
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang

GN_ARGS=use_custom_libcxx=false RUST_BACKTRACE=full cargo build --release --target aarch64-linux-android -vv --verbose

# Dependencies
# - from web-rtc: libwebrtc.jar
# - from ffmpeg: libavcodec, libavfilter, libavdevice, libavformat, libavutil, libswresample, libswscale
mkdir -p ../../godot/lib/android/arm64/
mkdir -p ../../godot/android/build/libs/debug/arm64-v8a/

cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/lib/android/arm64/libdecentraland_godot_lib.so
cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/android/build/libs/debug/arm64-v8a/libdecentraland_godot_lib.so
fi
1 change: 1 addition & 0 deletions rust/decentraland-godot-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ fn main() -> io::Result<()> {
std::env::set_var("PROTOC", protoc_path);
prost_build::compile_protos(&proto_files, &["src/dcl/components/proto/"])?;

#[cfg(feature = "use_livekit")]
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
webrtc_sys_build::configure_jni_symbols().unwrap();
}
Expand Down
1 change: 1 addition & 0 deletions rust/decentraland-godot-lib/src/comms/adapter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod adapter_trait;
#[cfg(feature = "use_livekit")]
pub mod livekit;
pub mod ws_room;
16 changes: 12 additions & 4 deletions rust/decentraland-godot-lib/src/comms/communication_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use godot::prelude::*;
use http::Uri;

use crate::{
comms::{
adapter::{livekit::LivekitRoom, ws_room::WebSocketRoom},
signed_login::SignedLoginMeta,
},
comms::{adapter::ws_room::WebSocketRoom, signed_login::SignedLoginMeta},
dcl::components::proto_components::kernel::comms::rfc4,
godot_classes::dcl_global::DclGlobal,
};
Expand All @@ -15,6 +12,9 @@ use super::{
signed_login::{SignedLogin, SignedLoginPollStatus},
};

#[cfg(feature = "use_livekit")]
use crate::comms::adapter::livekit::LivekitRoom;

#[allow(clippy::large_enum_variant)]
enum CommsConnection {
None,
Expand Down Expand Up @@ -323,6 +323,8 @@ impl CommunicationManager {
SignedLoginMeta::new(true, origin),
));
}

#[cfg(feature = "use_livekit")]
"livekit" => {
self.current_connection = CommsConnection::Connected(Box::new(LivekitRoom::new(
comms_address.to_string(),
Expand All @@ -331,6 +333,12 @@ impl CommunicationManager {
avatar_scene,
)));
}

#[cfg(not(feature = "use_livekit"))]
"livekit" => {
tracing::error!("livekit wasn't included in this build");
}

"offline" => {
tracing::info!("set offline");
}
Expand Down
83 changes: 83 additions & 0 deletions rust/decentraland-godot-lib/src/dcl/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use std::sync::atomic::AtomicBool;

use serde::{Deserialize, Serialize};

use crate::godot_classes::JsonGodotClass;

pub struct SceneJsFileContent(pub String);
pub struct SceneMainCrdtFileContent(pub Vec<u8>);

pub struct SceneStartTime(pub std::time::SystemTime);
pub struct SceneLogs(pub Vec<SceneLogMessage>);
pub struct SceneMainCrdt(pub Option<Vec<u8>>);
pub struct SceneTickCounter(pub u32);
pub struct SceneDying(pub bool);

pub struct SceneElapsedTime(pub f32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum SceneLogLevel {
Log = 1,
SceneError = 2,
SystemError = 3,
}

#[derive(Clone, Debug)]
pub struct SceneLogMessage {
pub timestamp: f64, // scene local time
pub level: SceneLogLevel,
pub message: String,
}
static SCENE_LOG_ENABLED: AtomicBool = AtomicBool::new(false);

#[derive(Debug, Deserialize, Serialize)]
pub struct GreyPixelDiffRequest {}

#[derive(Debug, Deserialize, Serialize)]
pub struct TestingScreenshotComparisonMethodRequest {
grey_pixel_diff: Option<GreyPixelDiffRequest>,
}

impl JsonGodotClass for TestingScreenshotComparisonMethodRequest {}

#[derive(Debug, Deserialize, Serialize)]
pub struct GreyPixelDiffResult {
pub similarity: f64,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TakeAndCompareSnapshotResponse {
pub stored_snapshot_found: bool,
pub grey_pixel_diff: Option<GreyPixelDiffResult>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SceneTestResult {
pub name: String,
pub ok: bool,
pub error: Option<String>,
pub stack: Option<String>,
pub total_frames: i32,
pub total_time: f32,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SceneTestPlan {
pub tests: Vec<SceneTestPlanTestPlanEntry>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SceneTestPlanTestPlanEntry {
pub name: String,
}

pub fn set_scene_log_enabled(enabled: bool) {
SCENE_LOG_ENABLED.store(enabled, std::sync::atomic::Ordering::Relaxed);
}

pub fn is_scene_log_enabled() -> bool {
SCENE_LOG_ENABLED.load(std::sync::atomic::Ordering::Relaxed)
}
3 changes: 1 addition & 2 deletions rust/decentraland-godot-lib/src/dcl/js/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use std::{
use deno_core::{op, Op, OpDecl, OpState};

use crate::dcl::{
common::{SceneDying, SceneElapsedTime, SceneLogs, SceneMainCrdtFileContent},
crdt::{
message::{
append_gos_component, delete_entity, process_many_messages, put_or_delete_lww_component,
},
SceneCrdtState,
},
js::{SceneDying, SceneMainCrdtFileContent},
scene_apis::{LocalCall, RpcCall},
serialization::{reader::DclReader, writer::DclWriter},
RendererResponse, SceneId, SceneResponse, SharedSceneCrdtState,
Expand All @@ -22,7 +22,6 @@ use crate::dcl::{
use super::{
events::process_events,
players::{get_player_data, get_players},
SceneElapsedTime, SceneLogs,
};

// list of op declarations
Expand Down
Loading
Loading