Skip to content

Commit

Permalink
Version constants to allow fetching version at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 17, 2023
1 parent 6200e2a commit d892830
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings/c/include/ipl3checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
#include "ipl3checksum/checksum.h"
#include "ipl3checksum/detect.h"
#include "ipl3checksum/utils.h"
#include "ipl3checksum/version.h"

#endif
15 changes: 15 additions & 0 deletions bindings/c/include/ipl3checksum/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef IPL3CHECKSUM_VERSION_H
#define IPL3CHECKSUM_VERSION_H
#pragma once

#include <stdint.h>

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
2 changes: 2 additions & 0 deletions bindings/c/tests/test_checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 2 additions & 0 deletions bindings/c/tests/test_checksum_autodetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions bindings/c/tests/test_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
Expand Down
1 change: 1 addition & 0 deletions src/rs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod cickinds;
mod detect;
mod error;
mod utils;
pub mod version;

pub use checksum::*;
pub use cickinds::*;
Expand Down
31 changes: 31 additions & 0 deletions src/rs/version.rs
Original file line number Diff line number Diff line change
@@ -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";
}

0 comments on commit d892830

Please sign in to comment.