Skip to content

Commit d75005b

Browse files
committed
Avoid rebuilding check-symbols artifacts
Like other recent PRs, this change uses true file dependencies to avoid rebuilding the files used to check which symbols are defined or not. The true `git diff` test is still run each time, however.
1 parent fe15980 commit d75005b

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

Makefile

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LIBC_BOTTOM_HALF_OMIT_SOURCES := \
111111
LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES))
112112
# Omit p2-specific headers from include-all.c test.
113113
# for exception-handling.
114-
INCLUDE_ALL_CLAUSES := -not -name wasip2.h -not -name descriptor_table.h
114+
INCLUDE_ALL_CLAUSES += -not -name wasip2.h -not -name descriptor_table.h
115115
endif
116116

117117
ifeq ($(WASI_SNAPSHOT), p2)
@@ -906,58 +906,57 @@ finish: check-symbols
906906
endif
907907
endif
908908

909-
DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt
910-
UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt
909+
install: finish
910+
mkdir -p "$(INSTALL_DIR)"
911+
cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
911912

912-
ifeq ($(WASI_SNAPSHOT),p2)
913-
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
914-
else
915-
ifeq ($(THREAD_MODEL),posix)
916-
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
917-
else
918-
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
919-
endif
920-
endif
921913

914+
##### CHECK ####################################################################
915+
# The `check-symbols` target builds up a set of text files in `<sysroot>/share`
916+
# which are compared with known-good output in the `expected` directory.
917+
################################################################################
922918

923-
check-symbols: startup_files libc
924-
#
925-
# Collect metadata on the sysroot and perform sanity checks.
926-
#
919+
$(SYSROOT_SHARE)/defined-symbols.txt: startup_files libc
927920
mkdir -p "$(SYSROOT_SHARE)"
928-
929-
#
930-
# Collect symbol information.
931-
#
921+
"$(NM)" --defined-only \
922+
$(SYSROOT_LIB)/libc.a $(SYSROOT_LIB)/libwasi-emulated-*.a $(SYSROOT_LIB)/*.o \
923+
|grep ' [[:upper:]] ' \
924+
|sed 's/.* [[:upper:]] //' \
925+
|LC_ALL=C sort \
926+
|uniq \
927+
> "$@"
928+
929+
$(SYSROOT_SHARE)/undefined-symbols.txt: $(SYSROOT_SHARE)/defined-symbols.txt
932930
@# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on
933931
@# LLVM PR40497, which is fixed in 9.0, but not in 8.0.
934932
@# Ignore certain llvm builtin symbols such as those starting with __mul
935933
@# since these dependencies can vary between llvm versions.
936-
"$(NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
937-
|grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort |uniq > "$(DEFINED_SYMBOLS)"
938-
for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
939-
|grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
940-
grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \
941-
done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__tls_base" > "$(UNDEFINED_SYMBOLS)"
942-
grep '^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \
943-
> "$(SYSROOT_LIB)/libc.imports"
934+
for undef_sym in $$("$(NM)" --undefined-only $(SYSROOT_LIB)/libc.a $(SYSROOT_LIB)/libc-*.a $(SYSROOT_LIB)/*.o |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
935+
grep -q '\<'$$undef_sym'\>' "$<" || echo $$undef_sym; \
936+
done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__tls_base" > "$@"
944937

938+
$(SYSROOT_LIB)/libc.imports: $(SYSROOT_SHARE)/undefined-symbols.txt
939+
grep '^_*imported_wasi_' $< > $@
940+
941+
INCLUDE_ALL_CLAUSES += -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h -not -name setjmp.h
942+
$(SYSROOT_SHARE)/include-all.c: include_dirs
943+
mkdir -p "$(SYSROOT_SHARE)"
945944
#
946945
# Generate a test file that includes all public C header files.
947946
#
948947
# setjmp.h is excluded because it requires a different compiler option
949948
#
950949
cd "$(SYSROOT_INC)" && \
951-
for header in $$(find . -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h -not -name setjmp.h $(INCLUDE_ALL_CLAUSES) |grep -v /bits/ |grep -v /c++/); do \
950+
for header in $$(find . -type f $(INCLUDE_ALL_CLAUSES) |grep -v /bits/ |grep -v /c++/); do \
952951
echo '#include <'$$header'>' | sed 's/\.\///' ; \
953-
done |LC_ALL=C sort >$(SYSROOT_SHARE)/include-all.c ; \
952+
done |LC_ALL=C sort > $@; \
954953
cd - >/dev/null
955-
956954
#
957-
# Test that it compiles.
955+
# Test that all public C headers compile.
958956
#
959-
$(CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings
957+
$(CC) $(CFLAGS) -fsyntax-only "$@" -Wno-\#warnings
960958

959+
$(SYSROOT_SHARE)/predefined-macros.txt: $(SYSROOT_SHARE)/include-all.c
961960
#
962961
# Collect all the predefined macros, except for compiler version macros
963962
# which we don't need to track here.
@@ -987,7 +986,7 @@ check-symbols: startup_files libc
987986
@# TODO: Undefine __wasm_nontrapping_fptoint__ and __wasm_bulk_memory__, that are
988987
@# new to clang 20.
989988
@# TODO: As of clang 16, __GNUC_VA_LIST is #defined without a value.
990-
$(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
989+
$(CC) $(CFLAGS) "$<" \
991990
-isystem $(SYSROOT_INC) \
992991
-std=gnu17 \
993992
-E -dM -Wno-\#warnings \
@@ -1027,15 +1026,23 @@ check-symbols: startup_files libc
10271026
| grep -v '^#define __OPTIMIZE__' \
10281027
| grep -v '^#define assert' \
10291028
| grep -v '^#define __NO_INLINE__' \
1030-
> "$(SYSROOT_SHARE)/predefined-macros.txt"
1029+
> "$@"
10311030

1031+
# Pick which `expected` target to compare against.
1032+
ifeq ($(WASI_SNAPSHOT),p2)
1033+
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
1034+
else
1035+
ifeq ($(THREAD_MODEL),posix)
1036+
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
1037+
else
1038+
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
1039+
endif
1040+
endif
1041+
1042+
check-symbols: $(SYSROOT_SHARE)/defined-symbols.txt $(SYSROOT_SHARE)/undefined-symbols.txt $(SYSROOT_SHARE)/include-all.c $(SYSROOT_SHARE)/predefined-macros.txt $(SYSROOT_LIB)/libc.imports
10321043
# Check that the computed metadata matches the expected metadata.
10331044
# This ignores whitespace because on Windows the output has CRLF line endings.
1034-
diff -wur "$(EXPECTED_TARGET_DIR)" "$(SYSROOT_SHARE)"
1035-
1036-
install: finish
1037-
mkdir -p "$(INSTALL_DIR)"
1038-
cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
1045+
diff -wur $(EXPECTED_TARGET_DIR) $(SYSROOT_SHARE)
10391046

10401047
$(BINDING_WORK_DIR)/wasi-cli:
10411048
mkdir -p "$(BINDING_WORK_DIR)"

0 commit comments

Comments
 (0)