Skip to content

Commit 2ef2881

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 c47daaf commit 2ef2881

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
@@ -115,7 +115,7 @@ LIBC_BOTTOM_HALF_OMIT_SOURCES := \
115115
LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES))
116116
# Omit p2-specific headers from include-all.c test.
117117
# for exception-handling.
118-
INCLUDE_ALL_CLAUSES := -not -name wasip2.h -not -name descriptor_table.h
118+
INCLUDE_ALL_CLAUSES += -not -name wasip2.h -not -name descriptor_table.h
119119
endif
120120

121121
ifeq ($(WASI_SNAPSHOT), p2)
@@ -921,58 +921,57 @@ finish: check-symbols
921921
endif
922922
endif
923923

924-
DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt
925-
UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt
924+
install: finish
925+
mkdir -p "$(INSTALL_DIR)"
926+
cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
926927

927-
ifeq ($(WASI_SNAPSHOT),p2)
928-
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
929-
else
930-
ifeq ($(THREAD_MODEL),posix)
931-
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
932-
else
933-
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
934-
endif
935-
endif
936928

929+
##### CHECK ####################################################################
930+
# The `check-symbols` target builds up a set of text files in `<sysroot>/share`
931+
# which are compared with known-good output in the `expected` directory.
932+
################################################################################
937933

938-
check-symbols: startup_files libc
939-
#
940-
# Collect metadata on the sysroot and perform sanity checks.
941-
#
934+
$(SYSROOT_SHARE)/defined-symbols.txt: startup_files libc
942935
mkdir -p "$(SYSROOT_SHARE)"
943-
944-
#
945-
# Collect symbol information.
946-
#
936+
"$(NM)" --defined-only \
937+
$(SYSROOT_LIB)/libc.a $(SYSROOT_LIB)/libwasi-emulated-*.a $(SYSROOT_LIB)/*.o \
938+
|grep ' [[:upper:]] ' \
939+
|sed 's/.* [[:upper:]] //' \
940+
|LC_ALL=C sort \
941+
|uniq \
942+
> "$@"
943+
944+
$(SYSROOT_SHARE)/undefined-symbols.txt: $(SYSROOT_SHARE)/defined-symbols.txt
947945
@# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on
948946
@# LLVM PR40497, which is fixed in 9.0, but not in 8.0.
949947
@# Ignore certain llvm builtin symbols such as those starting with __mul
950948
@# since these dependencies can vary between llvm versions.
951-
"$(NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
952-
|grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort |uniq > "$(DEFINED_SYMBOLS)"
953-
for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
954-
|grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
955-
grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \
956-
done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__tls_base" > "$(UNDEFINED_SYMBOLS)"
957-
grep '^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \
958-
> "$(SYSROOT_LIB)/libc.imports"
949+
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 \
950+
grep -q '\<'$$undef_sym'\>' "$<" || echo $$undef_sym; \
951+
done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__tls_base" > "$@"
959952

953+
$(SYSROOT_LIB)/libc.imports: $(SYSROOT_SHARE)/undefined-symbols.txt
954+
grep '^_*imported_wasi_' $< > $@
955+
956+
INCLUDE_ALL_CLAUSES += -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h -not -name setjmp.h
957+
$(SYSROOT_SHARE)/include-all.c: $(INCLUDE_DIRS)
958+
mkdir -p "$(SYSROOT_SHARE)"
960959
#
961960
# Generate a test file that includes all public C header files.
962961
#
963962
# setjmp.h is excluded because it requires a different compiler option
964963
#
965964
cd "$(SYSROOT_INC)" && \
966-
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 \
965+
for header in $$(find . -type f $(INCLUDE_ALL_CLAUSES) |grep -v /bits/ |grep -v /c++/); do \
967966
echo '#include <'$$header'>' | sed 's/\.\///' ; \
968-
done |LC_ALL=C sort >$(SYSROOT_SHARE)/include-all.c ; \
967+
done |LC_ALL=C sort > $@; \
969968
cd - >/dev/null
970-
971969
#
972-
# Test that it compiles.
970+
# Test that all public C headers compile.
973971
#
974-
$(CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings
972+
$(CC) $(CFLAGS) -fsyntax-only "$@" -Wno-\#warnings
975973

974+
$(SYSROOT_SHARE)/predefined-macros.txt: $(SYSROOT_SHARE)/include-all.c
976975
#
977976
# Collect all the predefined macros, except for compiler version macros
978977
# which we don't need to track here.
@@ -1002,7 +1001,7 @@ check-symbols: startup_files libc
10021001
@# TODO: Undefine __wasm_nontrapping_fptoint__ and __wasm_bulk_memory__, that are
10031002
@# new to clang 20.
10041003
@# TODO: As of clang 16, __GNUC_VA_LIST is #defined without a value.
1005-
$(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
1004+
$(CC) $(CFLAGS) "$<" \
10061005
-isystem $(SYSROOT_INC) \
10071006
-std=gnu17 \
10081007
-E -dM -Wno-\#warnings \
@@ -1042,15 +1041,23 @@ check-symbols: startup_files libc
10421041
| grep -v '^#define __OPTIMIZE__' \
10431042
| grep -v '^#define assert' \
10441043
| grep -v '^#define __NO_INLINE__' \
1045-
> "$(SYSROOT_SHARE)/predefined-macros.txt"
1044+
> "$@"
10461045

1046+
# Pick which `expected` target to compare against.
1047+
ifeq ($(WASI_SNAPSHOT),p2)
1048+
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
1049+
else
1050+
ifeq ($(THREAD_MODEL),posix)
1051+
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
1052+
else
1053+
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
1054+
endif
1055+
endif
1056+
1057+
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
10471058
# Check that the computed metadata matches the expected metadata.
10481059
# This ignores whitespace because on Windows the output has CRLF line endings.
1049-
diff -wur "$(EXPECTED_TARGET_DIR)" "$(SYSROOT_SHARE)"
1050-
1051-
install: finish
1052-
mkdir -p "$(INSTALL_DIR)"
1053-
cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
1060+
diff -wur $(EXPECTED_TARGET_DIR) $(SYSROOT_SHARE)
10541061

10551062
$(BINDING_WORK_DIR)/wasi-cli:
10561063
mkdir -p "$(BINDING_WORK_DIR)"

0 commit comments

Comments
 (0)