Skip to content

Commit

Permalink
Merge branch 'main' into jleibs/batch_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jul 26, 2023
2 parents 76a3ed1 + b0a1793 commit c3622ac
Show file tree
Hide file tree
Showing 134 changed files with 3,311 additions and 429 deletions.
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ BasedOnStyle: Google
# Make it slightly more similar to Rust.
# Based loosely on https://gist.github.com/YodaEmbedding/c2c77dc693d11f3734d78489f9a6eea4
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
Expand All @@ -19,9 +21,9 @@ InsertTrailingCommas: Wrapped
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: true
SeparateDefinitionBlocks: Always
SpacesBeforeTrailingComments: 1
ReflowComments: true

# Don't change include blocks, we want to control this manually.
# Sorting headers however is allowed as all our headers should be standalone.
Expand Down
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions crates/re_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ glam = ["re_components/glam"]
## Integration with the [`image`](https://crates.io/crates/image/) crate, plus JPEG support..
image = ["re_components/image"]

## Support serving a web viewer over HTTP.
##
## Enabling this inflates the binary size quite a bit, since it embeds the viewer wasm.
##
## For faster & easier builds, the web-player build comes bundled with the crate.
## Enabling this feature will embed this pre-built web-player.
##
## However, when building from source in the repository, this feature adds quite a bit
## to the compile time since it requires compiling and bundling the viewer as wasm.
## You also need to install some additional tools, which you can do by running
## [`scripts/setup_web.sh`](https://github.com/rerun-io/rerun/blob/main/scripts/setup_web.sh).
web_viewer = [
"dep:re_smart_channel",
"dep:re_web_viewer_server",
"dep:re_ws_comms",
"dep:anyhow",
"dep:webbrowser",
"re_ws_comms?/server",
]


[dependencies]
re_build_info.workspace = true
Expand All @@ -48,6 +68,15 @@ once_cell.workspace = true
parking_lot.workspace = true
thiserror.workspace = true

# Optional dependencies

re_smart_channel = { workspace = true, optional = true }
re_ws_comms = { workspace = true, optional = true }
re_web_viewer_server = { workspace = true, optional = true }

anyhow = { workspace = true, optional = true }
webbrowser = { version = "0.8", optional = true }


[dev-dependencies]
re_components = { workspace = true, features = ["arrow_datagen"] }
Expand Down
4 changes: 4 additions & 0 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub mod experimental {
pub use re_types::{archetypes, components, datatypes, Archetype, Component, Datatype};
}

/// Methods for spawning the web viewer and streaming the SDK log stream to it.
#[cfg(feature = "web_viewer")]
pub mod web_viewer;

/// Re-exports of other crates.
pub mod external {
pub use re_log;
Expand Down
56 changes: 56 additions & 0 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use re_log_types::{
TimePoint, TimeType, Timeline, TimelineName,
};

#[cfg(feature = "web_viewer")]
use re_web_viewer_server::WebViewerServerPort;
#[cfg(feature = "web_viewer")]
use re_ws_comms::RerunServerPort;

use crate::sink::{LogSink, MemorySinkStorage};

// ---
Expand All @@ -31,6 +36,10 @@ pub enum RecordingStreamError {
name: &'static str,
err: Box<dyn std::error::Error + Send + Sync>,
},

#[cfg(feature = "web_viewer")]
#[error(transparent)]
WebSink(anyhow::Error),
}

pub type RecordingStreamResult<T> = Result<T, RecordingStreamError>;
Expand Down Expand Up @@ -259,6 +268,53 @@ impl RecordingStreamBuilder {
}
}

/// Creates a new [`RecordingStream`] that is pre-configured to stream the data through to a
/// web-based Rerun viewer via WebSockets.
///
/// This method needs to be called in a context where a Tokio runtime is already running (see
/// example below).
///
/// If the `open_browser` argument is `true`, your default browser will be opened with a
/// connected web-viewer.
///
/// If not, you can connect to this server using the `rerun` binary (`cargo install rerun-cli`).
///
/// ## Example
///
/// ```ignore
/// // Ensure we have a running tokio runtime.
/// let mut tokio_runtime = None;
/// let tokio_runtime_handle = if let Ok(handle) = tokio::runtime::Handle::try_current() {
/// handle
/// } else {
/// let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
/// tokio_runtime.get_or_insert(rt).handle().clone()
/// };
/// let _tokio_runtime_guard = tokio_runtime_handle.enter();
///
/// let rec_stream = re_sdk::RecordingStreamBuilder::new("my_app")
/// .serve("0.0.0.0", Default::default(), Default::default(), true)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[cfg(feature = "web_viewer")]
pub fn serve(
self,
bind_ip: &str,
web_port: WebViewerServerPort,
ws_port: RerunServerPort,
open_browser: bool,
) -> RecordingStreamResult<RecordingStream> {
let (enabled, store_info, batcher_config) = self.into_args();
if enabled {
let sink = crate::web_viewer::new_sink(open_browser, bind_ip, web_port, ws_port)
.map_err(RecordingStreamError::WebSink)?;
RecordingStream::new(store_info, batcher_config, sink)
} else {
re_log::debug!("Rerun disabled - call to serve() ignored");
Ok(RecordingStream::disabled())
}
}

/// Returns whether or not logging is enabled, a [`StoreInfo`] and the associated batcher
/// configuration.
///
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions crates/re_types/definitions/rerun/components/instance_key.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct InstanceKey (
"attr.python.array_aliases": "int, npt.NDArray[np.uint64]",
"attr.rerun.legacy_fqname": "rerun.instance_key",
"attr.rust.derive": "Copy, Hash, PartialEq, Eq, PartialOrd, Ord",
"attr.rust.custom_clause":
'cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))',
order: 100
) {
value: uint64 (order: 100);
Expand Down
6 changes: 6 additions & 0 deletions crates/re_types/definitions/rust/attributes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ attribute "attr.rust.tuple_struct";
/// E.g. "attr.rust.derive": "Copy"`.
attribute "attr.rust.derive";

/// Apply to any object to generate an arbitrary clause.
///
/// The value of the attribute will be trimmed out but otherwise left as-is.
/// E.g. "attr.rust.custom_clause": "cfg_attr(feature = "serde", derive(::serde::Serialize))"`.
attribute "attr.rust.custom_clause";

/// Apply to any object to generate a #repr clause with the specified value.
attribute "attr.rust.repr";
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_types/src/components/instance_key.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions crates/re_types/src/components/instance_key_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,3 @@ impl std::fmt::Display for InstanceKey {
}
}
}

// TODO(jleibs): allow cfg_attr for codegen

#[cfg(feature = "serde")]
impl serde::Serialize for InstanceKey {
#[inline]
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for InstanceKey {
#[inline]
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
u64::deserialize(deserializer).map(Self::from)
}
}
1 change: 1 addition & 0 deletions crates/re_types_builder/src/codegen/cpp/forward_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct ForwardDecls {
}

impl ForwardDecls {
#[allow(dead_code)]
pub fn insert(&mut self, namespace: impl Into<String>, decl: ForwardDecl) {
self.declarations_per_namespace
.entry(namespace.into())
Expand Down
6 changes: 4 additions & 2 deletions crates/re_types_builder/src/codegen/cpp/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::quote;

use crate::Docs;

use super::{doc_comment, quote_docstrings, NEWLINE_TOKEN};
use super::{quote_doc_comment, quote_docstrings, NEWLINE_TOKEN};

#[derive(Default)]
pub struct MethodDeclaration {
Expand Down Expand Up @@ -82,7 +82,7 @@ impl quote::ToTokens for MethodDocumentation {
match self {
Self::None => {}
Self::String(s) => {
tokens.extend(doc_comment(s));
tokens.extend(quote_doc_comment(s));
}
Self::Docs(docs) => tokens.extend(quote_docstrings(docs)),
}
Expand Down Expand Up @@ -125,12 +125,14 @@ impl Method {
#declaration {
#definition_body
}
#NEWLINE_TOKEN
}
} else {
quote! {
#NEWLINE_TOKEN
#docs
#declaration;
#NEWLINE_TOKEN
}
}
}
Expand Down
Loading

0 comments on commit c3622ac

Please sign in to comment.