From b5b55c43f7df5f46c0d64a5b857804d89f5f3ca9 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Sat, 18 Jul 2020 23:00:26 -0700 Subject: [PATCH] Add feature flag to enable all log levels in examples (#98) - Adds extra troubleshooting documentation to the README --- README.md | 21 +++++++++++++++++++++ examples/conway/Cargo.toml | 6 +++++- examples/invaders/Cargo.toml | 6 +++++- examples/minimal-sdl2/Cargo.toml | 8 ++++++-- examples/minimal-winit/Cargo.toml | 6 +++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e84033a..a551894 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,27 @@ requests a low power (aka integrated) GPU by default. If the examples are not wo You should also try to keep your graphics drivers up-to-date, especially if you have an old Intel integrated GPU. Keep in mind that some drivers and GPUs are EOL and will not be supported. +### Logging + +You may want to use the `RUST_LOG` environment variable (see [`env_logger`](https://docs.rs/env_logger) for full documentation) to gain additional insight while troubleshooting the examples. `RUST_LOG=trace` will spew all logs to `stderr` on debug builds: + +``` +$ RUST_LOG=trace cargo run --package minimal-winit +``` + +And also on release builds when default features are disabled: + +``` +$ cd examples/minimal-winit +$ RUST_LOG=trace cargo run --release --no-default-features +``` + +Alternatively, nightly Cargo allows using the `--no-default-features` flag directly from the top-level directory in combination with the unstable `-Zpackage-features` flag: + +``` +$ RUST_LOG=trace cargo run --release --package minimal-winit -Zpackage-features --no-default-features +``` + ## Comparison with `minifb` The [`minifb`](https://crates.io/crates/minifb) crate shares some similarities with `pixels`; it also allows rapid prototyping of 2D games and emulators. But it requires the use of its own window/GUI management, event loop, and input handling. One of the disadvantages with the `minifb` approach is the lack of hardware acceleration (except on macOS, which uses Metal but is not configurable). An advantage is that it relies on fewer dependencies. diff --git a/examples/conway/Cargo.toml b/examples/conway/Cargo.toml index d79d874..a0d8bbf 100644 --- a/examples/conway/Cargo.toml +++ b/examples/conway/Cargo.toml @@ -5,12 +5,16 @@ authors = ["Jay Oster "] edition = "2018" publish = false +[features] +optimize = ["log/release_max_level_warn"] +default = ["optimize"] + [dependencies] byteorder = "1.3.4" env_logger = "0.7.1" getrandom = "0.1.14" line_drawing = "0.8.0" -log = { version = "0.4.8", features = [ "release_max_level_warn" ] } +log = "0.4.8" pixels = { path = "../.." } randomize = "3.0.1" winit = "0.22.0" diff --git a/examples/invaders/Cargo.toml b/examples/invaders/Cargo.toml index 635f5a5..029cae1 100644 --- a/examples/invaders/Cargo.toml +++ b/examples/invaders/Cargo.toml @@ -5,12 +5,16 @@ authors = ["Jay Oster "] edition = "2018" publish = false +[features] +optimize = ["log/release_max_level_warn"] +default = ["optimize"] + [dependencies] byteorder = "1.3.4" env_logger = "0.7.1" getrandom = "0.1.14" gilrs = "0.7.4" -log = { version = "0.4.8", features = [ "release_max_level_warn" ] } +log = "0.4.8" pixels = { path = "../.." } randomize = "3.0.1" simple-invaders = { path = "simple-invaders" } diff --git a/examples/minimal-sdl2/Cargo.toml b/examples/minimal-sdl2/Cargo.toml index e089d9b..c896857 100644 --- a/examples/minimal-sdl2/Cargo.toml +++ b/examples/minimal-sdl2/Cargo.toml @@ -5,8 +5,12 @@ authors = ["Jay Oster "] edition = "2018" publish = false +[features] +optimize = ["log/release_max_level_warn"] +default = ["optimize"] + [dependencies] -beryllium = { version = "0.2.1", features = [ "extern_crate_raw_window_handle" ] } +beryllium = { version = "0.2.1", features = ["extern_crate_raw_window_handle"] } env_logger = "0.7.1" -log = { version = "0.4.8", features = [ "release_max_level_warn" ] } +log = "0.4.8" pixels = { path = "../.." } diff --git a/examples/minimal-winit/Cargo.toml b/examples/minimal-winit/Cargo.toml index 8eda3f5..7acbc4e 100644 --- a/examples/minimal-winit/Cargo.toml +++ b/examples/minimal-winit/Cargo.toml @@ -5,9 +5,13 @@ authors = ["Jay Oster "] edition = "2018" publish = false +[features] +optimize = ["log/release_max_level_warn"] +default = ["optimize"] + [dependencies] env_logger = "0.7.1" -log = { version = "0.4.8", features = [ "release_max_level_warn" ] } +log = "0.4.8" pixels = { path = "../.." } winit = "0.22.0" winit_input_helper = "0.6.0"