From 02754956aa7ed4ab88f2025f73bb38170a1981ed Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 16 Jun 2024 20:38:48 +0900 Subject: [PATCH 1/5] Make backtrace optional feature --- rust_crate/Cargo.toml | 3 ++- rust_crate/src/interface_os.rs | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/rust_crate/Cargo.toml b/rust_crate/Cargo.toml index 520a0f49..35285330 100644 --- a/rust_crate/Cargo.toml +++ b/rust_crate/Cargo.toml @@ -10,10 +10,11 @@ rust-version = "1.70" [features] multi-worker = ["tokio/rt-multi-thread"] +show-backtrace = ["backtrace"] [target.'cfg(not(target_family = "wasm"))'.dependencies] os-thread-local = "0.1.3" -backtrace = "0.3.69" +backtrace = { version = "0.3.69", optional = true } protoc-prebuilt = "0.3.0" home = "0.5.9" which = "6.0.0" diff --git a/rust_crate/src/interface_os.rs b/rust_crate/src/interface_os.rs index e0629a8b..3494c314 100644 --- a/rust_crate/src/interface_os.rs +++ b/rust_crate/src/interface_os.rs @@ -41,10 +41,19 @@ where // Enable backtrace output for panics. #[cfg(debug_assertions)] { - std::panic::set_hook(Box::new(|panic_info| { - let backtrace = backtrace::Backtrace::new(); - crate::debug_print!("A panic occurred in Rust.\n{panic_info}\n{backtrace:?}"); - })); + #[cfg(not(feature = "backtrace"))] + { + std::panic::set_hook(Box::new(|panic_info| { + crate::debug_print!("A panic occurred in Rust.\n{panic_info}"); + })); + } + #[cfg(feature = "backtrace")] + { + std::panic::set_hook(Box::new(|panic_info| { + let backtrace = backtrace::Backtrace::new(); + crate::debug_print!("A panic occurred in Rust.\n{panic_info}\n{backtrace:?}"); + })); + } } // Prepare the channel that will notify tokio runtime to shutdown From b0bc69244fd3b7240930436c1bed72461018bd9f Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 16 Jun 2024 20:48:57 +0900 Subject: [PATCH 2/5] Add backtrace feature to the docs --- documentation/docs/configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index e534da96..266aa48b 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -26,3 +26,4 @@ rinf = { version = "0.0.0", features = ["feature-name"] } ``` - `multi-worker`: Starts a worker thread for each CPU core available on the system within the `tokio` runtime. By default, the `tokio` runtime uses only one thread. Enabling this feature allows the `tokio` runtime to utilize all the cores on your computer. This feature does not affect applications on the web platform. +- `show-backtrace`: Prints the full backtrace in the CLI when a panic occurs in debug mode. This feature does not affect debugging on the web platform. From 4d3360949b0ccb9c7aa6aef5038a0422c0d87bc4 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 16 Jun 2024 20:51:56 +0900 Subject: [PATCH 3/5] Explain `show-backtrace` in the docs --- documentation/docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index 266aa48b..33a9cc20 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -26,4 +26,4 @@ rinf = { version = "0.0.0", features = ["feature-name"] } ``` - `multi-worker`: Starts a worker thread for each CPU core available on the system within the `tokio` runtime. By default, the `tokio` runtime uses only one thread. Enabling this feature allows the `tokio` runtime to utilize all the cores on your computer. This feature does not affect applications on the web platform. -- `show-backtrace`: Prints the full backtrace in the CLI when a panic occurs in debug mode. This feature does not affect debugging on the web platform. +- `show-backtrace`: Prints the full backtrace in the CLI when a panic occurs in debug mode. In general, backtrace is not very helpful when debugging async apps, so consider using [`tracing`](https://crates.io/crates/tracing) for logging purposes. Note that this feature does not affect debugging on the web platform. From 9aebf0a5e167308dfa9fed4fb7e6eca2ba249144 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 16 Jun 2024 20:53:23 +0900 Subject: [PATCH 4/5] Improve guides about `multi-worker` --- documentation/docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index 33a9cc20..eab38f96 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -25,5 +25,5 @@ rinf config rinf = { version = "0.0.0", features = ["feature-name"] } ``` -- `multi-worker`: Starts a worker thread for each CPU core available on the system within the `tokio` runtime. By default, the `tokio` runtime uses only one thread. Enabling this feature allows the `tokio` runtime to utilize all the cores on your computer. This feature does not affect applications on the web platform. +- `multi-worker`: Starts a worker thread for each CPU core available on the system within the `tokio` runtime by enabling its `rt-multi-thread` feature. By default, the `tokio` runtime uses only one thread. Enabling this feature allows the `tokio` runtime to utilize all the cores on your computer. This feature does not affect applications on the web platform. - `show-backtrace`: Prints the full backtrace in the CLI when a panic occurs in debug mode. In general, backtrace is not very helpful when debugging async apps, so consider using [`tracing`](https://crates.io/crates/tracing) for logging purposes. Note that this feature does not affect debugging on the web platform. From 1705de320a22c28a8eb12f6824f97664572db0a1 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 16 Jun 2024 20:57:21 +0900 Subject: [PATCH 5/5] Add a sentence in the docs --- documentation/docs/configuration.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index eab38f96..692c3cec 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -21,6 +21,8 @@ rinf config ## 📦 Crate Features +Customizing the behavior of the Rinf crate is possible through its crate features. + ```toml title="native/hub/Cargo.toml" rinf = { version = "0.0.0", features = ["feature-name"] } ```