Skip to content

Commit

Permalink
Add version.h defining WASI_LIBC_VERSION
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abrown committed Sep 12, 2024
1 parent 5d3c5e9 commit a2bdc56
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ endif

BUILTINS_LIB ?= $(shell ${CC} ${CFLAGS} --print-libgcc-file-name)

LIBC_GIT_REF := $(shell git describe --tags --dirty)

# These variables describe the locations of various files and directories in
# the source tree.
DLMALLOC_DIR = dlmalloc
Expand Down Expand Up @@ -755,6 +757,12 @@ include_dirs:
mkdir -p "$(SYSROOT_INC)"
cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)"

# Generate the version.h header (and remove the template).
rm -f "$(SYSROOT_INC)/wasi/version.h.in"
sed 's/{{VERSION}}/$(LIBC_GIT_REF)/' \
$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)/wasi/version.h.in \
> "$(SYSROOT_INC)/wasi/version.h"

# Generate musl's bits/alltypes.h header.
mkdir -p "$(SYSROOT_INC)/bits"
sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \
Expand Down Expand Up @@ -957,6 +965,7 @@ check-symbols: startup_files libc
| grep -v '^#define __OPTIMIZE__' \
| grep -v '^#define assert' \
| grep -v '^#define __NO_INLINE__' \
| grep -v '^#define WASI_LIBC_VERSION' \
> "$(SYSROOT_SHARE)/predefined-macros.txt"

# Check that the computed metadata matches the expected metadata.
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1-threads/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@
#include <wasi/libc-find-relpath.h>
#include <wasi/libc-nocwd.h>
#include <wasi/libc.h>
#include <wasi/version.h>
#include <wchar.h>
#include <wctype.h>
1 change: 1 addition & 0 deletions expected/wasm32-wasip1-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@
#define USHRT_MAX 0xffff
#define UTIME_NOW (-1)
#define UTIME_OMIT (-2)
#define VERSION_H
#define WCHAR_MAX (0x7fffffff+L'\0')
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
#define WEOF 0xffffffffU
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@
#include <wasi/libc-find-relpath.h>
#include <wasi/libc-nocwd.h>
#include <wasi/libc.h>
#include <wasi/version.h>
#include <wchar.h>
#include <wctype.h>
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@
#define USHRT_MAX 0xffff
#define UTIME_NOW (-1)
#define UTIME_OMIT (-2)
#define VERSION_H
#define WCHAR_MAX (0x7fffffff+L'\0')
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
#define WEOF 0xffffffffU
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
#include <wasi/libc-find-relpath.h>
#include <wasi/libc-nocwd.h>
#include <wasi/libc.h>
#include <wasi/version.h>
#include <wasi/wasip2.h>
#include <wchar.h>
#include <wctype.h>
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,7 @@
#define USHRT_MAX 0xffff
#define UTIME_NOW (-1)
#define UTIME_OMIT (-2)
#define VERSION_H
#define WCHAR_MAX (0x7fffffff+L'\0')
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
#define WEOF 0xffffffffU
Expand Down
5 changes: 5 additions & 0 deletions libc-bottom-half/headers/public/wasi/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Generated by wasi-lib's `Makefile`.
#ifndef VERSION_H
#define VERSION_H
#define WASI_LIBC_VERSION "{{VERSION}}"
#endif

0 comments on commit a2bdc56

Please sign in to comment.