Skip to content

Commit

Permalink
Prune dependencies from rerun and re_sdk (#4824)
Browse files Browse the repository at this point in the history
* Part of #4788

### What
* `rerun` has a new opt-in feature `run`
* `re_log` has a new opt-in feature `setup`
* `re_log_encoding` has a new opt-in feature `stream_from_http`
* …and other smaller fixes

### Result
* `cargo build -p re_sdk -F default` 269 -> 218 dependencies
* `cargo build -p rerun --no-default-features` 364 -> 226 dependencies
* `cargo build -p rerun -F sdk` 370 -> 286 dependencies
* `cargo build -p rerun -F default` 383 -> 339 dependencies

Yes, this is still _a lot_.


![sisyphus](https://github.com/rerun-io/rerun/assets/1148717/aa1fbdd6-1f0f-4d20-ae1c-724caacef7a3)

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/4824/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/4824/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/4824/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4824)
- [Docs
preview](https://rerun.io/preview/a5cf84457e7f2b1399a4e0c3e803e2351f44551a/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/a5cf84457e7f2b1399a4e0c3e803e2351f44551a/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
emilk authored Jan 16, 2024
1 parent 1989951 commit 26e8aff
Show file tree
Hide file tree
Showing 60 changed files with 241 additions and 113 deletions.
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

0 comments on commit 26e8aff

Please sign in to comment.