Skip to content

Commit 92c5bce

Browse files
committed
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. ``` 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]: WebAssembly/wasi-libc#490
1 parent 754aec3 commit 92c5bce

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cmake/wasi-sdk-sysroot.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ file(GENERATE OUTPUT ${version_file_tmp} CONTENT ${version_dump})
336336
add_custom_target(version-file DEPENDS ${version_file_tmp})
337337
add_dependencies(build version-file)
338338

339+
# Install a `version.h` script in each sysroot's include directory.
340+
execute_process(
341+
COMMAND ${PYTHON} ${version_script} header
342+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
343+
OUTPUT_VARIABLE version_header)
344+
foreach(target IN LISTS WASI_SDK_TARGETS)
345+
message(STATUS "Creating version.h in ${version_dir}")
346+
set(version_header_path ${wasi_sysroot}/include/${target}/wasi/version.h)
347+
file(GENERATE OUTPUT ${version_header_path} CONTENT ${version_header})
348+
add_custom_target(version-header-${target} DEPENDS ${version_header_path})
349+
add_dependencies(build version-header-${target})
350+
endforeach()
351+
339352
if(WASI_SDK_INCLUDE_TESTS)
340353
add_subdirectory(tests)
341354
endif()

version.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def parse_git_version(version):
6262
def git_version():
6363
version = exec(['git', 'describe', '--long', '--candidates=999',
6464
'--match=wasi-sdk-*', '--dirty=+m', f'--abbrev={GIT_REF_LEN}'],
65-
os.path.dirname(sys.argv[0]))
65+
os.path.dirname(sys.argv[0]))
6666
major, minor, git, dirty = parse_git_version(version)
6767
version = f'{major}.{minor}'
6868
if git:
@@ -109,13 +109,23 @@ def main(action, llvm_dir):
109109
major, minor, path = llvm_cmake_version(llvm_dir)
110110
print(f'llvm-version: {major}.{minor}.{path}')
111111
print(f'config: {git_commit("src/config")}')
112+
elif action == 'header':
113+
print('// Generated by wasi-sdk\'s `version.py` script.')
114+
print('#ifndef VERSION_H')
115+
print('#define VERSION_H')
116+
print()
117+
print(f'#define WASI_SDK_VERSION "{git_version()}"')
118+
print(f'#define WASI_LIBC_VERSION "{git_commit("src/wasi-libc")}"')
119+
print()
120+
print('#endif')
112121

113122

114123
if __name__ == '__main__':
115124
parser = argparse.ArgumentParser(
116125
description='Print the various kinds of versions in wasi-sdk')
117126
parser.add_argument('action',
118-
choices=['wasi-sdk', 'llvm', 'llvm-major', 'dump'],
127+
choices=['wasi-sdk', 'llvm',
128+
'llvm-major', 'dump', 'header'],
119129
nargs='?',
120130
default='wasi-sdk',
121131
help='Which kind of version to print (default: wasi-sdk).')

0 commit comments

Comments
 (0)