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

refactor: bumping rust to 1.79 - livekit, deno, gdext #490

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77.2
toolchain: 1.79
override: true
components: clippy, rustfmt
- name: Set up cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77.2
toolchain: 1.79
override: true
components: llvm-tools-preview

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.77.2
toolchain: 1.79
override: true

- name: Set up cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.77.2
toolchain: 1.79
override: true

# Dependencies section
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.77.2
toolchain: 1.79
override: true
components: clippy, rustfmt
- run: rustup component add rustfmt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.77.2
toolchain: 1.79
override: true

- name: Set up cache
Expand Down
5 changes: 4 additions & 1 deletion godot/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ mono_crash.*.json
# System/tool-specific ignores
.directory
.DS_Store
*~
*~

# Decentraland ignores
/output/
5 changes: 4 additions & 1 deletion lib/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ rustflags = ["-C", "link-args=-ObjC"]
rustflags = ["-C", "link-args=-mios-version-min=12.0 -ObjC"]

[target.aarch64-apple-ios-sim]
rustflags = ["-C", "link-args=-mios-version-min=12.0 -ObjC"]
rustflags = ["-C", "link-args=-mios-version-min=12.0 -ObjC"]

[env]
CARGO_FEATURE_CRT_STATIC = "ohyes"
18 changes: 7 additions & 11 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
godot = { git = "https://github.com/dclexplorer/gdext", rev ="4204285cdd32799690de28ee3a98ef624e95369e", features=["experimental-threads", "serde"] }
godot = { version = "0.1.3", features=["experimental-threads", "serde"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.92", features = ["raw_value"] }
tokio = { version = "1.37.0", features = ["full"] }
tokio = { version = "1.40.0", features = ["full"] }
protobuf = "3.2.0"
prost = "0.11.8"
once_cell = "1.16.0"
Expand Down Expand Up @@ -41,8 +41,8 @@ tracing-subscriber = "0.3"
poll-promise = "0.2.0"
log-panics = { version = "2", features = ["with-backtrace"]}

v8 = { version = "0.74.3", optional = true }
deno_core = { version = "0.197", optional = true }
v8 = { version = "0.105.1", default-features = false, optional = true }
deno_core = { git = "https://github.com/robtfm/deno_core", branch = "0_307_hotfix", optional = true }
uuid = { version = "1.3.0", features = ["v4"] }
fastwebsockets = { version = "0.3.1", features = ["upgrade"], optional = true }
hyper1 = { package = "hyper", version = "0.14.26", features = ["server","runtime", "http1"], optional = true }
Expand All @@ -55,7 +55,7 @@ bytes = "1.4.0"
tokio-tungstenite = "0.20.1"
futures-util = "0.3.30"

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

taffy = "0.5.2"
tracing-test = "0.2.4"
Expand Down Expand Up @@ -83,10 +83,6 @@ use_resource_tracking = []
enable_inspector = ["use_deno", "dep:fastwebsockets", "dep:hyper1"]

[build-dependencies]
webrtc-sys-build = { git = "https://github.com/livekit/rust-sdks", optional = true, rev="8b276f9d4b98437a139e1cbe41cfda1332ce1120" }
webrtc-sys-build = { version = "0.3.5", optional = true }
prost-build = "0.11.8"
chrono = "0.4.31"

[patch."https://github.com/godot-rust/godot4-prebuilt".godot4-prebuilt]
git = "https://github.com//godot-rust/godot4-prebuilt"
rev = "bc1e77856d181c14c59d2a5cb6a7e138ea5a2b39"
chrono = "0.4.31"
16 changes: 12 additions & 4 deletions lib/android-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,28 @@ if [[ "$1" == "x86_64" ]]; then
cp target/x86_64-linux-android/release/libdclgodot.so ../godot/android/build/libs/release/x86_64/libdclgodot.so

else
# Run the specified commands
# Run the specified commands
export TARGET_CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android35-clang
export TARGET_CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android35-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-android35-clang"
export CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG=true

export CXXFLAGS="-v --target=aarch64-linux-android"
export RUSTFLAGS="-L${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib/aarch64-unknown-linux-musl"

# CI
export RUSTY_V8_MIRROR=https://github.com/leanmendoza/rusty_v8/releases/download
V8_BINDING_FILE_NAME=src_binding_debug_aarch64-linux-android.rs
V8_BINDING=$RUSTY_V8_MIRROR/v0.105.1/$V8_BINDING_FILE_NAME
export RUSTY_V8_SRC_BINDING_PATH=$(pwd)/target/$V8_BINDING_FILE_NAME
# download if not exists
if [ ! -f "target/$V8_BINDING_FILE_NAME" ]; then
curl -L -o target/$V8_BINDING_FILE_NAME $V8_BINDING
fi
GODOT_DIR=../godot

# Local development
# - V8 local build
# export RUSTY_V8_SRC_BINDING_PATH=/home/user/github/rusty_v8_updated/target/aarch64-linux-android/release/gn_out/src_binding.rs
Expand Down
8 changes: 4 additions & 4 deletions lib/src/avatars/avatar_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ impl DclAvatarWireFormat {

for (i, emote) in DEFAULT_EMOTES.iter().enumerate() {
if let Some(emote) = used_emotes.iter().find(|e| e.slot == i as u32) {
emotes.set(i, GString::from(emote.urn.as_str()));
emotes[i] = GString::from(emote.urn.as_str());
} else {
emotes.set(i, GString::from(*emote));
emotes[i] = GString::from(*emote);
}
}
emotes
Expand Down Expand Up @@ -156,7 +156,7 @@ impl DclAvatarWireFormat {
fn set_wearables(&mut self, wearables: PackedStringArray) {
let mut wearables_vec = Vec::new();
for i in 0..wearables.len() {
wearables_vec.push(wearables.get(i).to_string());
wearables_vec.push(wearables.get(i).as_ref().unwrap().to_string());
}
self.inner.wearables = wearables_vec;
}
Expand All @@ -172,7 +172,7 @@ impl DclAvatarWireFormat {
for i in 0..10 {
emotes_vec.push(AvatarEmote {
slot: i as u32,
urn: emotes.get(i).to_string(),
urn: emotes.get(i).as_ref().unwrap().to_string(),
});
}
self.inner.emotes = Some(emotes_vec);
Expand Down
14 changes: 5 additions & 9 deletions lib/src/comms/adapter/livekit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use livekit::{
audio_source::native::NativeAudioSource,
prelude::{AudioSourceOptions, RtcAudioSource},
},
DataPacket, DataPacketKind, RoomOptions,
DataPacket, RoomOptions,
};
use prost::Message;

Expand Down Expand Up @@ -411,7 +411,7 @@ fn spawn_livekit_task(
echo_cancellation: true,
noise_suppression: true,
auto_gain_control: true,
}, 48000, 1);
}, 48000, 1, None);
let mic_track = LocalTrack::Audio(LocalAudioTrack::create_audio_track("mic", RtcAudioSource::Native(native_source.clone())));
room.local_participant().publish_track(mic_track, TrackPublishOptions{ source: TrackSource::Microphone, ..Default::default() }).await.unwrap();

Expand Down Expand Up @@ -473,7 +473,7 @@ fn spawn_livekit_task(
livekit::track::RemoteTrack::Audio(audio) => {
let sender = sender.clone();
rt2.spawn(async move {
let mut x = livekit::webrtc::audio_stream::native::NativeAudioStream::new(audio.rtc_track());
let mut x = livekit::webrtc::audio_stream::native::NativeAudioStream::new(audio.rtc_track(), 48000, 1);

tracing::debug!("remove track from {:?}", participant.identity().0.as_str());

Expand Down Expand Up @@ -519,12 +519,8 @@ fn spawn_livekit_task(
break 'stream;
};

let kind = if outgoing.unreliable {
DataPacketKind::Lossy
} else {
DataPacketKind::Reliable
};
if let Err(e) = room.local_participant().publish_data(DataPacket { payload: outgoing.data, kind, ..Default::default() }).await {
let reliable = !outgoing.unreliable;
if let Err(e) = room.local_participant().publish_data(DataPacket { payload: outgoing.data, reliable, ..Default::default() }).await {
tracing::debug!("outgoing failed: {e}; not exiting loop though since it often fails at least once or twice at the start...");
// break 'stream;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dcl/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SceneEntityId {
pub version: u16,
}

impl godot::builtin::meta::GodotConvert for SceneEntityId {
impl GodotConvert for SceneEntityId {
type Via = i32;
}

Expand Down
9 changes: 5 additions & 4 deletions lib/src/dcl/js/adaptation_layer_helper.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::dcl::scene_apis::RpcCall;
use deno_core::{anyhow::anyhow, op, Op, OpDecl, OpState};
use deno_core::{anyhow::anyhow, op2, OpDecl, OpState};
use serde::Serialize;
use std::{cell::RefCell, rc::Rc};

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_get_texture_size::DECL]
vec![op_get_texture_size()]
}

#[derive(Serialize)]
Expand All @@ -14,8 +14,9 @@ struct TextureSize {
height: f32,
}

#[op(v8)]
async fn op_get_texture_size(state: Rc<RefCell<OpState>>, src: String) -> TextureSize {
#[op2(async)]
#[serde]
async fn op_get_texture_size(state: Rc<RefCell<OpState>>, #[string] src: String) -> TextureSize {
let (sx, rx) = tokio::sync::oneshot::channel::<Result<godot::builtin::Vector2, String>>();

state
Expand Down
13 changes: 7 additions & 6 deletions lib/src/dcl/js/comms.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cell::RefCell, rc::Rc};

use deno_core::{op, JsBuffer, Op, OpDecl, OpState};
use deno_core::{op2, JsBuffer, OpDecl, OpState};
use ethers_core::types::H160;

use crate::dcl::scene_apis::RpcCall;
Expand All @@ -12,27 +12,28 @@ pub(crate) struct InternalPendingBinaryMessages {

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_comms_send_string::DECL, op_comms_send_binary::DECL]
vec![op_comms_send_string(), op_comms_send_binary()]
}

pub(crate) const COMMS_MSG_TYPE_STRING: u8 = 1;
pub(crate) const COMMS_MSG_TYPE_BINARY: u8 = 2;

#[op]
#[op2(async)]
async fn op_comms_send_string(
state: Rc<RefCell<OpState>>,
message: String,
#[string] message: String,
) -> Result<(), anyhow::Error> {
let mut message = message.into_bytes();
message.insert(0, COMMS_MSG_TYPE_STRING);
comms_send(state, vec![message]).await?;
Ok(())
}

#[op]
#[op2(async)]
#[serde]
async fn op_comms_send_binary(
state: Rc<RefCell<OpState>>,
messages: Vec<JsBuffer>,
#[serde] messages: Vec<JsBuffer>,
) -> Result<Vec<Vec<u8>>, anyhow::Error> {
let messages = messages
.iter()
Expand Down
25 changes: 13 additions & 12 deletions lib/src/dcl/js/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::{Arc, Mutex},
};

use deno_core::{op, Op, OpDecl, OpState};
use deno_core::{op2, OpDecl, OpState};

use crate::dcl::{
common::{SceneDying, SceneElapsedTime, SceneLogs, SceneMainCrdtFileContent},
Expand All @@ -27,15 +27,12 @@ use super::{

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![
op_crdt_send_to_renderer::DECL,
op_crdt_recv_from_renderer::DECL,
]
vec![op_crdt_send_to_renderer(), op_crdt_recv_from_renderer()]
}

// receive and process a buffer of crdt messages
#[op(v8)]
fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, messages: &[u8]) {
#[op2(fast)]
fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, #[arraybuffer] messages: &[u8]) {
let dying = op_state.borrow().borrow::<SceneDying>().0;
if dying {
return;
Expand Down Expand Up @@ -79,16 +76,20 @@ fn op_crdt_send_to_renderer(op_state: Rc<RefCell<OpState>>, messages: &[u8]) {
.expect("error sending scene response!!")
}

#[op(v8)]
async fn op_crdt_recv_from_renderer(op_state: Rc<RefCell<OpState>>) -> Vec<Vec<u8>> {
#[op2(async)]
#[serde]
async fn op_crdt_recv_from_renderer(
op_state: Rc<RefCell<OpState>>,
) -> Result<Vec<Vec<u8>>, anyhow::Error> {
let dying = op_state.borrow().borrow::<SceneDying>().0;
if dying {
return vec![];
return Ok(vec![]);
}

let mut receiver = op_state
.borrow_mut()
.take::<tokio::sync::mpsc::Receiver<RendererResponse>>();
.try_take::<tokio::sync::mpsc::Receiver<RendererResponse>>()
.ok_or(anyhow::Error::msg("already borrowed"))?;
let response = receiver.recv().await;

let mut op_state = op_state.borrow_mut();
Expand Down Expand Up @@ -182,7 +183,7 @@ async fn op_crdt_recv_from_renderer(op_state: Rc<RefCell<OpState>>) -> Vec<Vec<u
ret.push(main_crdt.0);
}
ret.push(data);
ret
Ok(ret)
}

fn process_local_api_calls(local_api_calls: Vec<LocalCall>, crdt_state: &SceneCrdtState) {
Expand Down
11 changes: 6 additions & 5 deletions lib/src/dcl/js/ethereum_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use deno_core::{anyhow::anyhow, error::AnyError, op, Op, OpDecl, OpState};
use deno_core::{anyhow::anyhow, error::AnyError, op2, OpDecl, OpState};

use std::{cell::RefCell, rc::Rc, sync::Arc};

Expand All @@ -9,14 +9,15 @@ use crate::{

// list of op declarations
pub fn ops() -> Vec<OpDecl> {
vec![op_send_async::DECL]
vec![op_send_async()]
}

#[op]
#[op2(async)]
#[serde]
async fn op_send_async(
state: Rc<RefCell<OpState>>,
method: String,
params: String,
#[string] method: String,
#[string] params: String,
) -> Result<serde_json::Value, AnyError> {
let params: Vec<serde_json::Value> = serde_json::from_str(&params)?;

Expand Down
Loading
Loading