Skip to content

Commit 1d6e16b

Browse files
committed
cbindgen: Add version defines
This will allow users to check the version of rustls-ffi without resorting to checking if functions are defined. In addition to RUSTLS_VERSION_{MAJOR,MINOR,PATCH}, also define RUSTLS_VERSION_NUMBER, which includes each version part in it, bit shifted to the left. This is inspired by openssl[0], c-ares[1]. There are other options for this, for example zstd multiplies each part by a power of 100[2]. We might want to also have the entire version string here, which could help tools that need to parse the header file itself. [0] https://github.com/openssl/openssl/blob/cdd01b5e0734b0324251b32a8edd97f42ba90429/include/openssl/opensslv.h.in#L92-L102 [1] https://github.com/c-ares/c-ares/blob/42ddbc14ec008e738fa44aa2c16e74cad93742c2/include/ares_version.h#L43-L45 [2] https://github.com/facebook/zstd/blob/3c3b8274c517727952927c705940eb90c10c736f/lib/zstd.h#L115 Fixes #557
1 parent 9779eb7 commit 1d6e16b

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

librustls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[package]
22
name = "rustls-ffi"
3+
# Keep in sync with defines in cbindgen.toml
34
version = "0.15.0"
45
license = "Apache-2.0 OR ISC OR MIT"
56
readme = "../README-crates.io.md"

librustls/cbindgen.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ language = "C"
33

44
usize_is_size_t = true
55

6+
# Keep in sync with "package.version" in Cargo.toml
7+
after_includes = """
8+
9+
#define RUSTLS_VERSION_MAJOR 0
10+
#define RUSTLS_VERSION_MINOR 15
11+
#define RUSTLS_VERSION_PATCH 0
12+
13+
/**
14+
* This gives each version part 8 bits, and leaves the 8 least significant bits
15+
* empty for future additions, for example pre-release versions.
16+
*/
17+
#define RUSTLS_VERSION_NUMBER ((RUSTLS_VERSION_MAJOR << 24) \\
18+
|(RUSTLS_VERSION_MINOR << 16) \\
19+
|(RUSTLS_VERSION_MINOR << 8))"""
20+
621
[enum]
722
prefix_with_name = true
823
rename_variants = "ScreamingSnakeCase"

librustls/src/rustls.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
#include <stdint.h>
88
#include <stdlib.h>
99

10+
#define RUSTLS_VERSION_MAJOR 0
11+
#define RUSTLS_VERSION_MINOR 15
12+
#define RUSTLS_VERSION_PATCH 0
13+
14+
/**
15+
* This gives each version part 8 bits, and leaves the 8 least significant bits
16+
* empty for future additions, for example pre-release versions.
17+
*/
18+
#define RUSTLS_VERSION_NUMBER ((RUSTLS_VERSION_MAJOR << 24) \
19+
|(RUSTLS_VERSION_MINOR << 16) \
20+
|(RUSTLS_VERSION_MINOR << 8))
21+
1022
/**
1123
* Describes which sort of handshake happened.
1224
*/

0 commit comments

Comments
 (0)