Skip to content

Commit c47daaf

Browse files
authored
Avoid re-copying include headers (#549)
This adds a `.stamp` file to the build directory that tracks when all headers have been copied over to the sysroot `include` directory. Previously, the `include_dirs` target was phony, which `make` will run every time, regardless of whether it is needed. This was part of the problem with all of libc being rebuilt at each `make` invocation.
1 parent 913e58e commit c47daaf

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

Makefile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ ifeq ($(WASI_SNAPSHOT), p2)
6666
TARGET_TRIPLE = wasm32-wasip2
6767
endif
6868

69+
# These artifacts are "stamps" that we use to mark that some task (e.g., copying
70+
# files) has been completed.
71+
INCLUDE_DIRS := $(OBJDIR)/copy-include-headers.stamp
72+
6973
BUILTINS_LIB ?= $(shell ${CC} ${CFLAGS} --print-libgcc-file-name)
7074

7175
# These variables describe the locations of various files and directories in
@@ -735,31 +739,31 @@ $(LIBSETJMP_OBJS) $(LIBSETJMP_SO_OBJS): CFLAGS += \
735739
$(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS): CFLAGS += \
736740
-D_WASI_EMULATED_SIGNAL
737741

738-
$(OBJDIR)/%.long-double.pic.o: %.c include_dirs
742+
$(OBJDIR)/%.long-double.pic.o: %.c $(INCLUDE_DIRS)
739743
@mkdir -p "$(@D)"
740744
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
741745

742746
$(OBJDIR)/wasip2_component_type.pic.o $(OBJDIR)/wasip2_component_type.o: $(LIBC_BOTTOM_HALF_SOURCES)/wasip2_component_type.o
743747
@mkdir -p "$(@D)"
744748
cp $< $@
745749

746-
$(OBJDIR)/%.pic.o: %.c include_dirs
750+
$(OBJDIR)/%.pic.o: %.c $(INCLUDE_DIRS)
747751
@mkdir -p "$(@D)"
748752
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
749753

750-
$(OBJDIR)/%.long-double.o: %.c include_dirs
754+
$(OBJDIR)/%.long-double.o: %.c $(INCLUDE_DIRS)
751755
@mkdir -p "$(@D)"
752756
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
753757

754-
$(OBJDIR)/%.no-floating-point.o: %.c include_dirs
758+
$(OBJDIR)/%.no-floating-point.o: %.c $(INCLUDE_DIRS)
755759
@mkdir -p "$(@D)"
756760
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
757761

758-
$(OBJDIR)/%.o: %.c include_dirs
762+
$(OBJDIR)/%.o: %.c $(INCLUDE_DIRS)
759763
@mkdir -p "$(@D)"
760764
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
761765

762-
$(OBJDIR)/%.o: %.s include_dirs
766+
$(OBJDIR)/%.o: %.s $(INCLUDE_DIRS)
763767
@mkdir -p "$(@D)"
764768
$(CC) $(ASMFLAGS) -o $@ -c $<
765769

@@ -807,7 +811,10 @@ $(LIBWASI_EMULATED_PTHREAD_OBJS) $(LIBWASI_EMULATED_PTHREAD_SO_OBJS): CFLAGS +=
807811
$(EMMALLOC_OBJS): CFLAGS += \
808812
-fno-strict-aliasing
809813

810-
include_dirs:
814+
ALL_POSSIBLE_HEADERS += $(shell find $(LIBC_TOP_HALF_MUSL_DIR) -name \*.h)
815+
ALL_POSSIBLE_HEADERS += $(shell find $(LIBC_BOTTOM_HALF_HEADERS_PUBLIC) -name \*.h)
816+
ALL_POSSIBLE_HEADERS += $(shell find $(MUSL_FTS_SRC_DIR) -name \*.h)
817+
$(INCLUDE_DIRS): $(ALL_POSSIBLE_HEADERS)
811818
#
812819
# Install the include files.
813820
#
@@ -823,10 +830,12 @@ include_dirs:
823830

824831
# Copy in the bulk of musl's public header files.
825832
cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)"
833+
826834
# Copy in the musl's "bits" header files.
827835
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits"
828836
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits"
829837

838+
# Copy in the fts header files.
830839
cp "$(MUSL_FTS_SRC_DIR)/fts.h" "$(SYSROOT_INC)/fts.h"
831840

832841
# Remove selected header files.
@@ -836,7 +845,11 @@ ifeq ($(WASI_SNAPSHOT), p2)
836845
> "$(SYSROOT_INC)/__wasi_snapshot.h"
837846
endif
838847

839-
startup_files: include_dirs $(LIBC_BOTTOM_HALF_CRT_OBJS)
848+
# Stamp the include installation.
849+
@mkdir -p $(@D)
850+
touch $@
851+
852+
startup_files: $(INCLUDE_DIRS) $(LIBC_BOTTOM_HALF_CRT_OBJS)
840853
#
841854
# Install the startup files (crt1.o etc).
842855
#
@@ -861,7 +874,7 @@ LIBC_SO += \
861874
endif
862875
endif
863876

864-
libc_so: include_dirs $(LIBC_SO)
877+
libc_so: $(INCLUDE_DIRS) $(LIBC_SO)
865878

866879
STATIC_LIBS = \
867880
$(SYSROOT_LIB)/libc.a \
@@ -881,7 +894,7 @@ STATIC_LIBS += \
881894
$(SYSROOT_LIB)/libsetjmp.a
882895
endif
883896

884-
libc: include_dirs $(STATIC_LIBS)
897+
libc: $(INCLUDE_DIRS) $(STATIC_LIBS)
885898

886899
DUMMY := m rt pthread crypt util xnet resolv
887900
DUMMY_LIBS := $(patsubst %,$(SYSROOT_LIB)/lib%.a,$(DUMMY))
@@ -1101,4 +1114,4 @@ clean:
11011114
$(RM) -r "$(OBJDIR)"
11021115
$(RM) -r "$(SYSROOT)"
11031116

1104-
.PHONY: default startup_files libc libc_so finish install include_dirs clean check-symbols bindings
1117+
.PHONY: default startup_files libc libc_so finish install clean check-symbols bindings

0 commit comments

Comments
 (0)