C++: add version macro

Fixes #705
This commit is contained in:
Olivier Goffart 2021-12-06 15:36:16 +01:00 committed by GitHub
parent f27a2b8c74
commit 53775465dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 9 deletions

View file

@ -340,21 +340,30 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
.with_include("sixtyfps_image.h")
.with_include("sixtyfps_pathdata.h")
.with_include("sixtyfps_brush.h")
.with_after_include(format!(
.with_header(format!(
r"
namespace sixtyfps {{
namespace private_api {{ enum class VersionCheck {{ Major = {}, Minor = {}, Patch = {} }}; class WindowRc; }}
namespace cbindgen_private {{
#define SIXTYFPS_VERSION_MAJOR {}
#define SIXTYFPS_VERSION_MINOR {}
#define SIXTYFPS_VERSION_PATCH {}
",
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR"),
env!("CARGO_PKG_VERSION_PATCH"),
))
.with_after_include(
r"
namespace sixtyfps {
namespace private_api { class WindowRc; }
namespace cbindgen_private {
using sixtyfps::private_api::WindowRc;
using namespace vtable;
struct KeyEvent; struct PointerEvent;
using private_api::Property;
using private_api::PathData;
using private_api::Point;
}}
}}",
env!("CARGO_PKG_VERSION_MAJOR"), env!("CARGO_PKG_VERSION_MINOR"), env!("CARGO_PKG_VERSION_PATCH"),
))
}
}",
)
.with_trailer(gen_item_declarations(&items))
.generate()
.expect("Unable to generate bindings")

View file

@ -42,6 +42,19 @@ struct ItemVTable;
/// \endrst
namespace sixtyfps {
// these macro are defined in the generated sixtyfps_internal.h
#if defined(DOXYGEN)
/// This macro expands to the to the numeric value of the major version of SixtyFPS you're developing against.
/// For example if you're using version 1.5.2, this macro will expand to 1.
#define SIXTYFPS_VERSION_MAJOR SIXTYFPS_VERSION_MAJOR
/// This macro expands to the to the numeric value of the minor version of SixtyFPS you're developing against.
/// For example if you're using version 1.5.2, this macro will expand to 5.
#define SIXTYFPS_VERSION_MINOR SIXTYFPS_VERSION_MINOR
/// This macro expands to the to the numeric value of the patch version of SixtyFPS you're developing against.
/// For example if you're using version 1.5.2, this macro will expand to 2.
#define SIXTYFPS_VERSION_PATCH SIXTYFPS_VERSION_PATCH
#endif
// Bring opaque structure in scope
namespace private_api {
using cbindgen_private::ComponentVTable;
@ -756,6 +769,12 @@ inline bool operator!=(const StandardListViewItem &a, const StandardListViewItem
}
namespace private_api {
// Code generated by SixtyFPS <= 0.1.5 uses this enum with VersionCheckHelper
enum class [[deprecated]] VersionCheck {
Major = SIXTYFPS_VERSION_MAJOR,
Minor = SIXTYFPS_VERSION_MINOR,
Patch = SIXTYFPS_VERSION_PATCH
};
template<int Major, int Minor, int Patch>
struct VersionCheckHelper
{

View file

@ -702,7 +702,7 @@ pub fn generate(doc: &Document, diag: &mut BuildDiagnostics) -> Option<impl std:
env!("CARGO_PKG_VERSION_MINOR"),
env!("CARGO_PKG_VERSION_PATCH")),
name: "THE_SAME_VERSION_MUST_BE_USED_FOR_THE_COMPILER_AND_THE_RUNTIME".into(),
init: Some("sixtyfps::private_api::VersionCheckHelper<int(sixtyfps::private_api::VersionCheck::Major), int(sixtyfps::private_api::VersionCheck::Minor), int(sixtyfps::private_api::VersionCheck::Patch)>()".into()),
init: Some("sixtyfps::private_api::VersionCheckHelper<SIXTYFPS_VERSION_MAJOR, SIXTYFPS_VERSION_MINOR, SIXTYFPS_VERSION_PATCH>()".into()),
..Default::default()
}));