aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/udf/udf_version.h
blob: 8045789bfc0ddc198a9f4e01c9c9112f194e3bad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

#include <util/generic/fwd.h>
#include <util/system/types.h>

namespace NYql {
namespace NUdf {

#define CURRENT_UDF_ABI_VERSION_MAJOR 2
#define CURRENT_UDF_ABI_VERSION_MINOR 40
#define CURRENT_UDF_ABI_VERSION_PATCH 0

#ifdef USE_CURRENT_UDF_ABI_VERSION
#define UDF_ABI_VERSION_MAJOR CURRENT_UDF_ABI_VERSION_MAJOR
#define UDF_ABI_VERSION_MINOR CURRENT_UDF_ABI_VERSION_MINOR
#define UDF_ABI_VERSION_PATCH CURRENT_UDF_ABI_VERSION_PATCH
#else
#if !defined(UDF_ABI_VERSION_MAJOR) || !defined(UDF_ABI_VERSION_MINOR) || !defined(UDF_ABI_VERSION_PATCH)
#error Please use UDF_ABI_VERSION macro to define ABI version
#endif
#endif

inline const char* CurrentAbiVersionStr()
{
#define str(s) #s
#define xstr(s) str(s)

    return xstr(UDF_ABI_VERSION_MAJOR) "."
            xstr(UDF_ABI_VERSION_MINOR) "."
            xstr(UDF_ABI_VERSION_PATCH);

#undef str
#undef xstr
}

#define UDF_ABI_COMPATIBILITY_VERSION(MAJOR, MINOR) ((MAJOR) * 100 + (MINOR))
#define UDF_ABI_COMPATIBILITY_VERSION_CURRENT UDF_ABI_COMPATIBILITY_VERSION(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR)

static_assert(UDF_ABI_COMPATIBILITY_VERSION_CURRENT <=
    UDF_ABI_COMPATIBILITY_VERSION(CURRENT_UDF_ABI_VERSION_MAJOR, CURRENT_UDF_ABI_VERSION_MINOR),
    "UDF ABI version " Y_STRINGIZE(UDF_ABI_VERSION_MAJOR) "." Y_STRINGIZE(UDF_ABI_VERSION_MINOR)
    " is above " Y_STRINGIZE(CURRENT_UDF_ABI_VERSION_MAJOR) "." Y_STRINGIZE(CURRENT_UDF_ABI_VERSION_MINOR));

constexpr ui32 MakeAbiVersion(ui8 major, ui8 minor, ui8 patch)
{
    return major * 10000 + minor * 100 + patch;
}

constexpr ui16 MakeAbiCompatibilityVersion(ui8 major, ui8 minor)
{
    return major * 100 + minor;
}

constexpr ui32 CurrentAbiVersion()
{
    return MakeAbiVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR, UDF_ABI_VERSION_PATCH);
}

constexpr ui32 CurrentCompatibilityAbiVersion()
{
    return MakeAbiCompatibilityVersion(UDF_ABI_VERSION_MAJOR, UDF_ABI_VERSION_MINOR);
}

constexpr bool IsAbiCompatible(ui32 version)
{
    // backward compatibility in greater minor versions of host
    return version / 10000 == UDF_ABI_VERSION_MAJOR &&
            (version / 100) % 100 <= UDF_ABI_VERSION_MINOR;
}

TString AbiVersionToStr(ui32 version);

} // namspace NUdf
} // namspace NYql

namespace NKikimr { namespace NUdf = ::NYql::NUdf; }