Publish header with toolchain versions

This change is an attempt to resolve [wasi-libc#490] but at the wasi-sdk
level. It adds a `version.h` header file to
`share/wasi-sysroot/include/<target>/wasi` so that users have
programmatic access to some extra information to output better error
messages, e.g. This `version.h` looks something like:

  ```c
  // Generated by wasi-sdk's `version.py` script.
  #ifndef VERSION_H
  #define VERSION_H

  #define WASI_SDK_VERSION "24.6g754aec3d6f58+m"
  #define WASI_LIBC_VERSION "b9ef79d7dbd4"

  #endif
  ```

It _is_ a bit strange that we're adding to wasi-libc's include files
from wasi-sdk (it would be cleaner if it happened in wasi-libc directly)
but wasi-sdk actually has the information available.

[wasi-libc#490]: https://github.com/WebAssembly/wasi-libc/issues/490
pull/487/head
Andrew Brown 4 months ago
parent 754aec3d6f
commit aa3373270d
No known key found for this signature in database

@ -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()

@ -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).')

Loading…
Cancel
Save