diff --git a/Cargo.lock b/Cargo.lock index c173066..9858042 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,6 +344,7 @@ dependencies = [ "libc", "mnn-sys", "oneshot", + "semver", "thiserror", "tracing", ] @@ -369,6 +370,7 @@ dependencies = [ "dunce", "fs_extra", "libc", + "semver", "tap", ] diff --git a/Cargo.toml b/Cargo.toml index dec4e5a..6b6c65a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ thiserror = "1.0" error-stack = { version = "0.5" } oneshot = "0.1" tracing = { version = "0.1.40", optional = true } +semver = "1.0.23" [features] metal = ["mnn-sys/metal"] diff --git a/flake.lock b/flake.lock index 6a35de4..f593e19 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1725403077, - "narHash": "sha256-JLtZxyurwjOl3zBEJZVxMnqAftS1QIdD6ZWjASHqM0U=", + "lastModified": 1725883717, + "narHash": "sha256-QifFNLfu5bzKPO4iznCj1h+nHhqGZ8NR2Lo7tzh9FRc=", "owner": "rustsec", "repo": "advisory-db", - "rev": "341f80ff9225eed1b91ea52231506b51b2700115", + "rev": "7fbf1e630ae52b7b364791a107b5bee5ff929496", "type": "github" }, "original": { @@ -127,11 +127,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1725103162, - "narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=", + "lastModified": 1725634671, + "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b", + "rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c", "type": "github" }, "original": { @@ -159,11 +159,11 @@ ] }, "locked": { - "lastModified": 1725416653, - "narHash": "sha256-iNBv7ILlZI6ubhW0ExYy8YgiLKUerudxY7n8R5UQK2E=", + "lastModified": 1726021481, + "narHash": "sha256-4J4E+Fh+77XIYnq2RVtg+ENWXpu6t74P0jKN/f2RQmI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "e5d3f9c2f24d852cddc79716daf0f65ce8468b28", + "rev": "1c2c120246c51a644c20ba2a36a33d3bd4860d70", "type": "github" }, "original": { diff --git a/mnn-sys/Cargo.toml b/mnn-sys/Cargo.toml index d9305e9..0b6b72a 100644 --- a/mnn-sys/Cargo.toml +++ b/mnn-sys/Cargo.toml @@ -30,3 +30,4 @@ crt_static = [] [dependencies] libc = "0.2.155" +semver = "1.0.23" diff --git a/mnn-sys/build.rs b/mnn-sys/build.rs index 870df0e..e6d60e6 100644 --- a/mnn-sys/build.rs +++ b/mnn-sys/build.rs @@ -134,6 +134,7 @@ pub fn mnn_c_bindgen(vendor: impl AsRef, out: impl AsRef) -> Result< "tensor_c.h", "backend_c.h", "schedule_c.h", + "mnndefine.h", ]; let bindings = bindgen::Builder::default() diff --git a/mnn-sys/mnn_c/interpreter_c.cpp b/mnn-sys/mnn_c/interpreter_c.cpp index 6bfb0b4..8b915d9 100644 --- a/mnn-sys/mnn_c/interpreter_c.cpp +++ b/mnn-sys/mnn_c/interpreter_c.cpp @@ -24,7 +24,7 @@ void modelPrintIO(const char *model) { } } -const char *getVersion() { return MNN::getVersion(); } +// const char *getVersion() { return MNN::getVersion(); } Interpreter *Interpreter_createFromFile(const char *file) { return reinterpret_cast( MNN::Interpreter::createFromFile(file)); diff --git a/mnn-sys/mnn_c/mnndefine.h b/mnn-sys/mnn_c/mnndefine.h new file mode 100644 index 0000000..1bc1abd --- /dev/null +++ b/mnn-sys/mnn_c/mnndefine.h @@ -0,0 +1,4 @@ +#ifndef MNN_DEFINE_C +#define MNN_DEFINE_C +#include +#endif diff --git a/mnn-sys/src/lib.rs b/mnn-sys/src/lib.rs index 46617b9..b1dc1ac 100644 --- a/mnn-sys/src/lib.rs +++ b/mnn-sys/src/lib.rs @@ -93,3 +93,11 @@ impl halide_type_code_t { unsafe { std::mem::transmute(code) } } } + +pub const fn version() -> semver::Version { + semver::Version::new( + mnn_sys::MNN_VERSION_MAJOR as u64, + mnn_sys::MNN_VERSION_MINOR as u64, + mnn_sys::MNN_VERSION_PATCH as u64, + ) +} diff --git a/src/interpreter.rs b/src/interpreter.rs index b1c555d..f09956a 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -41,6 +41,10 @@ pub enum SessionMode { ResizeFix = mnn_sys::SessionMode::Session_Resize_Fix, } +pub const fn version() -> semver::Version { + mnn_sys::version() +} + impl SessionMode { #[cfg(windows)] fn to_mnn_sys(&self) -> i32 {