Skip to content

Commit 26e8aff

Browse files
authored
Prune dependencies from rerun and re_sdk (#4824)
* 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)
1 parent 1989951 commit 26e8aff

File tree

60 files changed

+241
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+241
-113
lines changed

Cargo.lock

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/re_data_source/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ default = []
2121

2222

2323
[dependencies]
24-
re_log_encoding = { workspace = true, features = ["decoder"] }
24+
re_log_encoding = { workspace = true, features = [
25+
"decoder",
26+
"stream_from_http",
27+
] }
2528
re_log_types.workspace = true
2629
re_log.workspace = true
2730
re_smart_channel.workspace = true

crates/re_data_source/src/data_loader/loader_external.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ use once_cell::sync::Lazy;
1010

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

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

2022
/// Keeps track of the paths all external executable [`crate::DataLoader`]s.

crates/re_log/Cargo.toml

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ version.workspace = true
1616
all-features = true
1717

1818

19+
[features]
20+
default = []
21+
22+
## Feature to set up logging in binaries,
23+
## i.e. from `main` or in a web-app.
24+
setup = ["dep:env_logger", "dep:js-sys", "dep:wasm-bindgen"]
25+
26+
1927
[dependencies]
2028
log = { workspace = true, features = ["std"] }
2129
log-once.workspace = true
@@ -26,9 +34,12 @@ tracing = { workspace = true, features = ["log"] }
2634

2735
# Native dependencies:
2836
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
29-
env_logger = { workspace = true, features = ["auto-color", "humantime"] }
37+
env_logger = { workspace = true, optional = true, features = [
38+
"auto-color",
39+
"humantime",
40+
] }
3041

3142
# web dependencies:
3243
[target.'cfg(target_arch = "wasm32")'.dependencies]
33-
js-sys.workspace = true
34-
wasm-bindgen.workspace = true
44+
js-sys = { workspace = true, optional = true }
45+
wasm-bindgen = { workspace = true, optional = true }

crates/re_log/src/lib.rs

+45-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
//! logging of the exact same message.
1414
1515
mod channel_logger;
16-
mod multi_logger;
1716
mod result_extensions;
17+
18+
#[cfg(feature = "setup")]
19+
mod multi_logger;
20+
21+
#[cfg(feature = "setup")]
1822
mod setup;
1923

20-
#[cfg(target_arch = "wasm32")]
24+
#[cfg(all(feature = "setup", target_arch = "wasm32"))]
2125
mod web_logger;
2226

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

35-
pub use {
36-
channel_logger::*,
37-
multi_logger::{add_boxed_logger, add_logger, MultiLoggerNotSetupError},
38-
setup::*,
39-
};
39+
pub use channel_logger::*;
40+
41+
#[cfg(feature = "setup")]
42+
pub use multi_logger::{add_boxed_logger, add_logger, MultiLoggerNotSetupError};
43+
44+
#[cfg(feature = "setup")]
45+
pub use setup::*;
4046

4147
/// Re-exports of other crates.
4248
pub mod external {
@@ -72,6 +78,38 @@ const CRATES_AT_INFO_LEVEL: &[&str] = &[
7278
"rustls",
7379
];
7480

81+
/// Get `RUST_LOG` environment variable or `info`, if not set.
82+
///
83+
/// Also sets some other log levels on crates that are too loud.
84+
#[cfg(not(target_arch = "wasm32"))]
85+
pub fn default_log_filter() -> String {
86+
let mut rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| {
87+
if cfg!(debug_assertions) {
88+
"debug".to_owned()
89+
} else {
90+
"info".to_owned()
91+
}
92+
});
93+
94+
for crate_name in crate::CRATES_AT_ERROR_LEVEL {
95+
if !rust_log.contains(&format!("{crate_name}=")) {
96+
rust_log += &format!(",{crate_name}=error");
97+
}
98+
}
99+
for crate_name in crate::CRATES_AT_WARN_LEVEL {
100+
if !rust_log.contains(&format!("{crate_name}=")) {
101+
rust_log += &format!(",{crate_name}=warn");
102+
}
103+
}
104+
for crate_name in crate::CRATES_AT_INFO_LEVEL {
105+
if !rust_log.contains(&format!("{crate_name}=")) {
106+
rust_log += &format!(",{crate_name}=info");
107+
}
108+
}
109+
110+
rust_log
111+
}
112+
75113
/// Should we log this message given the filter?
76114
fn is_log_enabled(filter: log::LevelFilter, metadata: &log::Metadata<'_>) -> bool {
77115
if CRATES_AT_ERROR_LEVEL

crates/re_log/src/setup.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
11
//! Function to setup logging in binaries and web apps.
22
3-
/// Get `RUST_LOG` environment variable or `info`, if not set.
4-
///
5-
/// Also sets some other log levels on crates that are too loud.
6-
#[cfg(not(target_arch = "wasm32"))]
7-
pub fn default_log_filter() -> String {
8-
let mut rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| {
9-
if cfg!(debug_assertions) {
10-
"debug".to_owned()
11-
} else {
12-
"info".to_owned()
13-
}
14-
});
15-
16-
for crate_name in crate::CRATES_AT_ERROR_LEVEL {
17-
if !rust_log.contains(&format!("{crate_name}=")) {
18-
rust_log += &format!(",{crate_name}=error");
19-
}
20-
}
21-
for crate_name in crate::CRATES_AT_WARN_LEVEL {
22-
if !rust_log.contains(&format!("{crate_name}=")) {
23-
rust_log += &format!(",{crate_name}=warn");
24-
}
25-
}
26-
for crate_name in crate::CRATES_AT_INFO_LEVEL {
27-
if !rust_log.contains(&format!("{crate_name}=")) {
28-
rust_log += &format!(",{crate_name}=info");
29-
}
30-
}
31-
32-
rust_log
33-
}
34-
353
/// Directs [`log`] calls to stderr.
364
#[cfg(not(target_arch = "wasm32"))]
375
pub fn setup_native_logging() {
@@ -49,7 +17,7 @@ pub fn setup_native_logging() {
4917

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

52-
let log_filter = default_log_filter();
20+
let log_filter = crate::default_log_filter();
5321

5422
if log_filter.contains("trace") {
5523
log::set_max_level(log::LevelFilter::Trace);

0 commit comments

Comments
 (0)