summaryrefslogtreecommitdiffstats
path: root/xpcom/rust/gkrust_utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /xpcom/rust/gkrust_utils
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/rust/gkrust_utils')
-rw-r--r--xpcom/rust/gkrust_utils/Cargo.toml9
-rw-r--r--xpcom/rust/gkrust_utils/cbindgen.toml31
-rw-r--r--xpcom/rust/gkrust_utils/src/lib.rs24
3 files changed, 64 insertions, 0 deletions
diff --git a/xpcom/rust/gkrust_utils/Cargo.toml b/xpcom/rust/gkrust_utils/Cargo.toml
new file mode 100644
index 0000000000..e398725260
--- /dev/null
+++ b/xpcom/rust/gkrust_utils/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "gkrust_utils"
+version = "0.1.0"
+authors = ["Jonathan Kingston <jkt@mozilla.com>"]
+license = "MPL-2.0"
+
+[dependencies]
+semver = "1.0"
+nsstring = { path = "../nsstring" }
diff --git a/xpcom/rust/gkrust_utils/cbindgen.toml b/xpcom/rust/gkrust_utils/cbindgen.toml
new file mode 100644
index 0000000000..967fbefd47
--- /dev/null
+++ b/xpcom/rust/gkrust_utils/cbindgen.toml
@@ -0,0 +1,31 @@
+header = """/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */"""
+autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
+ * To generate this file:
+ * 1. Get the latest cbindgen using `cargo install --force cbindgen`
+ * a. Alternatively, you can clone `https://github.com/eqrion/cbindgen` and use a tagged release
+ * 2. Run `rustup run nightly cbindgen xpcom/rust/gkrust_utils --lockfile Cargo.lock --crate gkrust_utils -o xpcom/base/gk_rust_utils_ffi_generated.h`
+ */
+#include "nsError.h"
+#include "nsString.h"
+"""
+include_version = true
+braces = "SameLine"
+line_length = 100
+tab_width = 2
+language = "C++"
+namespaces = ["mozilla"]
+
+[export]
+# Skip constants because we don't have any
+item_types = ["globals", "enums", "structs", "unions", "typedefs", "opaque", "functions"]
+
+[enum]
+add_sentinel = true
+derive_helper_methods = true
+
+[defines]
+"target_os = windows" = "XP_WIN"
+"target_os = macos" = "XP_MACOSX"
+"target_os = android" = "ANDROID"
diff --git a/xpcom/rust/gkrust_utils/src/lib.rs b/xpcom/rust/gkrust_utils/src/lib.rs
new file mode 100644
index 0000000000..c519d7e002
--- /dev/null
+++ b/xpcom/rust/gkrust_utils/src/lib.rs
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+extern crate nsstring;
+extern crate semver;
+use nsstring::nsACString;
+
+#[no_mangle]
+pub unsafe extern "C" fn GkRustUtils_ParseSemVer(
+ ver: &nsACString,
+ out_major: *mut u64,
+ out_minor: *mut u64,
+ out_patch: *mut u64,
+) -> bool {
+ let version = match semver::Version::parse(&ver.to_utf8()) {
+ Ok(ver) => ver,
+ Err(_) => return false,
+ };
+ *out_major = version.major;
+ *out_minor = version.minor;
+ *out_patch = version.patch;
+ true
+}