From e5e2e9dedd8548df196c779738f79f0dad70004a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 29 Aug 2024 06:23:04 +0000 Subject: [PATCH] Preserve timestamps for installed headers to improve incremental builds This change makes it so that the timestamps of installed header files are only updated when the contents of the header files change. This change is beneficial for incremental builds of projects depending on wasi-libc. For example, the Swift project builds wasi-libc as part of its build process, and this change reduces the number of build products in the Swift build that are unnecessarily rebuilt. The following commands can be used to verify the changes: ```bash make clean && make -j16 && ( cd sysroot && find . -name "*.h" -type f -exec stat -c '%n %y' {} \; ) > sysroot.v1.timestamp && \ make -j16 && ( cd sysroot && find . -name "*.h" -type f -exec stat -c '%n %y' {} \; ) > sysroot.v2.timestamp diff sysroot.v1.timestamp sysroot.v2.timestamp ``` The diff should show no changes in timestamps. --- Makefile | 37 +++++++++++-------- .../headers/public/__wasi_snapshot.h | 5 --- 2 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 libc-bottom-half/headers/public/__wasi_snapshot.h diff --git a/Makefile b/Makefile index 4f4b954f..68885bdb 100644 --- a/Makefile +++ b/Makefile @@ -764,13 +764,7 @@ $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) $(LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJ $(EMMALLOC_OBJS): CFLAGS += \ -fno-strict-aliasing -include_dirs: - # - # Install the include files. - # - mkdir -p "$(SYSROOT_INC)" - cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" - +$(SYSROOT_INC)/bits/alltypes.h: $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed $(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in $(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in # Generate musl's bits/alltypes.h header. mkdir -p "$(SYSROOT_INC)/bits" sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \ @@ -778,18 +772,31 @@ include_dirs: $(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in \ > "$(SYSROOT_INC)/bits/alltypes.h" +$(SYSROOT_INC)/__wasi_snapshot.h: + mkdir -p "$(SYSROOT_INC)" +ifeq ($(WASI_SNAPSHOT), p2) + printf '#ifndef __wasilibc_use_wasip2\n#define __wasilibc_use_wasip2\n#endif\n' \ + > "$(SYSROOT_INC)/__wasi_snapshot.h" +else + printf '/* This file is (practically) empty by default. The Makefile will replace it\n with a non-empty version that defines `__wasilibc_use_wasip2` if targeting\n `wasm32-wasip2`.\n */\n\n' \ + > "$(SYSROOT_INC)/__wasi_snapshot.h" +endif + +include_dirs: $(SYSROOT_INC)/bits/alltypes.h $(SYSROOT_INC)/__wasi_snapshot.h + # + # Install the include files. + # + mkdir -p "$(SYSROOT_INC)" + cp -p -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" + # Copy in the bulk of musl's public header files. - cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)" + cp -p -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)" # Copy in the musl's "bits" header files. - cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits" - cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits" + cp -p -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits" + cp -p -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits" # Remove selected header files. $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) -ifeq ($(WASI_SNAPSHOT), p2) - printf '#ifndef __wasilibc_use_wasip2\n#define __wasilibc_use_wasip2\n#endif\n' \ - > "$(SYSROOT_INC)/__wasi_snapshot.h" -endif startup_files: include_dirs $(LIBC_BOTTOM_HALF_CRT_OBJS) # @@ -981,7 +988,7 @@ check-symbols: startup_files libc install: finish mkdir -p "$(INSTALL_DIR)" - cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)" + cp -p -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)" $(BINDING_WORK_DIR)/wasi-cli: mkdir -p "$(BINDING_WORK_DIR)" diff --git a/libc-bottom-half/headers/public/__wasi_snapshot.h b/libc-bottom-half/headers/public/__wasi_snapshot.h deleted file mode 100644 index 9a100780..00000000 --- a/libc-bottom-half/headers/public/__wasi_snapshot.h +++ /dev/null @@ -1,5 +0,0 @@ -/* This file is (practically) empty by default. The Makefile will replace it - with a non-empty version that defines `__wasilibc_use_wasip2` if targeting - `wasm32-wasip2`. - */ -