Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish header with toolchain versions #487

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmake/wasi-sdk-sysroot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more traditional cmake way of doing this would be to create a template file called version.h that looks like this:

#ifndef VERSION_H
#define WASI_SDK_VERSION @WASI_SDK_VERSION@
#define WASI_LIBC_VERSION @WASI_LIBC_VERSION@
#endif

And then use configure_file : https://cmake.org/cmake/help/latest/command/configure_file.html

Then you would just need to set WASI_LIBC_VERSION and WASI_SDK_VERSION as cmake variables (presumably still by running version.py.. but without needing to add anything new to version.py I would hope).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that better for the most part but I was worried about having a non-functional file cause problems. That approach means that we would add a non-functional version.h file to wasi-libc that kind of hangs around un-configured until it is seen by wasi-sdk. For those users who interact with wasi-libc directly (not through wasi-sdk), wouldn't they see an error if they included that un-configured version.h?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, the non-functional file is called version.h.in.. which is used to create the functional version.h, so they won't be confused.


if(WASI_SDK_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
Expand Down
14 changes: 12 additions & 2 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def parse_git_version(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:
Expand Down Expand Up @@ -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).')
Expand Down
Loading