Skip to content

Commit df98da6

Browse files
committed
bindings: add Rust bindings
Rust bindings implement an FFI interface to the qclib C library and allows the usage of qclib in Rust context. The bindings come in two crates: * qclib-sys: contains the raw FFI interface to the C library. * qclib: contains a safe and idiomatic abstraction for data types and functions provided by the C library. Signed-off-by: Bjoern Walk <[email protected]>
1 parent 91c439c commit df98da6

25 files changed

+1577
-0
lines changed

bindings/rust/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

bindings/rust/Cargo.lock

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[workspace.package]
2+
edition = "2021"
3+
license-file = "LICENSE"
4+
5+
[package]
6+
name = "qclib"
7+
version = "2.5.1"
8+
edition.workspace = true
9+
license-file.workspace = true
10+
description = "Rust bindings for qclib (Query Capacity Library)"
11+
12+
[dependencies]
13+
serde_json = "1.0"
14+
15+
[dependencies.sys]
16+
package = "qclib-sys"
17+
path = "qclib-sys"
18+
version = "2"

bindings/rust/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

bindings/rust/qclib-sys/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "qclib-sys"
3+
version = "2.5.1"
4+
edition.workspace = true
5+
license-file.workspace = true
6+
description = "Raw bindings for qclib (Query Capacity Library)"
7+
links = "qc"

bindings/rust/qclib-sys/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo::rustc-link-lib=dylib:+verbatim=libqc.so.2");
3+
}

bindings/rust/qclib-sys/src/lib.rs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#![allow(nonstandard_style)]
2+
3+
pub type qc_layer_type = ::std::os::raw::c_uint;
4+
pub const QC_LAYER_TYPE_CEC: qc_layer_type = 1;
5+
pub const QC_LAYER_TYPE_LPAR_GROUP: qc_layer_type = 8;
6+
pub const QC_LAYER_TYPE_LPAR: qc_layer_type = 2;
7+
pub const QC_LAYER_TYPE_ZVM_HYPERVISOR: qc_layer_type = 3;
8+
pub const QC_LAYER_TYPE_ZVM_CPU_POOL: qc_layer_type = 4;
9+
pub const QC_LAYER_TYPE_ZVM_RESOURCE_POOL: qc_layer_type = 4;
10+
pub const QC_LAYER_TYPE_ZVM_GUEST: qc_layer_type = 5;
11+
pub const QC_LAYER_TYPE_KVM_HYPERVISOR: qc_layer_type = 6;
12+
pub const QC_LAYER_TYPE_KVM_GUEST: qc_layer_type = 7;
13+
pub const QC_LAYER_TYPE_ZOS_HYPERVISOR: qc_layer_type = 9;
14+
pub const QC_LAYER_TYPE_ZOS_TENANT_RESOURCE_GROUP: qc_layer_type = 10;
15+
pub const QC_LAYER_TYPE_ZOS_ZCX_SERVER: qc_layer_type = 11;
16+
17+
pub type qc_layer_category = ::std::os::raw::c_uint;
18+
pub const QC_LAYER_CAT_GUEST: qc_layer_category = 1;
19+
pub const QC_LAYER_CAT_HOST: qc_layer_category = 2;
20+
pub const QC_LAYER_CAT_POOL: qc_layer_category = 3;
21+
22+
pub type qc_attr_id = ::std::os::raw::c_uint;
23+
pub const QC_ADJUSTMENT: qc_attr_id = 0;
24+
pub const QC_CAPABILITY: qc_attr_id = 1;
25+
pub const QC_CAPACITY_ADJUSTMENT_INDICATION: qc_attr_id = 2;
26+
pub const QC_CAPACITY_CHANGE_REASON: qc_attr_id = 3;
27+
pub const QC_CAPPING: qc_attr_id = 4;
28+
pub const QC_CAPPING_NUM: qc_attr_id = 5;
29+
pub const QC_CLUSTER_NAME: qc_attr_id = 6;
30+
pub const QC_CONTROL_PROGRAM_ID: qc_attr_id = 7;
31+
pub const QC_CP_ABSOLUTE_CAPPING: qc_attr_id = 8;
32+
pub const QC_CP_CAPACITY_CAP: qc_attr_id = 9;
33+
pub const QC_CP_CAPPED_CAPACITY: qc_attr_id = 10;
34+
pub const QC_CP_DISPATCH_LIMITHARD: qc_attr_id = 11;
35+
pub const QC_CP_DISPATCH_TYPE: qc_attr_id = 12;
36+
pub const QC_CP_LIMITHARD_CAP: qc_attr_id = 13;
37+
pub const QC_CP_WEIGHT_CAPPING: qc_attr_id = 14;
38+
pub const QC_LIMITHARD_CONSUMPTION: qc_attr_id = 15;
39+
pub const QC_HARDLIMIT_CONSUMPTION: qc_attr_id = 15;
40+
pub const QC_HAS_MULTIPLE_CPU_TYPES: qc_attr_id = 16;
41+
pub const QC_IFL_ABSOLUTE_CAPPING: qc_attr_id = 17;
42+
pub const QC_IFL_CAPACITY_CAP: qc_attr_id = 18;
43+
pub const QC_IFL_CAPPED_CAPACITY: qc_attr_id = 19;
44+
pub const QC_IFL_DISPATCH_LIMITHARD: qc_attr_id = 20;
45+
pub const QC_IFL_DISPATCH_TYPE: qc_attr_id = 21;
46+
pub const QC_IFL_LIMITHARD_CAP: qc_attr_id = 22;
47+
pub const QC_IFL_WEIGHT_CAPPING: qc_attr_id = 23;
48+
pub const QC_ZIIP_ABSOLUTE_CAPPING: qc_attr_id = 66;
49+
pub const QC_ZIIP_CAPACITY_CAP: qc_attr_id = 67;
50+
pub const QC_ZIIP_CAPPED_CAPACITY: qc_attr_id = 68;
51+
pub const QC_ZIIP_DISPATCH_LIMITHARD: qc_attr_id = 69;
52+
pub const QC_ZIIP_DISPATCH_TYPE: qc_attr_id = 70;
53+
pub const QC_ZIIP_LIMITHARD_CAP: qc_attr_id = 71;
54+
pub const QC_ZIIP_WEIGHT_CAPPING: qc_attr_id = 72;
55+
pub const QC_LAYER_CATEGORY: qc_attr_id = 24;
56+
pub const QC_LAYER_CATEGORY_NUM: qc_attr_id = 25;
57+
pub const QC_LAYER_EXTENDED_NAME: qc_attr_id = 26;
58+
pub const QC_LAYER_NAME: qc_attr_id = 27;
59+
pub const QC_LAYER_TYPE: qc_attr_id = 28;
60+
pub const QC_LAYER_TYPE_NUM: qc_attr_id = 29;
61+
pub const QC_LAYER_UUID: qc_attr_id = 30;
62+
pub const QC_MANUFACTURER: qc_attr_id = 31;
63+
pub const QC_MOBILITY_ENABLED: qc_attr_id = 32;
64+
pub const QC_MOBILITY_ELIGIBLE: qc_attr_id = 32;
65+
pub const QC_HAS_SECURE: qc_attr_id = 77;
66+
pub const QC_SECURE: qc_attr_id = 78;
67+
pub const QC_MODEL: qc_attr_id = 33;
68+
pub const QC_MODEL_CAPACITY: qc_attr_id = 34;
69+
pub const QC_TYPE_FAMILY: qc_attr_id = 65;
70+
pub const QC_NUM_CP_DEDICATED: qc_attr_id = 35;
71+
pub const QC_NUM_CP_SHARED: qc_attr_id = 36;
72+
pub const QC_NUM_CP_TOTAL: qc_attr_id = 37;
73+
pub const QC_NUM_CPU_CONFIGURED: qc_attr_id = 38;
74+
pub const QC_NUM_CPU_DEDICATED: qc_attr_id = 39;
75+
pub const QC_NUM_CPU_RESERVED: qc_attr_id = 40;
76+
pub const QC_NUM_CPU_SHARED: qc_attr_id = 41;
77+
pub const QC_NUM_CPU_STANDBY: qc_attr_id = 42;
78+
pub const QC_NUM_CPU_TOTAL: qc_attr_id = 43;
79+
pub const QC_NUM_IFL_DEDICATED: qc_attr_id = 44;
80+
pub const QC_NUM_IFL_SHARED: qc_attr_id = 45;
81+
pub const QC_NUM_IFL_TOTAL: qc_attr_id = 46;
82+
pub const QC_NUM_ZIIP_DEDICATED: qc_attr_id = 73;
83+
pub const QC_NUM_ZIIP_SHARED: qc_attr_id = 74;
84+
pub const QC_NUM_ZIIP_TOTAL: qc_attr_id = 75;
85+
pub const QC_PARTITION_CHAR: qc_attr_id = 47;
86+
pub const QC_PARTITION_CHAR_NUM: qc_attr_id = 48;
87+
pub const QC_PARTITION_NUMBER: qc_attr_id = 49;
88+
pub const QC_PLANT: qc_attr_id = 50;
89+
pub const QC_SECONDARY_CAPABILITY: qc_attr_id = 51;
90+
pub const QC_SEQUENCE_CODE: qc_attr_id = 52;
91+
pub const QC_TYPE: qc_attr_id = 53;
92+
pub const QC_PRORATED_CORE_TIME: qc_attr_id = 54;
93+
pub const QC_NUM_CP_THREADS: qc_attr_id = 55;
94+
pub const QC_NUM_IFL_THREADS: qc_attr_id = 56;
95+
pub const QC_NUM_ZIIP_THREADS: qc_attr_id = 76;
96+
pub const QC_NUM_CORE_TOTAL: qc_attr_id = 57;
97+
pub const QC_NUM_CORE_CONFIGURED: qc_attr_id = 58;
98+
pub const QC_NUM_CORE_STANDBY: qc_attr_id = 59;
99+
pub const QC_NUM_CORE_RESERVED: qc_attr_id = 60;
100+
pub const QC_NUM_CORE_DEDICATED: qc_attr_id = 61;
101+
pub const QC_NUM_CORE_SHARED: qc_attr_id = 62;
102+
pub const QC_TYPE_NAME: qc_attr_id = 63;
103+
pub const QC_LIC_IDENTIFIER: qc_attr_id = 64;
104+
105+
extern "C" {
106+
pub fn qc_open(rc: *mut ::std::os::raw::c_int) -> *mut ::std::os::raw::c_void;
107+
pub fn qc_close(hdl: *mut ::std::os::raw::c_void);
108+
109+
pub fn qc_get_num_layers(
110+
hdl: *mut ::std::os::raw::c_void,
111+
rc: *mut ::std::os::raw::c_int,
112+
) -> ::std::os::raw::c_int;
113+
114+
pub fn qc_get_attribute_string(
115+
hdl: *mut ::std::os::raw::c_void,
116+
id: qc_attr_id,
117+
layer: ::std::os::raw::c_int,
118+
value: *mut *const ::std::os::raw::c_char,
119+
) -> ::std::os::raw::c_int;
120+
pub fn qc_get_attribute_int(
121+
hdl: *mut ::std::os::raw::c_void,
122+
id: qc_attr_id,
123+
layer: ::std::os::raw::c_int,
124+
value: *mut ::std::os::raw::c_int,
125+
) -> ::std::os::raw::c_int;
126+
pub fn qc_get_attribute_float(
127+
hdl: *mut ::std::os::raw::c_void,
128+
id: qc_attr_id,
129+
layer: ::std::os::raw::c_int,
130+
value: *mut ::std::os::raw::c_float,
131+
) -> ::std::os::raw::c_int;
132+
}

0 commit comments

Comments
 (0)