Skip to content

Commit f292a5c

Browse files
authored
Do not run codegen in build.rs scripts (#3874)
### What Running codegen from our `build.rs` was a problem, because it required specific versions of specific tools to be installed (`clang-format`, `black`, etc). It is better to run the codegen with `just codegen`, which will ensure the correct tools are installed via `pixi`. With this PR you now have to run `just codegen` manually each time you change `re_types_builder` or any `.fbs`. If you forget to do so, the CI will catch it for you. This PR removes `crates/re_types/build.rs`, but does NOT touch `crates/re_types_builder/build.rs`. ### 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/3874) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/3874) - [Docs preview](https://rerun.io/preview/fdfd159d5b2d8f7a089d3b69d05b2a6c33c24a2b/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/fdfd159d5b2d8f7a089d3b69d05b2a6c33c24a2b/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
1 parent 9a4d833 commit f292a5c

File tree

8 files changed

+47
-164
lines changed

8 files changed

+47
-164
lines changed

.github/workflows/contrib_checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
uses: actions-rs/cargo@v1
9393
with:
9494
command: codegen
95+
args: --force
9596

9697
- name: No Diffs From Running Codegen
9798
run: |

.github/workflows/reusable_checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ jobs:
134134
uses: actions-rs/cargo@v1
135135
with:
136136
command: codegen
137+
args: --force
137138

138139
- name: No Diffs From Running Codegen
139140
run: |

crates/re_types/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ serde = ["dep:serde", "re_string_interner/serde"]
4545
## Only useful for testing purposes.
4646
testing = []
4747

48-
## Special hack!
49-
##
50-
## If you configure rust-analyzer to set `--all-features,
51-
## then this feature will be set and that will ensure that
52-
## `rust-analyzer` won't run the (expensive) `build.rs`!
53-
__opt_out_of_auto_rebuild = []
54-
5548

5649
[dependencies]
5750
# Rerun

crates/re_types/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.
1010
The standard Rerun data types, component types, and archetypes.
1111

1212
This crate includes both the language-agnostic definitions (flatbuffers IDL) as well as the generated code.
13+
14+
Generated the code with `just codegen`.

crates/re_types/build.rs

Lines changed: 0 additions & 135 deletions
This file was deleted.

crates/re_types_builder/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.
1010
This crate implements Rerun's code generation tools.
1111

1212
These tools translate language-agnostic IDL definitions (flatbuffers) into code.
13-
They are invoked from `re_types`' build script (`build.rs`).
13+
14+
You can generate the code with `just codegen`.

crates/re_types_builder/src/bin/build_re_types.rs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
//! Helper binary for running the codegen manually. Useful during development!
1+
//! This binary runs the codegen manually.
2+
//!
3+
//! It is easiest to call this using `just codegen`,
4+
//! which will set up the necessary tools.
25
3-
use camino::Utf8Path;
46
use re_build_tools::{
57
read_versioning_hash, set_output_cargo_build_instructions, write_versioning_hash,
68
};
7-
use re_types_builder::{compute_re_types_builder_hash, compute_re_types_hash, SourceLocations};
9+
use re_types_builder::{compute_re_types_hash, SourceLocations};
10+
11+
use camino::Utf8Path;
812

9-
const RE_TYPES_BUILDER_SOURCE_HASH_PATH: &str = "crates/re_types_builder/source_hash.txt";
1013
const RE_TYPES_SOURCE_HASH_PATH: &str = "crates/re_types/source_hash.txt";
1114
const DEFINITIONS_DIR_PATH: &str = "crates/re_types/definitions";
1215
const ENTRYPOINT_PATH: &str = "crates/re_types/definitions/rerun/archetypes.fbs";
@@ -31,6 +34,7 @@ macro_rules! join {
3134

3235
fn main() {
3336
re_log::setup_native_logging();
37+
3438
// This isn't a build.rs script, so opt out of cargo build instrctinsr
3539
set_output_cargo_build_instructions(false);
3640

@@ -40,13 +44,17 @@ fn main() {
4044
.unwrap();
4145

4246
let mut profiler = re_tracing::Profiler::default();
47+
let mut always_run = false;
4348

4449
for arg in std::env::args().skip(1) {
4550
match arg.as_str() {
4651
"--help" => {
47-
println!("Usage: [--help] [--profile]");
52+
println!("Usage: [--help] [--force] [--profile]");
4853
return;
4954
}
55+
"--force" => {
56+
always_run = true;
57+
}
5058
"--profile" => profiler.start(),
5159
_ => {
5260
eprintln!("Unknown argument: {arg:?}");
@@ -61,28 +69,41 @@ fn main() {
6169
.unwrap();
6270

6371
let re_types_source_hash_path = workspace_dir.join(RE_TYPES_SOURCE_HASH_PATH);
64-
let re_types_builder_source_hash_path = workspace_dir.join(RE_TYPES_BUILDER_SOURCE_HASH_PATH);
6572
let definitions_dir_path = workspace_dir.join(DEFINITIONS_DIR_PATH);
6673
let entrypoint_path = workspace_dir.join(ENTRYPOINT_PATH);
67-
let doc_examples_dir_path = workspace_dir.join(DOC_EXAMPLES_DIR_PATH);
6874
let cpp_output_dir_path = workspace_dir.join(CPP_OUTPUT_DIR_PATH);
6975
let rust_output_dir_path = workspace_dir.join(RUST_OUTPUT_DIR_PATH);
7076
let python_output_dir_path = workspace_dir.join(PYTHON_OUTPUT_DIR_PATH);
7177
let python_testing_output_dir_path = workspace_dir.join(PYTHON_TESTING_OUTPUT_DIR_PATH);
7278
let docs_content_dir_path = workspace_dir.join(DOCS_CONTENT_DIR_PATH);
7379

7480
let cur_hash = read_versioning_hash(&re_types_source_hash_path);
75-
eprintln!("cur_hash: {cur_hash:?}");
76-
77-
let builder_hash = compute_re_types_builder_hash();
81+
re_log::debug!("cur_hash: {cur_hash:?}");
7882

7983
let new_hash = compute_re_types_hash(&SourceLocations {
80-
definitions_dir: definitions_dir_path.as_str(),
81-
doc_examples_dir: doc_examples_dir_path.as_str(),
82-
python_output_dir: python_output_dir_path.as_str(),
83-
cpp_output_dir: cpp_output_dir_path.as_str(),
84+
definitions_dir: DEFINITIONS_DIR_PATH,
85+
doc_examples_dir: DOC_EXAMPLES_DIR_PATH,
86+
python_output_dir: PYTHON_OUTPUT_DIR_PATH,
87+
cpp_output_dir: CPP_OUTPUT_DIR_PATH,
8488
});
8589

90+
if let Some(cur_hash) = cur_hash {
91+
if cur_hash == new_hash {
92+
if always_run {
93+
re_log::info!(
94+
"The hash hasn't changed, but --force was passed, so we'll run anyway."
95+
);
96+
} else {
97+
re_log::info!("Returning early: no changes detected (and --force wasn't set).");
98+
return;
99+
}
100+
} else {
101+
re_log::info!("Change detected");
102+
}
103+
} else {
104+
re_log::info!("Missing {re_types_source_hash_path:?} (first time running codegen)");
105+
}
106+
86107
re_log::info!("Running codegen…");
87108
let (report, reporter) = re_types_builder::report::init();
88109

@@ -121,7 +142,6 @@ fn main() {
121142
report.finalize();
122143

123144
write_versioning_hash(re_types_source_hash_path, new_hash);
124-
write_versioning_hash(re_types_builder_source_hash_path, builder_hash);
125145

126146
re_log::info!("Done.");
127147
}

crates/re_types_builder/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ pub fn compute_re_types_hash(locations: &SourceLocations<'_>) -> String {
328328
&cpp_extensions_hash,
329329
]);
330330

331-
eprintln!("re_types_builder_hash: {re_types_builder_hash:?}");
332-
eprintln!("definitions_hash: {definitions_hash:?}");
333-
eprintln!("doc_examples_hash: {doc_examples_hash:?}");
334-
eprintln!("python_extensions_hash: {python_extensions_hash:?}");
335-
eprintln!("cpp_extensions_hash: {cpp_extensions_hash:?}");
336-
eprintln!("new_hash: {new_hash:?}");
331+
re_log::debug!("re_types_builder_hash: {re_types_builder_hash:?}");
332+
re_log::debug!("definitions_hash: {definitions_hash:?}");
333+
re_log::debug!("doc_examples_hash: {doc_examples_hash:?}");
334+
re_log::debug!("python_extensions_hash: {python_extensions_hash:?}");
335+
re_log::debug!("cpp_extensions_hash: {cpp_extensions_hash:?}");
336+
re_log::debug!("new_hash: {new_hash:?}");
337337

338338
new_hash
339339
}

0 commit comments

Comments
 (0)