Skip to content

Commit

Permalink
Preserve timestamps for installed headers to improve incremental builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kateinoigakukun committed Aug 29, 2024
1 parent 1b19fc6 commit e5e2e9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
37 changes: 22 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -764,32 +764,39 @@ $(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 \
$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in \
$(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)
#
Expand Down Expand Up @@ -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)"
Expand Down
5 changes: 0 additions & 5 deletions libc-bottom-half/headers/public/__wasi_snapshot.h

This file was deleted.

0 comments on commit e5e2e9d

Please sign in to comment.