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

Treat backtrace as an optional feature #376

Merged
merged 5 commits into from
Jun 16, 2024
Merged
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
5 changes: 4 additions & 1 deletion documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ 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"] }
```

- `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.
3 changes: 2 additions & 1 deletion rust_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 13 additions & 4 deletions rust_crate/src/interface_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down