Skip to content

Commit

Permalink
make cargo codegen work irrelevant of CWD
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Aug 4, 2023
1 parent d74fbf9 commit 2516d23
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 2516d23

Please sign in to comment.