From d892830785c3e24f4a989327d3645b35e440a60c Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 17 Dec 2023 15:03:59 -0300 Subject: [PATCH] Version constants to allow fetching version at runtime --- bindings/c/include/ipl3checksum.h | 1 + bindings/c/include/ipl3checksum/version.h | 15 ++++++++++ bindings/c/tests/test_checksum.c | 2 ++ bindings/c/tests/test_checksum_autodetect.c | 2 ++ bindings/c/tests/test_detect.c | 2 ++ pyproject.toml | 3 ++ src/rs/lib.rs | 1 + src/rs/version.rs | 31 +++++++++++++++++++++ 8 files changed, 57 insertions(+) create mode 100644 bindings/c/include/ipl3checksum/version.h create mode 100644 src/rs/version.rs diff --git a/bindings/c/include/ipl3checksum.h b/bindings/c/include/ipl3checksum.h index 9c8c90d..5de8b77 100644 --- a/bindings/c/include/ipl3checksum.h +++ b/bindings/c/include/ipl3checksum.h @@ -7,5 +7,6 @@ #include "ipl3checksum/checksum.h" #include "ipl3checksum/detect.h" #include "ipl3checksum/utils.h" +#include "ipl3checksum/version.h" #endif diff --git a/bindings/c/include/ipl3checksum/version.h b/bindings/c/include/ipl3checksum/version.h new file mode 100644 index 0000000..a31d8a5 --- /dev/null +++ b/bindings/c/include/ipl3checksum/version.h @@ -0,0 +1,15 @@ +#ifndef IPL3CHECKSUM_VERSION_H +#define IPL3CHECKSUM_VERSION_H +#pragma once + +#include + +extern const int32_t ipl3checksum_version_major; +extern const int32_t ipl3checksum_version_minor; +extern const int32_t ipl3checksum_version_patch; + +extern const char *const ipl3checksum_version_str; + +extern const char *const ipl3checksum_version_author; + +#endif diff --git a/bindings/c/tests/test_checksum.c b/bindings/c/tests/test_checksum.c index 394bb70..ed6bff8 100644 --- a/bindings/c/tests/test_checksum.c +++ b/bindings/c/tests/test_checksum.c @@ -41,6 +41,8 @@ int main(int argc, char *argv[]) { return -1; } + fprintf(stderr, "Running ipl3checksum version %s\n", ipl3checksum_version_str); + const char *bin_path = argv[1]; const char *cic_kind_name = argv[2]; diff --git a/bindings/c/tests/test_checksum_autodetect.c b/bindings/c/tests/test_checksum_autodetect.c index a9fd52e..5a4d121 100644 --- a/bindings/c/tests/test_checksum_autodetect.c +++ b/bindings/c/tests/test_checksum_autodetect.c @@ -24,6 +24,8 @@ int main(int argc, char *argv[]) { return -1; } + fprintf(stderr, "Running ipl3checksum version %s\n", ipl3checksum_version_str); + const char *bin_path = argv[1]; size_t bin_size = 0; diff --git a/bindings/c/tests/test_detect.c b/bindings/c/tests/test_detect.c index 81bd821..6027436 100644 --- a/bindings/c/tests/test_detect.c +++ b/bindings/c/tests/test_detect.c @@ -41,6 +41,8 @@ int main(int argc, char *argv[]) { return -1; } + fprintf(stderr, "Running ipl3checksum version %s\n", ipl3checksum_version_str); + const char *bin_path = argv[1]; size_t bin_size = 0; diff --git a/pyproject.toml b/pyproject.toml index b8f5f34..29a0f1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,9 @@ version = "1.1.0.dev0" description = "Library to calculate the IPL3 checksum for N64 ROMs" readme = "README.md" requires-python = ">=3.7" +authors = [ + { name="Anghelo Carvajal", email="angheloalf95@gmail.com" }, +] classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", diff --git a/src/rs/lib.rs b/src/rs/lib.rs index f040cb4..eda37fd 100644 --- a/src/rs/lib.rs +++ b/src/rs/lib.rs @@ -6,6 +6,7 @@ mod cickinds; mod detect; mod error; mod utils; +pub mod version; pub use checksum::*; pub use cickinds::*; diff --git a/src/rs/version.rs b/src/rs/version.rs new file mode 100644 index 0000000..e41ba53 --- /dev/null +++ b/src/rs/version.rs @@ -0,0 +1,31 @@ +/* SPDX-FileCopyrightText: © 2023 Decompollaborate */ +/* SPDX-License-Identifier: MIT */ + +pub static VERSION_MAJOR: i32 = 1; +pub static VERSION_MINOR: i32 = 1; +pub static VERSION_PATCH: i32 = 0; + +pub static VERSION_INFO: (i32, i32, i32) = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); + +// TODO: figure out a way to construct this string by using VERSION_MAJOR, VERSION_MINOR and VERSION_PATCH (concat! and stringify! didn't work) +pub static VERSION_STR: &str = "1.1.0"; + +pub static AUTHOR: &str = "Decompollaborate"; + +#[cfg(feature = "c_bindings")] +mod c_bindings { + #[no_mangle] + static ipl3checksum_version_major: i32 = super::VERSION_MAJOR; + #[no_mangle] + static ipl3checksum_version_minor: i32 = super::VERSION_MINOR; + #[no_mangle] + static ipl3checksum_version_patch: i32 = super::VERSION_PATCH; + + // TODO: construct this from super::VERSION_STR + #[no_mangle] + static ipl3checksum_version_str: &[u8] = b"1.1.0\0"; + + // TODO: construct this from super::AUTHOR + #[no_mangle] + static ipl3checksum_version_author: &[u8] = b"Decompollaborate\0"; +}