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

Bug 1802503 - Rust: Implement a rust dispatcher connected to GCD #2316

Draft
wants to merge 2 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
30 changes: 30 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ commands:
glean_parser coverage --allow-reserved -c glean_coverage.txt -f codecovio -o codecov.json glean-core/metrics.yaml
bin/codecov.sh -X yaml -f codecov.json

test-rust-native-dispatcher:
steps:
- run:
name: Install required dependencies
command: |
sudo apt update
sudo apt install -y cmake ninja-build clang
- run:
name: Install libdispatch
command: |
cd ~
git clone https://github.com/apple/swift-corelibs-libdispatch
cd swift-corelibs-libdispatch
mkdir build && cd build
cmake -G Ninja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=On \
..
ninja
sudo ninja install

- run:
name: Run Rust tests with native dispatcher
command: |
export LD_LIBRARY_PATH=/usr/local/lib
cargo test --verbose --jobs 6 --features native-dispatcher -- --nocapture

install-rustup:
steps:
- run:
Expand Down Expand Up @@ -324,6 +352,7 @@ jobs:
resource_class: "medium+"
steps:
- test-rust
- test-rust-native-dispatcher

Rust tests - beta:
docker:
Expand Down Expand Up @@ -528,6 +557,7 @@ jobs:
- restore_cache:
keys:
- v2-cargo-cache-{{arch}}-{{checksum "buildtype.txt"}}-{{checksum "Cargo.lock"}}

- run:
name: Run iOS build
command: bash bin/run-ios-build.sh
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions glean-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ uniffi_macros = "0.22.0"
time = "0.1.40"
remove_dir_all = "0.5.3"
env_logger = { version = "0.9.0", default-features = false, optional = true }
dispatch = { version = "0.2.0", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
android_logger = { version = "0.11.0", default-features = false }

[target.'cfg(target_os = "ios")'.dependencies]
oslog = { version = "0.1.0", default-features = false, features = ["logger"] }

[target.'cfg(any(target_os = "ios"))'.dependencies]
dispatch = "0.2.0"

[dev-dependencies]
env_logger = { version = "0.9.0", default-features = false, features = ["termcolor", "atty", "humantime"] }
tempfile = "3.1.0"
Expand All @@ -67,3 +71,5 @@ uniffi_build = { version = "0.22.0", features = ["builtin-bindgen"] }
preinit_million_queue = []
# Enable `env_logger`. Only works on non-Android non-iOS targets.
enable_env_logger = ["env_logger"]
# Use libdispatch, default on iOS
native-dispatcher = ["dispatch"]
1 change: 1 addition & 0 deletions glean-core/rlb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ flate2 = "1.0.19"

[features]
preinit_million_queue = ["glean-core/preinit_million_queue"]
native-dispatcher = ["glean-core/native-dispatcher"]
12 changes: 5 additions & 7 deletions glean-core/src/dispatcher/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use once_cell::sync::Lazy;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::RwLock;

use once_cell::sync::Lazy;

use super::{DispatchError, DispatchGuard, Dispatcher};

#[cfg(feature = "preinit_million_queue")]
Expand All @@ -26,7 +28,7 @@ pub fn is_test_mode() -> bool {
///
/// A dispatcher is cheap to create, so we create one on every access instead of caching it.
/// This avoids troubles for tests where the global dispatcher _can_ change.
fn guard() -> DispatchGuard {
fn guard() -> Arc<DispatchGuard> {
GLOBAL_DISPATCHER
.read()
.unwrap()
Expand Down Expand Up @@ -89,11 +91,7 @@ fn join_dispatcher_thread() -> Result<(), DispatchError> {
let mut lock = GLOBAL_DISPATCHER.write().unwrap();
let dispatcher = lock.as_mut().expect("Global dispatcher has gone missing");

if let Some(worker) = dispatcher.worker.take() {
return worker.join().map_err(|_| DispatchError::WorkerPanic);
}

Ok(())
dispatcher.join()
}

/// Kill the blocked dispatcher without processing the queue.
Expand Down
Loading