Skip to content

Commit 4b515ff

Browse files
committed
Only include the version in the globals version file
1 parent 7f41190 commit 4b515ff

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

crates/codegen/src/csharp.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::code_indenter::CodeIndenter;
88
use super::Lang;
99
use crate::util::{
1010
collect_case, is_reducer_invokable, iter_indexes, iter_reducers, iter_tables, print_auto_generated_file_comment,
11-
type_ref_name,
11+
print_auto_generated_version_comment, type_ref_name,
1212
};
1313
use crate::{indent_scope, OutputFile};
1414
use convert_case::{Case, Casing};
@@ -442,6 +442,7 @@ impl Lang for Csharp<'_> {
442442
"System.Collections.Generic",
443443
"System.Runtime.Serialization",
444444
],
445+
false,
445446
);
446447

447448
writeln!(output, "public sealed partial class RemoteTables");
@@ -587,6 +588,7 @@ impl Lang for Csharp<'_> {
587588
"System.Collections.Generic",
588589
"System.Runtime.Serialization",
589590
],
591+
false,
590592
);
591593

592594
writeln!(output, "public sealed partial class RemoteReducers : RemoteBase");
@@ -713,6 +715,7 @@ impl Lang for Csharp<'_> {
713715
"System.Collections.Generic",
714716
"System.Runtime.Serialization",
715717
],
718+
true, // print the version in the globals file
716719
);
717720

718721
writeln!(output, "public sealed partial class RemoteReducers : RemoteBase");
@@ -945,10 +948,13 @@ impl std::ops::DerefMut for CsharpAutogen {
945948
}
946949

947950
impl CsharpAutogen {
948-
pub fn new(namespace: &str, extra_usings: &[&str]) -> Self {
951+
pub fn new(namespace: &str, extra_usings: &[&str], include_version: bool) -> Self {
949952
let mut output = CodeIndenter::new(String::new(), INDENT);
950953

951954
print_auto_generated_file_comment(&mut output);
955+
if include_version {
956+
print_auto_generated_version_comment(&mut output);
957+
}
952958

953959
writeln!(output, "#nullable enable");
954960
writeln!(output);
@@ -984,7 +990,7 @@ impl CsharpAutogen {
984990
}
985991

986992
fn autogen_csharp_sum(module: &ModuleDef, sum_type_name: String, sum_type: &SumTypeDef, namespace: &str) -> String {
987-
let mut output = CsharpAutogen::new(namespace, &[]);
993+
let mut output = CsharpAutogen::new(namespace, &[], false);
988994

989995
writeln!(output, "[SpacetimeDB.Type]");
990996
write!(
@@ -1021,7 +1027,7 @@ fn autogen_csharp_sum(module: &ModuleDef, sum_type_name: String, sum_type: &SumT
10211027
}
10221028

10231029
fn autogen_csharp_plain_enum(enum_type_name: String, enum_type: &PlainEnumTypeDef, namespace: &str) -> String {
1024-
let mut output = CsharpAutogen::new(namespace, &[]);
1030+
let mut output = CsharpAutogen::new(namespace, &[], false);
10251031

10261032
writeln!(output, "[SpacetimeDB.Type]");
10271033
writeln!(output, "public enum {enum_type_name}");
@@ -1038,6 +1044,7 @@ fn autogen_csharp_tuple(module: &ModuleDef, name: String, tuple: &ProductTypeDef
10381044
let mut output = CsharpAutogen::new(
10391045
namespace,
10401046
&["System.Collections.Generic", "System.Runtime.Serialization"],
1047+
false,
10411048
);
10421049

10431050
autogen_csharp_product_common(module, &mut output, name, tuple, "", |_| {});

crates/codegen/src/rust.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use super::code_indenter::{CodeIndenter, Indenter};
22
use super::util::{collect_case, iter_reducers, print_lines, type_ref_name};
33
use super::Lang;
4-
use crate::util::{iter_tables, iter_types, iter_unique_cols, print_auto_generated_file_comment};
4+
use crate::util::{
5+
iter_tables, iter_types, iter_unique_cols, print_auto_generated_file_comment, print_auto_generated_version_comment,
6+
};
57
use crate::OutputFile;
68
use convert_case::{Case, Casing};
79
use spacetimedb_lib::sats::layout::PrimitiveType;
@@ -28,7 +30,7 @@ impl Lang for Rust {
2830
let mut output = CodeIndenter::new(String::new(), INDENT);
2931
let out = &mut output;
3032

31-
print_file_header(out);
33+
print_file_header(out, false);
3234
out.newline();
3335

3436
match &module.typespace_for_generate()[typ.ty] {
@@ -78,7 +80,7 @@ impl __sdk::InModule for {type_name} {{
7880
let mut output = CodeIndenter::new(String::new(), INDENT);
7981
let out = &mut output;
8082

81-
print_file_header(out);
83+
print_file_header(out, false);
8284

8385
let row_type = type_ref_name(module, type_ref);
8486
let row_type_module = type_ref_module_name(module, type_ref);
@@ -298,7 +300,7 @@ pub(super) fn parse_table_update(
298300
let mut output = CodeIndenter::new(String::new(), INDENT);
299301
let out = &mut output;
300302

301-
print_file_header(out);
303+
print_file_header(out, false);
302304

303305
out.newline();
304306

@@ -489,7 +491,7 @@ impl {set_reducer_flags_trait} for super::SetReducerFlags {{
489491
let mut output = CodeIndenter::new(String::new(), INDENT);
490492
let out = &mut output;
491493

492-
print_file_header(out);
494+
print_file_header(out, true);
493495

494496
out.newline();
495497

@@ -600,8 +602,11 @@ fn print_spacetimedb_imports(output: &mut Indenter) {
600602
print_lines(output, SPACETIMEDB_IMPORTS);
601603
}
602604

603-
fn print_file_header(output: &mut Indenter) {
605+
fn print_file_header(output: &mut Indenter, include_version: bool) {
604606
print_auto_generated_file_comment(output);
607+
if include_version {
608+
print_auto_generated_version_comment(output);
609+
}
605610
writeln!(output, "{ALLOW_LINTS}");
606611
print_spacetimedb_imports(output);
607612
}

crates/codegen/src/typescript.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::util::{is_reducer_invokable, iter_reducers, iter_tables, iter_types, iter_unique_cols};
1+
use crate::util::{
2+
is_reducer_invokable, iter_reducers, iter_tables, iter_types, iter_unique_cols,
3+
print_auto_generated_version_comment,
4+
};
25
use crate::{indent_scope, OutputFile};
36

47
use super::util::{collect_case, print_auto_generated_file_comment, type_ref_name};
@@ -33,7 +36,7 @@ impl Lang for TypeScript {
3336
let mut output = CodeIndenter::new(String::new(), INDENT);
3437
let out = &mut output;
3538

36-
print_file_header(out);
39+
print_file_header(out, false);
3740
gen_and_print_imports(module, out, &product.elements, &[typ.ty], None);
3841
writeln!(out);
3942
define_body_for_product(module, out, &type_name, &product.elements);
@@ -48,7 +51,7 @@ impl Lang for TypeScript {
4851
let mut output = CodeIndenter::new(String::new(), INDENT);
4952
let out = &mut output;
5053

51-
print_file_header(out);
54+
print_file_header(out, false);
5255
// Note that the current type is not included in dont_import below.
5356
gen_and_print_imports(module, out, variants, &[], Some("Type"));
5457
writeln!(out);
@@ -64,7 +67,7 @@ impl Lang for TypeScript {
6467
let mut output = CodeIndenter::new(String::new(), INDENT);
6568
let out = &mut output;
6669

67-
print_file_header(out);
70+
print_file_header(out, false);
6871
gen_and_print_imports(module, out, variants, &[typ.ty], None);
6972
writeln!(
7073
out,
@@ -113,7 +116,7 @@ impl Lang for TypeScript {
113116
let mut output = CodeIndenter::new(String::new(), INDENT);
114117
let out = &mut output;
115118

116-
print_file_header(out);
119+
print_file_header(out, false);
117120

118121
let type_ref = table.product_type_ref;
119122
let row_type = type_ref_name(module, type_ref);
@@ -280,7 +283,7 @@ removeOnUpdate = (cb: (ctx: EventContext, onRow: {row_type}, newRow: {row_type})
280283
let mut output = CodeIndenter::new(String::new(), INDENT);
281284
let out = &mut output;
282285

283-
print_file_header(out);
286+
print_file_header(out, false);
284287

285288
out.newline();
286289

@@ -307,7 +310,7 @@ removeOnUpdate = (cb: (ctx: EventContext, onRow: {row_type}, newRow: {row_type})
307310
let mut output = CodeIndenter::new(String::new(), INDENT);
308311
let out = &mut output;
309312

310-
print_file_header(out);
313+
print_file_header(out, true);
311314

312315
out.newline();
313316

@@ -697,8 +700,11 @@ fn print_spacetimedb_imports(out: &mut Indenter) {
697700
writeln!(out, "}} from \"@clockworklabs/spacetimedb-sdk\";");
698701
}
699702

700-
fn print_file_header(output: &mut Indenter) {
703+
fn print_file_header(output: &mut Indenter, include_version: bool) {
701704
print_auto_generated_file_comment(output);
705+
if include_version {
706+
print_auto_generated_version_comment(output);
707+
}
702708
print_lint_suppression(output);
703709
print_spacetimedb_imports(output);
704710
}

crates/codegen/src/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const AUTO_GENERATED_FILE_COMMENT: &[&str] = &[
5555

5656
pub(super) fn print_auto_generated_file_comment(output: &mut Indenter) {
5757
print_lines(output, AUTO_GENERATED_FILE_COMMENT);
58+
}
59+
60+
pub(super) fn print_auto_generated_version_comment(output: &mut Indenter) {
5861
writeln!(
5962
output,
6063
"// This was generated using spacetimedb cli version {} (commit {}).",

0 commit comments

Comments
 (0)