diff --git a/Makefile b/Makefile index 174115e2..2345a814 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ @@ -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. diff --git a/expected/wasm32-wasip1-threads/include-all.c b/expected/wasm32-wasip1-threads/include-all.c index 50733743..5f01f06a 100644 --- a/expected/wasm32-wasip1-threads/include-all.c +++ b/expected/wasm32-wasip1-threads/include-all.c @@ -170,5 +170,6 @@ #include #include #include +#include #include #include diff --git a/expected/wasm32-wasip1-threads/predefined-macros.txt b/expected/wasm32-wasip1-threads/predefined-macros.txt index 644e3697..2b8fec8a 100644 --- a/expected/wasm32-wasip1-threads/predefined-macros.txt +++ b/expected/wasm32-wasip1-threads/predefined-macros.txt @@ -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 diff --git a/expected/wasm32-wasip1/include-all.c b/expected/wasm32-wasip1/include-all.c index 50733743..5f01f06a 100644 --- a/expected/wasm32-wasip1/include-all.c +++ b/expected/wasm32-wasip1/include-all.c @@ -170,5 +170,6 @@ #include #include #include +#include #include #include diff --git a/expected/wasm32-wasip1/predefined-macros.txt b/expected/wasm32-wasip1/predefined-macros.txt index 2fb588ce..48b7ccf2 100644 --- a/expected/wasm32-wasip1/predefined-macros.txt +++ b/expected/wasm32-wasip1/predefined-macros.txt @@ -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 diff --git a/expected/wasm32-wasip2/include-all.c b/expected/wasm32-wasip2/include-all.c index 2efa2ded..5885a978 100644 --- a/expected/wasm32-wasip2/include-all.c +++ b/expected/wasm32-wasip2/include-all.c @@ -171,6 +171,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index ea346a9d..b76ce5e0 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -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 diff --git a/libc-bottom-half/headers/public/wasi/version.h.in b/libc-bottom-half/headers/public/wasi/version.h.in new file mode 100644 index 00000000..2a2f7ad8 --- /dev/null +++ b/libc-bottom-half/headers/public/wasi/version.h.in @@ -0,0 +1,5 @@ +// Generated by wasi-lib's `Makefile`. +#ifndef VERSION_H +#define VERSION_H +#define WASI_LIBC_VERSION "{{VERSION}}" +#endif