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

Conversation

abrown
Copy link
Collaborator

@abrown abrown commented Sep 5, 2024

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:

// 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.

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]: WebAssembly/wasi-libc#490
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.

@grynspan
Copy link

grynspan commented Sep 5, 2024

Thanks very much for looking into this! This would solve our problem very neatly!

To be clear, would I want to include <version.h> or would it be located elsewhere?

@sbc100
Copy link
Member

sbc100 commented Sep 5, 2024

Thanks very much for looking into this! This would solve our problem very neatly!

To be clear, would I want to include <version.h> or would it be located elsewhere?

I think you would include <wasi/version.h>. We certainly wouldn't want to call the file version.h if it was in the default include path, as that would be asking for trouble.

@abrown
Copy link
Collaborator Author

abrown commented Sep 5, 2024

To be clear, would I want to include <version.h> or would it be located elsewhere?

@grynspan, I think it would be <wasi/version.h>?

@yamt
Copy link
Contributor

yamt commented Sep 5, 2024

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)

yes.
i'm against this because it introduces an incompatibility between wasi-sdk and direct use of wasi-libc.
(programs including this header won't build for the latter)

abrown added a commit to abrown/wasi-libc that referenced this pull request Sep 12, 2024
This change re-imagines [wasi-sdk#487] entirely in `wasi-libc`. Instead
of generating a `version.h` header late--in `wasi-sdk`--it is generated
immediately when `wasi-libc` is built. This has the disadvantage that we
don't know what `wasi-sdk` this will be used in... but almost: when
releasing `wasi-sdk`, we _should_ be tagging the `wasi-libc` repository.
If we did that more faithfully ([docs]), this commit would generate:

  ```c
  // Generated by wasi-lib's `Makefile`.
  #ifndef VERSION_H
  #define VERSION_H
  #define WASI_LIBC_VERSION "wasi-sdk-24"
  #endif
  ```

Using the magic of `git-describe`, if someone is using `wasi-libc`
directly, they may see a version like: `wasi-sdk-22-19-g5d3c5e9-dirty`.
This should be read like: `<wasi-sdk tag>-<# commits since
tag>-<current commit>-<is the repository dirty?>`.

[wasi-sdk#487]: WebAssembly/wasi-sdk#487
[docs]: https://github.com/WebAssembly/wasi-sdk/blob/754aec3/RELEASING.md?plain=1#L22
@abrown
Copy link
Collaborator Author

abrown commented Sep 12, 2024

If we did this exclusively in wasi-libc it could look like: WebAssembly/wasi-libc#534.

@grynspan
Copy link

Could the two be combined? Such that -libc provides its version and -sdk provides its version?

abrown added a commit to abrown/wasi-libc that referenced this pull request Sep 18, 2024
This change re-imagines [wasi-sdk#487] entirely in `wasi-libc`. Instead
of generating a `version.h` header late--in `wasi-sdk`--it is generated
immediately when `wasi-libc` is built. This has the disadvantage that we
don't know what `wasi-sdk` this will be used in... but almost: when
releasing `wasi-sdk`, we _should_ be tagging the `wasi-libc` repository.
If we did that more faithfully ([docs]), this commit would generate:

  ```c
  // Generated by wasi-lib's `Makefile`.
  #ifndef VERSION_H
  #define VERSION_H
  #define WASI_LIBC_VERSION "wasi-sdk-24"
  #endif
  ```

Using the magic of `git-describe`, if someone is using `wasi-libc`
directly, they may see a version like: `wasi-sdk-22-19-g5d3c5e9-dirty`.
This should be read like: `<wasi-sdk tag>-<# commits since
tag>-<current commit>-<is the repository dirty?>`.

[wasi-sdk#487]: WebAssembly/wasi-sdk#487
[docs]: https://github.com/WebAssembly/wasi-sdk/blob/754aec3/RELEASING.md?plain=1#L22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement request: interface to get the wasi-libc version at runtime
4 participants