Skip to content

Commit

Permalink
Make cargo codegen work irrelevant of CWD (#2913)
Browse files Browse the repository at this point in the history
What the title says.

### What

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2913) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2913)
- [Docs
preview](https://rerun.io/preview/pr%3Acmc%2Fcargo_codegen_anywhere/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Acmc%2Fcargo_codegen_anywhere/examples)
  • Loading branch information
teh-cmc authored Aug 7, 2023
1 parent ac8bc41 commit 250ebed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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.

21 changes: 17 additions & 4 deletions crates/re_types_builder/src/bin/build_re_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Helper binary for running the codegen manually. Useful during development!
use camino::Utf8Path;

const DEFINITIONS_DIR_PATH: &str = "crates/re_types/definitions";
const ENTRYPOINT_PATH: &str = "crates/re_types/definitions/rerun/archetypes.fbs";
const CPP_OUTPUT_DIR_PATH: &str = "rerun_cpp/src/rerun";
Expand All @@ -25,17 +27,28 @@ fn main() {
}
}

let workspace_dir = Utf8Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(|p| p.parent())
.unwrap();

let definitions_dir_path = workspace_dir.join(DEFINITIONS_DIR_PATH);
let entrypoint_path = workspace_dir.join(ENTRYPOINT_PATH);
let cpp_output_dir_path = workspace_dir.join(CPP_OUTPUT_DIR_PATH);
let rust_output_dir_path = workspace_dir.join(RUST_OUTPUT_DIR_PATH);
let python_output_dir_path = workspace_dir.join(PYTHON_OUTPUT_DIR_PATH);

re_log::info!("Running codegen…");
let (objects, arrow_registry) =
re_types_builder::generate_lang_agnostic(DEFINITIONS_DIR_PATH, ENTRYPOINT_PATH);
re_types_builder::generate_lang_agnostic(definitions_dir_path, entrypoint_path);

re_tracing::profile_scope!("Language-specific code-gen");
join3(
|| re_types_builder::generate_cpp_code(CPP_OUTPUT_DIR_PATH, &objects, &arrow_registry),
|| re_types_builder::generate_rust_code(RUST_OUTPUT_DIR_PATH, &objects, &arrow_registry),
|| re_types_builder::generate_cpp_code(cpp_output_dir_path, &objects, &arrow_registry),
|| re_types_builder::generate_rust_code(rust_output_dir_path, &objects, &arrow_registry),
|| {
re_types_builder::generate_python_code(
PYTHON_OUTPUT_DIR_PATH,
python_output_dir_path,
&objects,
&arrow_registry,
);
Expand Down

0 comments on commit 250ebed

Please sign in to comment.