diff --git a/cmake/wasi-sdk-sysroot.cmake b/cmake/wasi-sdk-sysroot.cmake index 127ca62..debe8ac 100644 --- a/cmake/wasi-sdk-sysroot.cmake +++ b/cmake/wasi-sdk-sysroot.cmake @@ -336,6 +336,19 @@ file(GENERATE OUTPUT ${version_file_tmp} CONTENT ${version_dump}) add_custom_target(version-file DEPENDS ${version_file_tmp}) add_dependencies(build version-file) +# Install a `version.h` script in each sysroot's include directory. +execute_process( + COMMAND ${PYTHON} ${version_script} header + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE version_header) +foreach(target IN LISTS WASI_SDK_TARGETS) + message(STATUS "Creating version.h in ${version_dir}") + set(version_header_path ${wasi_sysroot}/include/${target}/wasi/version.h) + file(GENERATE OUTPUT ${version_header_path} CONTENT ${version_header}) + add_custom_target(version-header-${target} DEPENDS ${version_header_path}) + add_dependencies(build version-header-${target}) +endforeach() + if(WASI_SDK_INCLUDE_TESTS) add_subdirectory(tests) endif() diff --git a/version.py b/version.py index 62f0ff9..396c65e 100755 --- a/version.py +++ b/version.py @@ -62,7 +62,7 @@ assert parse_git_version( def git_version(): version = exec(['git', 'describe', '--long', '--candidates=999', '--match=wasi-sdk-*', '--dirty=+m', f'--abbrev={GIT_REF_LEN}'], - os.path.dirname(sys.argv[0])) + os.path.dirname(sys.argv[0])) major, minor, git, dirty = parse_git_version(version) version = f'{major}.{minor}' if git: @@ -109,13 +109,23 @@ def main(action, llvm_dir): major, minor, path = llvm_cmake_version(llvm_dir) print(f'llvm-version: {major}.{minor}.{path}') print(f'config: {git_commit("src/config")}') + elif action == 'header': + print('// Generated by wasi-sdk\'s `version.py` script.') + print('#ifndef VERSION_H') + print('#define VERSION_H') + print() + print(f'#define WASI_SDK_VERSION "{git_version()}"') + print(f'#define WASI_LIBC_VERSION "{git_commit("src/wasi-libc")}"') + print() + print('#endif') if __name__ == '__main__': parser = argparse.ArgumentParser( description='Print the various kinds of versions in wasi-sdk') parser.add_argument('action', - choices=['wasi-sdk', 'llvm', 'llvm-major', 'dump'], + choices=['wasi-sdk', 'llvm', + 'llvm-major', 'dump', 'header'], nargs='?', default='wasi-sdk', help='Which kind of version to print (default: wasi-sdk).')