diff --git a/emulator/CMakeLists.txt b/emulator/CMakeLists.txt index 7a4b7676..dc8cbf62 100644 --- a/emulator/CMakeLists.txt +++ b/emulator/CMakeLists.txt @@ -35,7 +35,7 @@ else() add_library(emulator STATIC ${EMULATOR_SOURCE} ${EMULATOR_HEADERS}) endif() -target_link_libraries(emulator PUBLIC emulator_static) +target_link_libraries(emulator PUBLIC emulator_static git) generate_export_header(emulator EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/emulator_export.h) target_include_directories(emulator PUBLIC $ @@ -48,7 +48,7 @@ if (USE_EMSCRIPTEN) add_executable(emulator-emscripten ${EMULATOR_EMSCRIPTEN_SOURCE}) target_link_libraries(emulator-emscripten PUBLIC emulator) target_link_options(emulator-emscripten PRIVATE -sEXPORTED_RUNTIME_METHODS=_malloc,free,UTF8ToString,stringToUTF8,allocate,ALLOC_NORMAL,lengthBytesUTF8) - target_link_options(emulator-emscripten PRIVATE -sEXPORTED_FUNCTIONS=_emulate,_free,_run_get_method,_create_emulator,_destroy_emulator,_emulate_with_emulator) + target_link_options(emulator-emscripten PRIVATE -sEXPORTED_FUNCTIONS=_emulate,_free,_run_get_method,_create_emulator,_destroy_emulator,_emulate_with_emulator,_version) target_link_options(emulator-emscripten PRIVATE -sEXPORT_NAME=EmulatorModule) target_link_options(emulator-emscripten PRIVATE -sERROR_ON_UNDEFINED_SYMBOLS=0) target_link_options(emulator-emscripten PRIVATE -Oz) diff --git a/emulator/emulator-emscripten.cpp b/emulator/emulator-emscripten.cpp index e76607c6..17639d28 100644 --- a/emulator/emulator-emscripten.cpp +++ b/emulator/emulator-emscripten.cpp @@ -254,4 +254,8 @@ const char *run_get_method(const char *params, const char* stack, const char* co return output; } +const char *version() { + return emulator_version(); +} + } \ No newline at end of file diff --git a/emulator/emulator-extern.cpp b/emulator/emulator-extern.cpp index 5710d4c8..52c374ed 100644 --- a/emulator/emulator-extern.cpp +++ b/emulator/emulator-extern.cpp @@ -9,6 +9,7 @@ #include "tvm-emulator.hpp" #include "crypto/vm/stack.hpp" #include "crypto/vm/memo.h" +#include "git.h" td::Result> boc_b64_to_cell(const char *boc) { TRY_RESULT_PREFIX(boc_decoded, td::base64_decode(td::Slice(boc)), "Can't decode base64 boc: "); @@ -717,3 +718,12 @@ void tvm_emulator_destroy(void *tvm_emulator) { void emulator_config_destroy(void *config) { delete static_cast(config); } + +const char* emulator_version() { + auto version_json = td::JsonBuilder(); + auto obj = version_json.enter_object(); + obj("emulatorLibCommitHash", GitMetadata::CommitSHA1()); + obj("emulatorLibCommitDate", GitMetadata::CommitDate()); + obj.leave(); + return strdup(version_json.string_builder().as_cslice().c_str()); +} diff --git a/emulator/emulator-extern.h b/emulator/emulator-extern.h index 28d38d78..e69a9cb0 100644 --- a/emulator/emulator-extern.h +++ b/emulator/emulator-extern.h @@ -307,6 +307,10 @@ EMULATOR_EXPORT void tvm_emulator_destroy(void *tvm_emulator); */ EMULATOR_EXPORT void emulator_config_destroy(void *config); +/** + * @brief Get git commit hash and date of the library + */ +EMULATOR_EXPORT const char* emulator_version(); #ifdef __cplusplus } // extern "C" diff --git a/emulator/emulator_export_list b/emulator/emulator_export_list index c719a393..feb653e2 100644 --- a/emulator/emulator_export_list +++ b/emulator/emulator_export_list @@ -26,3 +26,4 @@ _tvm_emulator_send_external_message _tvm_emulator_send_internal_message _tvm_emulator_destroy _tvm_emulator_emulate_run_method +_emulator_version