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

Combine all Rust code-examples into one binary #4767

Merged
merged 15 commits into from
Jan 10, 2024
Merged
4 changes: 4 additions & 0 deletions .github/workflows/contrib_rerun_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: prefix-dev/[email protected]
with:
pixi-version: v0.6.0

# These should already be in the docker container, but run for good measure. A no-op install
# should be fast, and this way things don't break if we add new packages without rebuilding
# docker
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/reusable_test_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ jobs:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}

- uses: prefix-dev/[email protected]
with:
pixi-version: v0.6.0

# The pip-cache setup logic doesn't work in the ubuntu docker container
# That's probably fine since we bake these deps into the container already
- name: Setup python
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/re_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
//!
//! ### Examples
//!
//! You can add an example to `docs/code-examples`, and then include its source code in
//! You can add an example to `docs/code-examples/all`, and then include its source code in
//! the docs using the `\example` tag. The example will also be included in the list of
//! examples for type's generated docs.
//!
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/bin/build_re_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use camino::Utf8Path;
const RE_TYPES_SOURCE_HASH_PATH: &str = "crates/re_types/source_hash.txt";
const DEFINITIONS_DIR_PATH: &str = "crates/re_types/definitions";
const ENTRYPOINT_PATH: &str = "crates/re_types/definitions/rerun/archetypes.fbs";
const DOC_EXAMPLES_DIR_PATH: &str = "docs/code-examples";
const DOC_EXAMPLES_DIR_PATH: &str = "docs/code-examples/all";
const CPP_OUTPUT_DIR_PATH: &str = "rerun_cpp";
const PYTHON_OUTPUT_DIR_PATH: &str = "rerun_py/rerun_sdk/rerun";
const PYTHON_TESTING_OUTPUT_DIR_PATH: &str = "rerun_py/tests/test_types";
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn collect_examples_for_api_docs<'a>(
let mut out = Vec::new();

if let Some(examples) = docs.tagged_docs.get("example") {
let base_path = crate::rerun_workspace_path().join("docs/code-examples");
let base_path = crate::rerun_workspace_path().join("docs/code-examples/all");

for base @ ExampleInfo {
name,
Expand Down
11 changes: 6 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ The site documentation lives in Markdown files inside [`/content`](./content).

The entry point to the documentation is [`/content/index.md`](./content/index.md)

Code examples can be rendered in multiple languages by placing them in `code-examples`, like so:
Code examples can be rendered in multiple languages by placing them in `code-examples/all`, like so:

```
/docs
/code-examples
/my-example
/example.py
/example.rs
/code-examples
/all
/my-example
/example.py
/example.rs
```

## Special syntax
Expand Down
4 changes: 2 additions & 2 deletions docs/code-examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.16...3.27)

# Setup builds for examples
file(GLOB sources_list true ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB sources_list true ${CMAKE_CURRENT_SOURCE_DIR}/all/*.cpp)

# TODO(ab): incomplete code, need hideable stubs, see https://github.com/rerun-io/landing/issues/515
list(REMOVE_ITEM sources_list ${CMAKE_CURRENT_SOURCE_DIR}/timelines_example.cpp)
list(REMOVE_ITEM sources_list ${CMAKE_CURRENT_SOURCE_DIR}/all/timelines_example.cpp)

add_custom_target(doc_examples)

Expand Down
186 changes: 5 additions & 181 deletions docs/code-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,188 +6,12 @@ rust-version.workspace = true
license.workspace = true
publish = false


[[bin]]
name = "annotation_context_connections"
path = "annotation_context_connections.rs"

[[bin]]
name = "annotation_context_rects"
path = "annotation_context_rects.rs"

[[bin]]
name = "annotation_context_segmentation"
path = "annotation_context_segmentation.rs"

[[bin]]
name = "arrow2d_simple"
path = "arrow2d_simple.rs"

[[bin]]
name = "arrow3d_simple"
path = "arrow3d_simple.rs"

[[bin]]
name = "bar_chart"
path = "bar_chart.rs"

[[bin]]
name = "asset3d_simple"
path = "asset3d_simple.rs"

[[bin]]
name = "asset3d_out_of_tree"
path = "asset3d_out_of_tree.rs"

[[bin]]
name = "box2d_simple"
path = "box2d_simple.rs"

[[bin]]
name = "box3d_simple"
path = "box3d_simple.rs"

[[bin]]
name = "box3d_batch"
path = "box3d_batch.rs"

[[bin]]
name = "clear_recursive"
path = "clear_recursive.rs"

[[bin]]
name = "clear_simple"
path = "clear_simple.rs"

[[bin]]
name = "custom_data"
path = "custom_data.rs"

[[bin]]
name = "depth_image_3d"
path = "depth_image_3d.rs"

[[bin]]
name = "depth_image_simple"
path = "depth_image_simple.rs"

[[bin]]
name = "disconnected_space"
path = "disconnected_space.rs"

[[bin]]
name = "entity_path"
path = "entity_path.rs"

[[bin]]
name = "image_simple"
path = "image_simple.rs"

[[bin]]
name = "line_segments2d_simple"
path = "line_segments2d_simple.rs"

[[bin]]
name = "line_segments3d_simple"
path = "line_segments3d_simple.rs"

[[bin]]
name = "line_strip2d_simple"
path = "line_strip2d_simple.rs"

[[bin]]
name = "line_strip2d_batch"
path = "line_strip2d_batch.rs"

[[bin]]
name = "line_strip3d_simple"
path = "line_strip3d_simple.rs"

[[bin]]
name = "line_strip3d_batch"
path = "line_strip3d_batch.rs"

[[bin]]
name = "manual_indicator"
path = "manual_indicator.rs"

[[bin]]
name = "mesh3d_simple"
path = "mesh3d_simple.rs"

[[bin]]
name = "mesh3d_indexed"
path = "mesh3d_indexed.rs"

[[bin]]
name = "mesh3d_partial_updates"
path = "mesh3d_partial_updates.rs"

[[bin]]
name = "pinhole_simple"
path = "pinhole_simple.rs"

[[bin]]
name = "point2d_simple"
path = "point2d_simple.rs"

[[bin]]
name = "point2d_random"
path = "point2d_random.rs"

[[bin]]
name = "point3d_random"
path = "point3d_random.rs"

[[bin]]
name = "point3d_simple"
path = "point3d_simple.rs"

[[bin]]
name = "quick_start_connect"
path = "quick_start_connect.rs"

[[bin]]
name = "quick_start_spawn"
path = "quick_start_spawn.rs"

[[bin]]
name = "scalar_simple"
path = "scalar_simple.rs"

[[bin]]
name = "scalar_multiple_plots"
path = "scalar_multiple_plots.rs"

[[bin]]
name = "segmentation_image_simple"
path = "segmentation_image_simple.rs"

[[bin]]
name = "tensor_simple"
path = "tensor_simple.rs"

[[bin]]
name = "text_document"
path = "text_document.rs"

[[bin]]
name = "text_log"
path = "text_log.rs"

[[bin]]
name = "text_log_integration"
path = "text_log_integration.rs"

[[bin]]
name = "transform3d_simple"
path = "transform3d_simple.rs"

[[bin]]
name = "view_coordinates_simple"
path = "view_coordinates_simple.rs"

[dependencies]
ndarray.workspace = true
rand.workspace = true
rerun = { path = "../../crates/rerun" }

[build-dependencies]
itertools.workspace = true
re_build_tools.workspace = true
rust-format.workspace = true
9 changes: 3 additions & 6 deletions docs/code-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Most of these examples are automatically used as docstrings for the `Archetype`
You can run each example individually using the following:

- **C++**:
- `pixi run cpp-build-examples` to compile all examples
- `./build/docs/code-examples/<example_name>` to run, e.g. `./build/docs/code-examples/point3d_random`
- `pixi run cpp-build-doc-examples` to compile all examples
- `./build/docs/code-examples/all/<example_name>` to run, e.g. `./build/docs/code-examples/all/point3d_random`
- **Python**: `python <example_name>.py`, e.g. `python point3d_random.py`.
- **Rust**: `cargo r -p code_examples --bin <example_name`, e.g. `cargo r -p code_examples --bin point3d_random`.
- **Rust**: `cargo run -p code_examples -- <example_name> [args]`, e.g. `cargo run -p code_examples -- point3d_random`.

## Roundtrips

Expand All @@ -31,6 +31,3 @@ To run the roundtrip tests, check out `./docs/code-examples/roundtrips.py --help
Just pick a name for your test, and look at existing examples to get started. The `app_id` must be `rerun_example_<test_name>`.

The roundtrip process is driven by file names, so make sure all 3 tests use the same name: `<test_name>.rs`, `<test_name>.cpp`, `<test_name>.py`.

For Rust, also make sure to declare the new binary in `docs/code-examples/Cargo.toml`.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading