Skip to content

Commit 86d0adb

Browse files
committed
Make new Rust sysprop usage consistent with others.
1 parent 80308ae commit 86d0adb

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public class SbeTool
150150
*/
151151
public static final String CPP_NAMESPACES_COLLAPSE = "sbe.cpp.namespaces.collapse";
152152

153+
/**
154+
* Version of the Rust crate to generate.
155+
*/
156+
public static final String RUST_CRATE_VERSION = "sbe.rust.crate.version";
157+
158+
/**
159+
* The default version of the Rust crate to generate, when not specified via the system property.
160+
*/
161+
public static final String RUST_DEFAULT_CRATE_VERSION = "0.1.0";
162+
153163
/**
154164
* Boolean system property to turn on or off generation of the interface hierarchy. Defaults to false.
155165
*/

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir)
142142
{
143143
return new RustGenerator(
144144
ir,
145+
System.getProperty(RUST_CRATE_VERSION, RUST_DEFAULT_CRATE_VERSION),
145146
new RustOutputManager(outputDir, ir.packageName()));
146147
}
147148
};

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/rust/RustGenerator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
*/
4949
public class RustGenerator implements CodeGenerator
5050
{
51-
private static final String CRATE_VERSION = System.getProperty("sbe.rust.crate.version");
5251
static final String WRITE_BUF_TYPE = "WriteBuf";
5352
static final String READ_BUF_TYPE = "ReadBuf";
5453
static final String BUF_LIFETIME = "'a";
@@ -81,21 +80,26 @@ interface ParentDef
8180

8281
private final Ir ir;
8382
private final RustOutputManager outputManager;
83+
private final String crateVersion;
8484

8585
/**
8686
* Create a new Rust language {@link CodeGenerator}.
8787
*
8888
* @param ir for the messages and types.
89+
* @param crateVersion for the generated crate.
8990
* @param outputManager for generating the codecs to.
9091
*/
9192
public RustGenerator(
9293
final Ir ir,
94+
final String crateVersion,
9395
final OutputManager outputManager)
9496
{
9597
Verify.notNull(ir, "ir");
98+
Verify.notNull(crateVersion, "crateVersion");
9699
Verify.notNull(outputManager, "outputManager");
97100

98101
this.ir = ir;
102+
this.crateVersion = crateVersion;
99103
this.outputManager = (RustOutputManager)outputManager;
100104
}
101105

@@ -115,11 +119,10 @@ public void generate() throws IOException
115119
{
116120
namespace = (ir.namespaceName() + "_" + packageName).toLowerCase();
117121
}
118-
final String version = CRATE_VERSION == null ? "0.1.0" : CRATE_VERSION;
119122

120123
indent(writer, 0, "[package]\n");
121124
indent(writer, 0, "name = \"%s\"\n", namespace);
122-
indent(writer, 0, "version = \"%s\"\n", version);
125+
indent(writer, 0, "version = \"%s\"\n", crateVersion);
123126
indent(writer, 0, "authors = [\"sbetool\"]\n");
124127
indent(writer, 0, "description = \"%s\"\n", ir.description());
125128
indent(writer, 0, "edition = \"2021\"\n\n");

0 commit comments

Comments
 (0)