Skip to content

Commit da904d2

Browse files
committed
Add version.h defining WASI_LIBC_VERSION
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
1 parent 7d4d3b8 commit da904d2

File tree

8 files changed

+20
-0
lines changed

8 files changed

+20
-0
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ endif
6868

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

71+
LIBC_GIT_REF := $(shell git describe --tags --dirty)
72+
7173
# These variables describe the locations of various files and directories in
7274
# the source tree.
7375
DLMALLOC_DIR = dlmalloc
@@ -771,6 +773,12 @@ include_dirs:
771773
mkdir -p "$(SYSROOT_INC)"
772774
cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)"
773775

776+
# Generate the version.h header (and remove the template).
777+
rm -f "$(SYSROOT_INC)/wasi/version.h.in"
778+
sed 's/{{VERSION}}/$(LIBC_GIT_REF)/' \
779+
$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)/wasi/version.h.in \
780+
> "$(SYSROOT_INC)/wasi/version.h"
781+
774782
# Generate musl's bits/alltypes.h header.
775783
mkdir -p "$(SYSROOT_INC)/bits"
776784
sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \
@@ -973,6 +981,7 @@ check-symbols: startup_files libc
973981
| grep -v '^#define __OPTIMIZE__' \
974982
| grep -v '^#define assert' \
975983
| grep -v '^#define __NO_INLINE__' \
984+
| grep -v '^#define WASI_LIBC_VERSION' \
976985
> "$(SYSROOT_SHARE)/predefined-macros.txt"
977986

978987
# Check that the computed metadata matches the expected metadata.

expected/wasm32-wasip1-threads/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,6 @@
170170
#include <wasi/libc-find-relpath.h>
171171
#include <wasi/libc-nocwd.h>
172172
#include <wasi/libc.h>
173+
#include <wasi/version.h>
173174
#include <wchar.h>
174175
#include <wctype.h>

expected/wasm32-wasip1-threads/predefined-macros.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@
19941994
#define USHRT_MAX 0xffff
19951995
#define UTIME_NOW (-1)
19961996
#define UTIME_OMIT (-2)
1997+
#define VERSION_H
19971998
#define WCHAR_MAX (0x7fffffff+L'\0')
19981999
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
19992000
#define WEOF 0xffffffffU

expected/wasm32-wasip1/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,6 @@
170170
#include <wasi/libc-find-relpath.h>
171171
#include <wasi/libc-nocwd.h>
172172
#include <wasi/libc.h>
173+
#include <wasi/version.h>
173174
#include <wchar.h>
174175
#include <wctype.h>

expected/wasm32-wasip1/predefined-macros.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,7 @@
19891989
#define USHRT_MAX 0xffff
19901990
#define UTIME_NOW (-1)
19911991
#define UTIME_OMIT (-2)
1992+
#define VERSION_H
19921993
#define WCHAR_MAX (0x7fffffff+L'\0')
19931994
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
19941995
#define WEOF 0xffffffffU

expected/wasm32-wasip2/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
#include <wasi/libc-find-relpath.h>
172172
#include <wasi/libc-nocwd.h>
173173
#include <wasi/libc.h>
174+
#include <wasi/version.h>
174175
#include <wasi/wasip2.h>
175176
#include <wchar.h>
176177
#include <wctype.h>

expected/wasm32-wasip2/predefined-macros.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,7 @@
21392139
#define USHRT_MAX 0xffff
21402140
#define UTIME_NOW (-1)
21412141
#define UTIME_OMIT (-2)
2142+
#define VERSION_H
21422143
#define WCHAR_MAX (0x7fffffff+L'\0')
21432144
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
21442145
#define WEOF 0xffffffffU
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Generated by wasi-lib's `Makefile`.
2+
#ifndef VERSION_H
3+
#define VERSION_H
4+
#define WASI_LIBC_VERSION "{{VERSION}}"
5+
#endif

0 commit comments

Comments
 (0)