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(capi): Add API to get runtime library version #597

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
types: [checks_requested]

env:
RUST_VERSION: "1.70"
RUST_VERSION: "1.77"
CMAKE_GENERATOR: Ninja

jobs:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "chewing"
description = "The Chewing (酷音) intelligent Zhuyin input method."
documentation = "https://docs.rs/chewing"
license = "LGPL-2.1-or-later"
version = "0.8.5"
rust-version = "1.70"
version = "0.9.0-alpha.1"
rust-version = "1.77.0"
edition = "2021"

include = [
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ be built.
- cmake >= 3.21.0
+ Toolchain / IDE:
- clang >= 3.2 OR gcc >= 4.6.3
- Rust >= 1.70
- Rust >= 1.77
- Build Tools for Visual Studio 2022 for MSVC build
+ Documentation tools:
- texinfo >= 4.8
Expand Down Expand Up @@ -185,7 +185,7 @@ To ensure libchewing can be built on various Linux distributions, we use the
minimum rust version available from major distributions' next release branch.
Data source: https://repology.org/project/rust/versions

* Current MSRV: 1.70.0 (Debian unstable)
* Current MSRV: 1.77.0 (Debian unstable)


## Usage
Expand Down
6 changes: 3 additions & 3 deletions capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
name = "chewing_capi"
description = "The Chewing (酷音) intelligent Zhuyin input method."
license = "LGPL-2.1-or-later"
version = "0.8.5"
rust-version = "1.70"
version = "0.9.0-alpha.1"
rust-version = "1.77"
edition = "2021"

[lib]
crate-type = ["rlib", "staticlib"]

[dependencies]
chewing = { version = "0.8.5", path = ".." }
chewing = { version = "0.9.0-alpha.1", path = ".." }
env_logger = { version = ">= 0.10.2", default-features = false }
log = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub unsafe extern "C" fn chewing_config_has_option(
| "chewing.selection_keys"
| "chewing.character_form"
| "chewing.space_is_select_key"
| "chewing.fuzzy_searcy_mode" => true,
| "chewing.fuzzy_search_mode" => true,
_ => false,
};

Expand Down
2 changes: 2 additions & 0 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ mod io;
mod logger;
mod public;

pub mod version;

/// Initializes chewing context and environment settings.
///
/// Most of the Chewing IM APIs require a
Expand Down
5 changes: 5 additions & 0 deletions capi/src/symbols-elf.map
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,9 @@ CHEWING_0.9 {
chewing_config_get_int;
chewing_config_set_str;
chewing_config_get_str;
chewing_version;
chewing_version_major;
chewing_version_minor;
chewing_version_patch;
chewing_version_extra;
} CHEWING_0.5;
7 changes: 6 additions & 1 deletion capi/src/symbols-mach_o.map
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ _chewing_config_has_option
_chewing_config_set_int
_chewing_config_get_int
_chewing_config_set_str
_chewing_config_get_str
_chewing_config_get_str
_chewing_version
_chewing_version_major
_chewing_version_minor
_chewing_version_patch
_chewing_version_extra
7 changes: 6 additions & 1 deletion capi/src/symbols-msvc.def
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ EXPORTS
chewing_config_set_int;
chewing_config_get_int;
chewing_config_set_str;
chewing_config_get_str;
chewing_config_get_str;
chewing_version;
chewing_version_major;
chewing_version_minor;
chewing_version_patch;
chewing_version_extra;
26 changes: 26 additions & 0 deletions capi/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::ffi::{c_char, c_int};

#[no_mangle]
pub extern "C" fn chewing_version() -> *const c_char {
c"0.9.0-alpha.1".as_ptr()
}

#[no_mangle]
pub extern "C" fn chewing_version_major() -> c_int {
0
}

#[no_mangle]
pub extern "C" fn chewing_version_minor() -> c_int {
9
}

#[no_mangle]
pub extern "C" fn chewing_version_patch() -> c_int {
0
}

#[no_mangle]
pub extern "C" fn chewing_version_extra() -> *const c_char {
c"-alpha.1".as_ptr()
}
4 changes: 2 additions & 2 deletions fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chewing = { version = "0.8.5", path = ".." }
chewing_capi = { version = "0.8.5", path = "../capi" }
chewing = { version = "0.9.0-alpha.1", path = ".." }
chewing_capi = { version = "0.9.0-alpha.1", path = "../capi" }
log = "0.4.21"
env_logger = { version = ">= 0.10.2", default-features = false }
10 changes: 10 additions & 0 deletions include/chewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,16 @@ void chewing_set_hsuSelKeyType(struct ChewingContext *_ctx, int mode);
*/
int chewing_get_hsuSelKeyType(struct ChewingContext *_ctx);

const char *chewing_version(void);

int chewing_version_major(void);

int chewing_version_minor(void);

int chewing_version_patch(void);

const char *chewing_version_extra(void);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
22 changes: 22 additions & 0 deletions tests/test-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* of this file.
*/

#include <stdio.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
Expand Down Expand Up @@ -53,6 +54,7 @@ void test_has_option()
,"chewing.selection_keys"
,"chewing.character_form"
,"chewing.space_is_select_key"
,"chewing.fuzzy_search_mode"
};

ctx = chewing_new();
Expand Down Expand Up @@ -161,6 +163,9 @@ void test_default_value_options()
ok(chewing_config_get_int(ctx, "chewing.character_form") == HALFSHAPE_MODE,
"default chewing.character_form shall be %d", HALFSHAPE_MODE);

ok(chewing_config_get_int(ctx, "chewing.fuzzy_search_mode") == 0,
"default chewing.fuzzy_search_mode shall be 0");

chewing_delete(ctx);
}

Expand Down Expand Up @@ -722,6 +727,21 @@ void test_new2()
test_new2_userpath();
}

void test_runtime_version()
{
char buf[256];
int major = chewing_version_major();
int minor = chewing_version_minor();
int patch = chewing_version_patch();
const char *extra = chewing_version_extra();
const char *version = chewing_version();

ok(version != NULL, "chewing_version returns a version string");

sprintf(buf, "%d.%d.%d%s", major, minor, patch, extra);
ok(strcmp(buf, version) == 0, "chewing_version can be created from components");
}

int main(int argc, char *argv[])
{
char *logname;
Expand Down Expand Up @@ -760,6 +780,8 @@ int main(int argc, char *argv[])

test_new2();

test_runtime_version();

fclose(fd);

return exit_status();
Expand Down
2 changes: 1 addition & 1 deletion tests/testhelper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
chewing = { version = "0.8.5", path = "../.." }
chewing = { version = "0.9.0-alpha.1", path = "../.." }

[features]
sqlite = ["chewing/sqlite"]
4 changes: 2 additions & 2 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
name = "chewing-cli"
description = "Tools of the Chewing (酷音) intelligent Zhuyin input method."
license = "LGPL-2.1-or-later"
version = "0.8.5"
version = "0.9.0-alpha.1"
edition = "2021"

[dependencies]
anyhow = "1.0.0"
chewing = { version = "0.8.5", path = "..", features = ["sqlite"] }
chewing = { version = "0.9.0-alpha.1", path = "..", features = ["sqlite"] }
clap = { version = "4.4.18", features = ["derive"] }
clap_mangen = { version = "0.2.12", optional = true }

Expand Down