From 717e8a48e29be35a768a5d9f3c992d5f2b47fbaa Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 18 Aug 2022 19:01:05 +0800 Subject: [PATCH] Enable the semantic version mechanism for WAMR (#1374) Use the semantic versioning (https://semver.org) to replace the current date versioning system, which is more general and is requested by some developers, e.g. issue #1357. There are three parts in the new version string: - major. Any incompatible modification on ABIs and APIs will lead to an increment in the value of major, which mainly includes: AOT calling conventions, AOT file format, wasm_export.h, wasm_c_api.h, and so on. - minor. It represents new features, including MVP/POST-MVP features, libraries, WAMR private ones, and so one. - patch. It represents patches. The new version will start from 1.0.0. Update the help info and version showing for iwasm and wamrc. --- build-scripts/config_common.cmake | 18 +++++++++++++ core/iwasm/common/wasm_runtime_common.c | 9 +++++++ core/iwasm/include/wasm_export.h | 6 +++++ core/version.h | 14 +++++++++++ core/version.h.in | 14 +++++++++++ doc/semantic_version.md | 21 ++++++++++++++++ .../linux-sgx/enclave-sample/App/App.cpp | 25 +++++++++++++++++++ .../enclave-sample/Enclave/Enclave.cpp | 16 ++++++++++++ product-mini/platforms/posix/main.c | 7 ++++++ product-mini/platforms/windows/main.c | 7 ++++++ wamr-compiler/main.c | 7 ++++++ 11 files changed, 144 insertions(+) create mode 100644 core/version.h create mode 100644 core/version.h.in create mode 100644 doc/semantic_version.md diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 593954c9..84b7e2bf 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -116,6 +116,24 @@ else () unset (LLVM_AVAILABLE_LIBS) endif () +######################################## +## semantic version information + +if (NOT DEFINED WAMR_VERSION_MAJOR) + set (WAMR_VERSION_MAJOR 1) +endif () + +if (NOT DEFINED WAMR_VERSION_MINOR) + set (WAMR_VERSION_MINOR 0) +endif () + +if (NOT DEFINED WAMR_VERSION_PATCH) + set (WAMR_VERSION_PATCH 0) +endif () + +configure_file(${WAMR_ROOT_DIR}/core/version.h.in ${WAMR_ROOT_DIR}/core/version.h @ONLY) +######################################## + message ("-- Build Configurations:") message (" Build as target ${WAMR_BUILD_TARGET}") message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE}) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 22ff3553..c347a666 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -31,6 +31,7 @@ #include "../fast-jit/jit_compiler.h" #endif #include "../common/wasm_c_api_internal.h" +#include "../../version.h" /** * For runtime build, BH_MALLOC/BH_FREE should be defined as @@ -5055,3 +5056,11 @@ wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list) } } #endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION */ + +void +wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch) +{ + *major = WAMR_VERSION_MAJOR; + *minor = WAMR_VERSION_MINOR; + *patch = WAMR_VERSION_PATCH; +} \ No newline at end of file diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 7c30a7a7..9c1b3afc 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1137,6 +1137,12 @@ WASM_RUNTIME_API_EXTERN const uint8_t * wasm_runtime_get_custom_section(wasm_module_t const module_comm, const char *name, uint32_t *len); + +/** + * Get WAMR semantic version + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch); /* clang-format on */ #ifdef __cplusplus diff --git a/core/version.h b/core/version.h new file mode 100644 index 00000000..bbe3b78f --- /dev/null +++ b/core/version.h @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +/* Please don't modify this header. It is automatically generated. + Any modification should be in config_common.cmake */ + +#ifndef _WAMR_VERSION_H_ +#define _WAMR_VERSION_H_ +#define WAMR_VERSION_MAJOR 1 +#define WAMR_VERSION_MINOR 0 +#define WAMR_VERSION_PATCH 0 +#endif diff --git a/core/version.h.in b/core/version.h.in new file mode 100644 index 00000000..882305a8 --- /dev/null +++ b/core/version.h.in @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +/* Please don't modify this header. It is automatically generated. + Any modification should be in config_common.cmake */ + +#ifndef _WAMR_VERSION_H_ +#define _WAMR_VERSION_H_ +#cmakedefine WAMR_VERSION_MAJOR @WAMR_VERSION_MAJOR@ +#define WAMR_VERSION_MINOR @WAMR_VERSION_MINOR@ +#define WAMR_VERSION_PATCH @WAMR_VERSION_PATCH@ +#endif diff --git a/doc/semantic_version.md b/doc/semantic_version.md new file mode 100644 index 00000000..d0d46a5e --- /dev/null +++ b/doc/semantic_version.md @@ -0,0 +1,21 @@ +# WAMR uses semantic versioning + +WAMR uses the _semantic versioning_ to replace the current _date versioning_ system. + +There are three parts in the new version string: + +- _major_. Any incompatible modification, on both ABI and APIs, will lead an increment + in the value of _major_. APIs includes: `wasm_export.h`, `wasm_c_api.h`, + _sections in AOT files_, and so on. +- _minor_. It represents new features. It includes not just MVP or POST-MVP features + but also WASI features and WAMR private ones. +- _patch_. It represents patches. + +## Legacy versions + +All legacy versions(tags) will keep their current status. No existed releasings names +and links will be changed. + +## Reference + +- [Semantic Versioning 2.0.0](https://semver.org/) diff --git a/product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp b/product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp index 2a697285..eaf516ce 100644 --- a/product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp +++ b/product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp @@ -232,6 +232,7 @@ print_help() printf(" for example:\n"); printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n"); printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n"); + printf(" --version Show version information\n"); return 1; } /* clang-format on */ @@ -292,6 +293,7 @@ typedef enum EcallCmd { CMD_DESTROY_RUNTIME, /* wasm_runtime_destroy() */ CMD_SET_WASI_ARGS, /* wasm_runtime_set_wasi_args() */ CMD_SET_LOG_LEVEL, /* bh_log_set_verbose_level() */ + CMD_GET_VERSION, /* wasm_runtime_get_version() */ } EcallCmd; static void @@ -580,6 +582,23 @@ set_wasi_args(void *wasm_module, const char **dir_list, uint32_t dir_list_size, return (bool)ecall_args[0]; } +static void +get_version(uint64_t *major, uint64_t *minor, uint64_t *patch) +{ + uint64_t ecall_args[3] = { 0 }; + + if (SGX_SUCCESS + != ecall_handle_command(g_eid, CMD_GET_VERSION, (uint8_t *)ecall_args, + sizeof(ecall_args))) { + printf("Call ecall_handle_command() failed.\n"); + return; + } + + *major = ecall_args[0]; + *minor = ecall_args[1]; + *patch = ecall_args[2]; +} + int main(int argc, char *argv[]) { @@ -700,6 +719,12 @@ main(int argc, char *argv[]) return print_help(); max_thread_num = atoi(argv[0] + 14); } + else if (!strncmp(argv[0], "--version", 9)) { + uint64_t major = 0, minor = 0, patch = 0; + get_version(&major, &minor, &patch); + printf("iwasm %lu.%lu.%lu\n", major, minor, patch); + return 0; + } else return print_help(); } diff --git a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp index e8d266c3..ea48e9ae 100644 --- a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp +++ b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp @@ -44,6 +44,7 @@ typedef enum EcallCmd { CMD_DESTROY_RUNTIME, /* wasm_runtime_destroy() */ CMD_SET_WASI_ARGS, /* wasm_runtime_set_wasi_args() */ CMD_SET_LOG_LEVEL, /* bh_log_set_verbose_level() */ + CMD_GET_VERSION, /* wasm_runtime_get_version() */ } EcallCmd; typedef struct EnclaveModule { @@ -522,6 +523,18 @@ handle_cmd_set_wasi_args(uint64 *args, int32 argc) } #endif /* end of SGX_DISABLE_WASI */ +static void +handle_cmd_get_version(uint64 *args, uint32 argc) +{ + uint32 major, minor, patch; + bh_assert(argc == 3); + + wasm_runtime_get_version(&major, &minor, &patch); + args[0] = major; + args[1] = minor; + args[2] = patch; +} + void ecall_handle_command(unsigned cmd, unsigned char *cmd_buf, unsigned cmd_buf_size) @@ -569,6 +582,9 @@ ecall_handle_command(unsigned cmd, unsigned char *cmd_buf, case CMD_SET_LOG_LEVEL: handle_cmd_set_log_level(args, argc); break; + case CMD_GET_VERSION: + handle_cmd_get_version(args, argc); + break; default: LOG_ERROR("Unknown command %d\n", cmd); break; diff --git a/product-mini/platforms/posix/main.c b/product-mini/platforms/posix/main.c index 5fc89432..9d544e26 100644 --- a/product-mini/platforms/posix/main.c +++ b/product-mini/platforms/posix/main.c @@ -68,6 +68,7 @@ print_help() printf(" -g=ip:port Set the debug sever address, default is debug disabled\n"); printf(" if port is 0, then a random port will be used\n"); #endif + printf(" --version Show version information\n"); return 1; } /* clang-format on */ @@ -461,6 +462,12 @@ main(int argc, char *argv[]) ip_addr = argv[0] + 3; } #endif + else if (!strncmp(argv[0], "--version", 9)) { + uint32 major, minor, patch; + wasm_runtime_get_version(&major, &minor, &patch); + printf("iwasm %u.%u.%u\n", major, minor, patch); + return 0; + } else return print_help(); } diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index f044dc66..6d053c7a 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -50,6 +50,7 @@ print_help() printf(" -g=ip:port Set the debug sever address, default is debug disabled\n"); printf(" if port is 0, then a random port will be used\n"); #endif + printf(" --version Show version information\n"); return 1; } /* clang-format on */ @@ -339,6 +340,12 @@ main(int argc, char *argv[]) ip_addr = argv[0] + 3; } #endif + else if (!strncmp(argv[0], "--version", 9)) { + uint32 major, minor, patch; + wasm_runtime_get_version(&major, &minor, &patch); + printf("iwasm %u.%u.%u\n", major, minor, patch); + return 0; + } else return print_help(); } diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 67e3edbb..820420eb 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -63,6 +63,7 @@ print_help() printf(" multiple names, e.g.\n"); printf(" --emit-custom-sections=section1,section2,sectionN\n"); printf(" -v=n Set log verbose level (0 to 5, default is 2), larger with more log\n"); + printf(" --version Show version information\n"); printf("Examples: wamrc -o test.aot test.wasm\n"); printf(" wamrc --target=i386 -o test.aot test.wasm\n"); printf(" wamrc --target=i386 --format=object -o test.o test.wasm\n"); @@ -268,6 +269,12 @@ main(int argc, char *argv[]) option.custom_sections_count = len; } + else if (!strncmp(argv[0], "--version", 9)) { + uint32 major, minor, patch; + wasm_runtime_get_version(&major, &minor, &patch); + printf("wamrc %u.%u.%u\n", major, minor, patch); + return 0; + } else PRINT_HELP_AND_EXIT(); }