Skip to content

Commit

Permalink
Improve CI, fix doclinks (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored Jul 31, 2024
1 parent 8ac2733 commit da8923d
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ concurrency:
cancel-in-progress: true

name: CI

env:
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

jobs:
lint:
name: Lint
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copied from https://github.com/rerun-io/rerun_template

# https://github.com/crate-ci/typos
# Add exceptions to `.typos.toml`
# install and run locally: cargo install typos-cli && typos

name: Spell Check
on: [pull_request]

jobs:
run:
name: Spell Check
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling of entire workspace
uses: crate-ci/typos@master
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/target/
**/*.rs.bk
**/target_ra/
**/target/
6 changes: 6 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://github.com/crate-ci/typos
# install: cargo install typos-cli
# run: typos

[default.extend-words]
ba = "ba" # Used in a test
117 changes: 85 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,93 @@ license = "MIT OR Apache-2.0"
rust-version = "1.76"

[workspace.lints.rust]
elided_lifetimes_in_paths = "warn"
future_incompatible = "warn"
nonstandard_style = "warn"
rust_2018_idioms = "warn"
rust_2021_prelude_collisions = "warn"
semicolon_in_expressions_from_macros = "warn"
trivial_numeric_casts = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_extern_crates = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"

[workspace.lints.rustdoc]
all = "warn"
missing_crate_level_docs = "warn"

[workspace.lints.clippy]
all = "warn"

as_ptr_cast_mut = "warn"
await_holding_lock = "warn"
bool_to_int_with_if = "warn"
branches_sharing_code = "warn"
cast_lossless = "warn"
char_lit_as_u8 = "warn"
checked_conversions = "warn"
clear_with_drain = "warn"
cloned_instead_of_copied = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
default_union_representation = "warn"
derive_partial_eq_without_eq = "warn"
disallowed_macros = "warn"
disallowed_methods = "warn"
disallowed_names = "warn"
disallowed_script_idents = "warn"
disallowed_types = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
empty_enum = "warn"
empty_line_after_outer_attr = "warn"
enum_glob_use = "warn"
equatable_if_let = "warn"
exit = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
fn_to_numeric_cast_any = "warn"
from_iter_instead_of_collect = "warn"
get_unwrap = "warn"
if_let_mutex = "warn"
implicit_clone = "warn"
implied_bounds_in_impls = "warn"
imprecise_flops = "warn"
index_refutable_slice = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
iter_not_returning_iterator = "warn"
iter_on_empty_collections = "warn"
iter_on_single_items = "warn"
iter_over_hash_type = "warn"
iter_without_into_iter = "warn"
large_digit_groups = "warn"
large_include_file = "warn"
large_stack_arrays = "warn"
large_stack_frames = "warn"
large_types_passed_by_value = "warn"
let_underscore_must_use = "warn"
let_underscore_untyped = "warn"
let_unit_value = "warn"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
manual_assert = "warn"
manual_clamp = "warn"
manual_instant_elapsed = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
map_err_ignore = "warn"
map_flatten = "warn"
map_unwrap_or = "warn"
Expand All @@ -59,68 +104,76 @@ match_wild_err_arm = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mismatched_target_os = "warn"
mismatching_type_param_order = "warn"
missing_assert_message = "warn"
missing_enforced_import_renames = "warn"
missing_errors_doc = "warn"
missing_safety_doc = "warn"
mod_module_files = "warn"
mut_mut = "warn"
mutex_integer = "warn"
needless_borrow = "warn"
needless_continue = "warn"
needless_for_each = "warn"
needless_pass_by_ref_mut = "warn"
needless_pass_by_value = "warn"
negative_feature_names = "warn"
nonstandard_macro_braces = "warn"
option_option = "warn"
path_buf_push_overwrite = "warn"
print_stderr = "warn"
print_stdout = "warn"
ptr_as_ptr = "warn"
ptr_cast_constness = "warn"
pub_without_shorthand = "warn"
rc_mutex = "warn"
readonly_write_lock = "warn"
redundant_type_annotations = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
semicolon_if_nothing_returned = "warn"
should_panic_without_expect = "warn"
significant_drop_tightening = "warn"
single_match_else = "warn"
string_add_assign = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_lit_chars_any = "warn"
string_to_string = "warn"
suspicious_command_arg_space = "warn"
suspicious_xor_used_as_pow = "warn"
todo = "warn"
unimplemented = "warn"
unnecessary_box_returns = "warn"
unnested_or_patterns = "warn"
unused_self = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
zero_sized_map_values = "warn"

branches_sharing_code = "warn"
cast_lossless = "warn"
default_union_representation = "warn"
disallowed_script_idents = "warn"
doc_link_with_quotes = "warn"
empty_line_after_outer_attr = "warn"
equatable_if_let = "warn"
fn_to_numeric_cast_any = "warn"
implied_bounds_in_impls = "warn"
index_refutable_slice = "warn"
iter_not_returning_iterator = "warn"
large_include_file = "warn"
manual_instant_elapsed = "warn"
manual_let_else = "warn"
mod_module_files = "warn"
needless_pass_by_ref_mut = "warn"
negative_feature_names = "warn"
nonstandard_macro_braces = "warn"
print_stderr = "warn"
print_stdout = "warn"
readonly_write_lock = "warn"
should_panic_without_expect = "warn"
string_lit_chars_any = "warn"
too_many_lines = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_ptr_to_ptr = "warn"
tuple_array_conversions = "warn"
unchecked_duration_subtraction = "warn"
undocumented_unsafe_blocks = "warn"
unimplemented = "warn"
uninhabited_references = "warn"
uninlined_format_args = "warn"
unnecessary_box_returns = "warn"
unnecessary_safety_comment = "warn"
unnecessary_safety_doc = "warn"
unnecessary_self_imports = "warn"
unnecessary_struct_initialization = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
unused_self = "warn"
unwrap_used = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
wildcard_dependencies = "warn"
wildcard_enum_match_arm = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"

[patch.crates-io]
# eframe = { git = "https://github.com/emilk/egui.git", rev = "44ff29b01237975313606b91e7f3808e49d36d69" } # egui master 2023-11-19
Expand Down
4 changes: 3 additions & 1 deletion puffin/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const SCOPE_END: u8 = b')';
/// Used when parsing a Stream.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ScopeRecord<'s> {
/// The start oif this scope in nanoseconds.
/// The start of this scope in nanoseconds.
pub start_ns: NanoSecond,

/// The duration of this scope in nanoseconds.
pub duration_ns: NanoSecond,

/// e.g. function argument, like a mesh name. Optional.
/// Example: "image.png".
pub data: &'s str,
Expand Down
3 changes: 3 additions & 0 deletions puffin/src/frame_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl FrameDataState {
}
}

#[cfg(not(target_arch = "wasm32"))] // compression not supported on wasm
fn packed(&self) -> Option<&PackedStreams> {
match self {
FrameDataState::Unpacked(_) => None,
Expand All @@ -420,6 +421,7 @@ impl FrameDataState {
}
}

#[cfg(not(target_arch = "wasm32"))] // compression not supported on wasm
fn pack_and_keep(&mut self) {
if let FrameDataState::Unpacked(ref unpacked) = *self {
let packed = PackedStreams::pack(&unpacked.thread_streams);
Expand Down Expand Up @@ -549,6 +551,7 @@ impl FrameData {
}

/// Create a packed storage without freeing the unpacked storage.
#[cfg(not(target_arch = "wasm32"))] // compression not supported on wasm
fn create_packed(&self) {
self.data.write().pack_and_keep();
}
Expand Down
2 changes: 1 addition & 1 deletion puffin/src/global_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl GlobalProfiler {
new_scope_ids
}

/// Reports some profiling data. Called from [`ThreadProfiler`].
/// Reports some profiling data. Called from [`crate::ThreadProfiler`].
pub fn report(
&mut self,
info: ThreadInfo,
Expand Down
2 changes: 1 addition & 1 deletion puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use global_profiler::{FrameSink, GlobalProfiler};
pub use merge::{merge_scopes_for_thread, MergeScope};
pub use profile_view::{select_slowest, FrameStats, FrameView, GlobalFrameView};
pub use scope_details::{ScopeCollection, ScopeDetails, ScopeType};
pub use thread_profiler::{ThreadInfo, ThreadProfiler};
pub use thread_profiler::{internal_profile_reporter, ThreadInfo, ThreadProfiler};
pub use utils::{clean_function_name, short_file_name, shorten_rust_function_name, type_name_of};

static MACROS_ON: AtomicBool = AtomicBool::new(false);
Expand Down
2 changes: 1 addition & 1 deletion puffin/src/profile_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl FrameView {
self.pack_frames
}

/// Sets wether frames should be packed (compressed).
/// Sets whether frames should be packed (compressed).
/// Packing frames will increase CPU time and decrease memory usage.
pub fn set_pack_frames(&mut self, pack_frames: bool) {
self.pack_frames = pack_frames;
Expand Down
8 changes: 4 additions & 4 deletions puffin/src/thread_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::StreamInfoRef;

/// Report a stream of profile data from a thread to the [`GlobalProfiler`] singleton.
/// This is used for internal purposes only
pub(crate) fn internal_profile_reporter(
pub fn internal_profile_reporter(
info: ThreadInfo,
scope_details: &[ScopeDetails],
stream_scope_times: &StreamInfoRef<'_>,
Expand Down Expand Up @@ -47,10 +47,10 @@ impl Default for ThreadProfiler {
impl ThreadProfiler {
/// Explicit initialize with custom callbacks.
///
/// If not called, each thread will use the default nanosecond source ([`now_ns()`])
/// and report scopes to the global profiler ([`internal_profile_reporter()`]).
/// If not called, each thread will use the default nanosecond source ([`crate::now_ns`])
/// and report scopes to the global profiler ([`internal_profile_reporter`]).
///
/// For instance, when compiling for WASM the default timing function ([`now_ns()`]) won't work,
/// For instance, when compiling for WASM the default timing function ([`crate::now_ns`]) won't work,
/// so you'll want to call `puffin::ThreadProfiler::initialize(my_timing_function, internal_profile_reporter);`.
pub fn initialize(now_ns: NsSource, reporter: ThreadReporter) {
ThreadProfiler::call(|tp| {
Expand Down
2 changes: 1 addition & 1 deletion puffin_egui/src/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub fn ui(
ui.label("Grid spacing:");
let grid_spacing_drag = DragValue::new(&mut options.grid_spacing_micros)
.speed(0.1)
.clamp_range(1.0..=100.0)
.range(1.0..=100.0)
.suffix(" µs");
grid_spacing_drag.ui(ui);
});
Expand Down
16 changes: 8 additions & 8 deletions puffin_http/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context as _;
use puffin::{FrameView, GlobalProfiler};
use puffin::{FrameSinkId, FrameView, GlobalProfiler};
use std::{
io::Write,
net::{SocketAddr, TcpListener, TcpStream},
Expand All @@ -18,21 +18,21 @@ const MAX_FRAMES_IN_QUEUE: usize = 30;
/// Drop to stop transmitting and listening for new connections.
#[must_use = "When Server is dropped, the server is closed, so keep it around!"]
pub struct Server {
sink_id: puffin::FrameSinkId,
sink_id: FrameSinkId,
join_handle: Option<std::thread::JoinHandle<()>>,
num_clients: Arc<AtomicUsize>,
sink_remove: fn(puffin::FrameSinkId) -> (),
sink_remove: fn(FrameSinkId) -> (),
}

impl Server {
/// Start listening for connections on this addr (e.g. "0.0.0.0:8585")
///
/// Connects to the [GlobalProfiler]
pub fn new(bind_addr: &str) -> anyhow::Result<Self> {
fn global_add(sink: puffin::FrameSink) -> puffin::FrameSinkId {
fn global_add(sink: puffin::FrameSink) -> FrameSinkId {
GlobalProfiler::lock().add_sink(sink)
}
fn global_remove(id: puffin::FrameSinkId) {
fn global_remove(id: FrameSinkId) {
GlobalProfiler::lock().remove_sink(id);
}

Expand All @@ -45,7 +45,7 @@ impl Server {
/// * `bind_addr` - The address to bind to, when listening for connections
/// (e.g. "localhost:8585" or "127.0.0.1:8585")
/// * `sink_install` - A function that installs the [Server]'s sink into
/// a [GlobalProfiler], and then returns the [FrameSinkId] so that the sink can be removed later
/// a [`GlobalProfiler`], and then returns the [`FrameSinkId`] so that the sink can be removed later
/// * `sink_remove` - A function that reverts `sink_install`.
/// This should be a call to remove the sink from the profiler ([GlobalProfiler::remove_sink])
///
Expand Down Expand Up @@ -223,8 +223,8 @@ impl Server {
/// ```
pub fn new_custom(
bind_addr: &str,
sink_install: fn(puffin::FrameSink) -> puffin::FrameSinkId,
sink_remove: fn(puffin::FrameSinkId) -> (),
sink_install: fn(puffin::FrameSink) -> FrameSinkId,
sink_remove: fn(FrameSinkId) -> (),
) -> anyhow::Result<Self> {
let tcp_listener = TcpListener::bind(bind_addr).context("binding server TCP socket")?;
tcp_listener
Expand Down

0 comments on commit da8923d

Please sign in to comment.