Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): expose core version in java engine layer #199

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

sighphyre
Copy link
Member

Exposes the Yggdrasil version in the Java layer so we can always know what binary the Java engine is shipped with. Generally useful for other engines too

@@ -141,6 +141,11 @@ public List<FeatureDef> listKnownToggles() throws YggdrasilError {
return response.getValue();
}

public static String getCoreVersion() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're receiving a static pointer in this function so no need to clean up

@@ -31,6 +31,7 @@ pub type CompiledState = HashMap<String, CompiledToggle>;

pub const SUPPORTED_SPEC_VERSION: &str = "5.1.9";
const VARIANT_NORMALIZATION_SEED: u32 = 86028157;
pub const CORE_VERSION: &str = env!("CARGO_PKG_VERSION");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bake the semver defined in the cargo toml file into a constant in the binary itself

Context, EngineState, EvalWarning, ExtendedVariantDef, ToggleDefinition, CORE_VERSION,
};

static CORE_VERSION_CSTRING: std::sync::LazyLock<CString> =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the expect here is okay since this should only cause problems if this uses an escape character to inject a nul byte and this always a semver string which can't have escape characters.

For the Unrusted:

CStrings are heap allocated so we can't just make constants out of them. So we wrap this in a LazyLock, which sets the value the first time and thereafter just retrieves it. A singleton, if you will

For the Rusted:

Look ma, no once_cell!

Copy link
Member

@chriswk chriswk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@sighphyre sighphyre merged commit 76aa3e2 into refactor/java-engine Jan 14, 2025
1 check passed
@sighphyre sighphyre deleted the feat/expose-core-version branch January 14, 2025 09:25
sighphyre added a commit that referenced this pull request Jan 14, 2025
…ods can be exposed and do memory management that should work on Java 18 and above (#198)

* refactor(java): rework java engine so that static methods can be exposed cleanly

* feat(java): expose core version in java engine layer (#199)

* fix(java): force native encoding to utf-8 so windows doesn't set it to something horrible (#200)
sighphyre added a commit that referenced this pull request Jan 14, 2025
…#197)

* feat(java): expose list_known_features

* refactor(java):separate resposibilities on java engine so static methods can be exposed and do memory management that should work on Java 18 and above (#198)

* refactor(java): rework java engine so that static methods can be exposed cleanly

* feat(java): expose core version in java engine layer (#199)

* fix(java): force native encoding to utf-8 so windows doesn't set it to something horrible (#200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants