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

Prune dependencies from rerun and re_sdk #4824

Merged
merged 14 commits into from
Jan 16, 2024
23 changes: 23 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/re_data_source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ default = []


[dependencies]
re_log_encoding = { workspace = true, features = ["decoder"] }
re_log_encoding = { workspace = true, features = [
"decoder",
"stream_from_http",
] }
re_log_types.workspace = true
re_log.workspace = true
re_smart_channel.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/re_data_source/src/data_loader/loader_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use once_cell::sync::Lazy;

/// To register a new external data loader, simply add an executable in your $PATH whose name
/// starts with this prefix.
// NOTE: this constant is duplicated in `rerun` to avoid an extra dependency there.
pub const EXTERNAL_DATA_LOADER_PREFIX: &str = "rerun-loader-";

/// When an external [`crate::DataLoader`] is asked to load some data that it doesn't know
/// how to load, it should exit with this exit code.
// NOTE: Always keep in sync with other languages.
// NOTE: this constant is duplicated in `rerun` to avoid an extra dependency there.
pub const EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE: i32 = 66;

/// Keeps track of the paths all external executable [`crate::DataLoader`]s.
Expand Down
17 changes: 14 additions & 3 deletions crates/re_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ version.workspace = true
all-features = true


[features]
default = []

## Feature to set up logging in binaries,
## i.e. from `main` or in a web-app.
setup = ["dep:env_logger", "dep:js-sys", "dep:wasm-bindgen"]


[dependencies]
log = { workspace = true, features = ["std"] }
log-once.workspace = true
Expand All @@ -26,9 +34,12 @@ tracing = { workspace = true, features = ["log"] }

# Native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = { workspace = true, features = ["auto-color", "humantime"] }
env_logger = { workspace = true, optional = true, features = [
"auto-color",
"humantime",
] }

# web dependencies:
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys.workspace = true
wasm-bindgen.workspace = true
js-sys = { workspace = true, optional = true }
wasm-bindgen = { workspace = true, optional = true }
52 changes: 45 additions & 7 deletions crates/re_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
//! logging of the exact same message.

mod channel_logger;
mod multi_logger;
mod result_extensions;

#[cfg(feature = "setup")]
mod multi_logger;

#[cfg(feature = "setup")]
mod setup;

#[cfg(target_arch = "wasm32")]
#[cfg(all(feature = "setup", target_arch = "wasm32"))]
mod web_logger;

pub use log::{Level, LevelFilter};
Expand All @@ -32,11 +36,13 @@ pub use tracing::{debug, error, info, trace, warn};
// similar to how the log console in a browser will automatically suppress duplicates.
pub use log_once::{debug_once, error_once, info_once, log_once, trace_once, warn_once};

pub use {
channel_logger::*,
multi_logger::{add_boxed_logger, add_logger, MultiLoggerNotSetupError},
setup::*,
};
pub use channel_logger::*;

#[cfg(feature = "setup")]
pub use multi_logger::{add_boxed_logger, add_logger, MultiLoggerNotSetupError};

#[cfg(feature = "setup")]
pub use setup::*;

/// Re-exports of other crates.
pub mod external {
Expand Down Expand Up @@ -72,6 +78,38 @@ const CRATES_AT_INFO_LEVEL: &[&str] = &[
"rustls",
];

/// Get `RUST_LOG` environment variable or `info`, if not set.
///
/// Also sets some other log levels on crates that are too loud.
#[cfg(not(target_arch = "wasm32"))]
pub fn default_log_filter() -> String {
let mut rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| {
if cfg!(debug_assertions) {
"debug".to_owned()
} else {
"info".to_owned()
}
});

for crate_name in crate::CRATES_AT_ERROR_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=error");
}
}
for crate_name in crate::CRATES_AT_WARN_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=warn");
}
}
for crate_name in crate::CRATES_AT_INFO_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=info");
}
}

rust_log
}

/// Should we log this message given the filter?
fn is_log_enabled(filter: log::LevelFilter, metadata: &log::Metadata<'_>) -> bool {
if CRATES_AT_ERROR_LEVEL
Expand Down
34 changes: 1 addition & 33 deletions crates/re_log/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
//! Function to setup logging in binaries and web apps.

/// Get `RUST_LOG` environment variable or `info`, if not set.
///
/// Also sets some other log levels on crates that are too loud.
#[cfg(not(target_arch = "wasm32"))]
pub fn default_log_filter() -> String {
let mut rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| {
if cfg!(debug_assertions) {
"debug".to_owned()
} else {
"info".to_owned()
}
});

for crate_name in crate::CRATES_AT_ERROR_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=error");
}
}
for crate_name in crate::CRATES_AT_WARN_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=warn");
}
}
for crate_name in crate::CRATES_AT_INFO_LEVEL {
if !rust_log.contains(&format!("{crate_name}=")) {
rust_log += &format!(",{crate_name}=info");
}
}

rust_log
}

/// Directs [`log`] calls to stderr.
#[cfg(not(target_arch = "wasm32"))]
pub fn setup_native_logging() {
Expand All @@ -49,7 +17,7 @@ pub fn setup_native_logging() {

crate::multi_logger::init().expect("Failed to set logger");

let log_filter = default_log_filter();
let log_filter = crate::default_log_filter();

if log_filter.contains("trace") {
log::set_max_level(log::LevelFilter::Trace);
Expand Down
Loading
Loading