Skip to content

Commit

Permalink
<Make> Add build cache to speed up builds
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkollipara committed Jul 31, 2024
1 parent daa6ba9 commit 15ebc68
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 25 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/github_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:

- name: Fetch Dependencies
run: |
sudo apt install cppcheck -y
sudo apt install cppcheck ccache -y
make get_avr_tc
make get_riscv_tc
- name: Init CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
debug: true
Expand All @@ -51,10 +51,16 @@ jobs:
make demo_qemu_sifive_e
make demo_ibex_ss
- name: Build Cache Stats
run: |
make show_ccache_stats
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3

- name: Clean Up
run: |
make clean
rm -rf toolchain
make clean_workspace
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tools/
backup/
bkp/
projects/
.buildcache/
*.elf
*.bin
*.d
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
SHELL := /bin/bash
N_JOBS ?= $(shell grep -c ^processor /proc/cpuinfo)
HOST_ARCH := $(shell lscpu | grep -Po '(?<='Architecture:' )[^"]*')
EN_BUILD_CACHE ?= 1
V ?= 0
PP ?= 0

include mk/help.mk
include mk/path.mk
include mk/ccache.mk
include mk/tc_get.mk
include mk/project.mk

Expand Down
141 changes: 141 additions & 0 deletions mk/ccache.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2024, Cyancore Team
#
# File Name : ccache.mk
# Description : This file provides recipes for build cache
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

#*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*#
#--------------< Build Cache >--------------#
#*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*#

CCACHE_DIR := $(CC_ROOT)/.buildcache

# For Flags read ccache documentation
CCACHE_ABSSTDERR := true
export CCACHE_ABSSTDERR
CCACHE_BASEDIR :=
export CCACHE_BASEDIR
CCACHE_DIR := $(CCACHE_DIR)/cache
export CCACHE_DIR
CCACHE_COMPILER :=
export CCACHE_COMPILER
CCACHE_COMPILERCHECK := mtime
export CCACHE_COMPILERCHECK
CCACHE_COMPILERTYPE := auto
export CCACHE_COMPILERTYPE
export CCACHE_COMPRESS
CCACHE_COMPRESSLEVEL := 0
export CCACHE_COMPRESSLEVEL
CCACHE_EXTENSION :=
export CCACHE_EXTENSION
# export CCACHE_DEBUG
export CCACHE_NODEBUG
CCACHE_DEBUGDIR := $(CCACHE_DIR)/dbg
export CCACHE_DEBUGDIR
CCACHE_DEBUGLEVEL := 2
export CCACHE_DEBUGLEVEL
# export CCACHE_DEPEND
export CCACHE_NODEPEND
export CCACHE_DIRECT
# export CCACHE_NODIRECT
# export CCACHE_DISABLE
export CCACHE_NODISABLE
CCACHE_EXTRAFILES :=
export CCACHE_EXTRAFILES
# export CCACHE_FILECLONE
export CCACHE_NOFILECLONE
# export CCACHE_HARDLINK
export CCACHE_NOHARDLINK
export CCACHE_HASHDIR
# export CCACHE_NOHASHDIR
CCACHE_IGNOREHEADERS :=
export CCACHE_IGNOREHEADERS
CCACHE_IGNOREOPTIONS :=
export CCACHE_IGNOREOPTIONS
# export CCACHE_INODECACHE
export CCACHE_NOINODECACHE
# export CCACHE_COMMENTS
export CCACHE_NOCOMMENTS
CCACHE_LOGFILE := $(CCACHE_DIR)/log
export CCACHE_LOGFILE
CCACHE_MAXFILES := 0
export CCACHE_MAXFILES
CCACHE_MAXSIZE := 1.0 GiB
export CCACHE_MAXSIZE
CCACHE_MSVC_DEP_PREFIX := Note: including file:
export CCACHE_MSVC_DEP_PREFIX
CCACHE_NAMESPACE := cyancore
export CCACHE_NAMESPACE
CCACHE_PATH :=
export CCACHE_PATH
# export CCACHE_PCH_EXTSUM
export CCACHE_NOPCH_EXTSUM
CCACHE_PREFIX :=
export CCACHE_PREFIX
CCACHE_PREFIX_CPP :=
export CCACHE_PREFIX_CPP
# export CCACHE_READONLY
export CCACHE_NOREADONLY
# export CCACHE_READONLY_DIRECT
export CCACHE_NOREADONLY_DIRECT
# export CCACHE_RECACHE
export CCACHE_NORECACHE
# export CCACHE_REMOTE_ONLY
export CCACHE_NOREMOTE_ONLY
CCACHE_REMOTE_STORAGE :=
export CCACHE_REMOTE_STORAGE
# export CCACHE_RESHARE
export CCACHE_NORESHARE
export CCACHE_CPP2
# export CCACHE_NOCPP2
CCACHE_SLOPPINESS :=
export CCACHE_SLOPPINESS
# export CCACHE_NOSTATS
export CCACHE_STATS
export CCACHE_STATSLOG := $(CCACHE_DIR)/stats
export CCACHE_TEMPDIR := $(CCACHE_DIR)/
CCACHE_UMASK :=
export CCACHE_UMASK


ifeq ($(EN_BUILD_CACHE),1)
CCACHE := ccache

T_ALLOWLIST += show_ccache_config show_ccache_stats clean_ccache

CHECK_CCACHE := $(shell which $(CCACHE))
ifeq ($(CHECK_CCACHE),)
$(info < ! > ccache is not installed!)
$(error < x > Stopping build.)
endif

show_ccache_stats:
ifneq ($(realpath $(CCACHE_LOGFILE)),)
$(CCACHE) -s -x -v
else
$(info < ! > No log file present, try to perform build and try!)
endif

show_ccache_config: --prepare-cache
$(CCACHE) -p

clean_ccache:
ifneq ($(realpath $(CCACHE_LOGFILE)),)
$(CCACHE) -c -C -z
else
$(info < ! > No log file present, try to perform build and try!)
endif


.PHONY: --prepare-cache
--prepare-cache: $(CCACHE_LOGFILE)

.SECONDEXPANSION:
$(CCACHE_LOGFILE): | $$(@D)/
touch $@
endif

4 changes: 2 additions & 2 deletions mk/elf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ elf: $(ELF)
.SECONDEXPANSION:
$(ELF): $(DEP_LIBS) $(DEP_OBJS) $(LD_SCRIPT) $(LD_SUPPLEMENT) | $$(SIZE)
@echo "Elf: Generating $(@F) ..."
$(LD) -dT $(LD_SCRIPT) $(addprefix -T , $(LD_SUPPLEMENT)) $(LD_FLAGS) \
$(CCACHE) $(LD) -dT $(LD_SCRIPT) $(addprefix -T , $(LD_SUPPLEMENT)) $(LD_FLAGS) \
-Map=$(@:.elf=.map) -o $@ $(filter %.o, $^) $(DEP_LIB_PATH) $(DEP_LIBS_ARG) $(EXLIB_ARGS) -L $(TL) -lgcc
$(OD) -Dx -h --wide $@ > $(@:.elf=.lst)
$(OC) -O binary $@ $(@:.elf=.bin)
Expand All @@ -40,5 +40,5 @@ $(ELF): $(DEP_LIBS) $(DEP_OBJS) $(LD_SCRIPT) $(LD_SUPPLEMENT) | $$(SIZE)
$(OUT)/%.ld: %.ld.sx
mkdir -p $(@D)
@echo "Elf: Preprocessing $(@F) ..."
$(CC) $(CFLAGS) -E -P -o $@ $<
$(CCACHE) $(CC) $(CFLAGS) -E -P -o $@ $<

2 changes: 1 addition & 1 deletion mk/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ AR_FLAGS ?= rcs

$(LIB): $(LIB_OBJS) | $$(@D)/
@echo "Lib: Generating $(@F) ..."
$(AR) $(AR_FLAGS) $@ $^
$(CCACHE) $(AR) $(AR_FLAGS) $@ $^

LIB_INCLUDE_PATH:=
LIB_OBJS :=
Expand Down
12 changes: 6 additions & 6 deletions mk/lobj.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ DEP_SRCS += $(C_SRCS) $(CPP_SRCS)
$(CPP_OBJS): $(OUT)/%.o: %.cpp | $$(@D)/
@echo "Elf: Compiling $(@F:.o=.cpp) ..."
ifeq ($(PP),1)
$(CCP) $(CPPFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.cpp)
$(CCACHE) $(CCP) $(CPPFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.cpp)
endif
$(CCP) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(CCACHE) $(CCP) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(C_OBJS): $(OUT)/%.o: %.c | $$(@D)/
@echo "Lib: Compiling $(@F:.o=.c) ..."
ifeq ($(PP),1)
$(CC) $(CCFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.c)
$(CCACHE) $(CC) $(CCFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.c)
endif
$(CC) $(CCFLAGS) $(CFLAGS) -c $< -o $@
$(CCACHE) $(CC) $(CCFLAGS) $(CFLAGS) -c $< -o $@

$(S_OBJS): $(OUT)/%.o: %.S | $$(@D)/
@echo "Lib: Assembling $(@F:.o=.S) ..."
$(CC) -E $(CCFLAGS) $(CFLAGS) -c $< -o $(@:.o=.pre.S)
$(AS) $(ASFLAGS) $(@:.o=.pre.S) -o $@
$(CCACHE) $(CC) -E $(CCFLAGS) $(CFLAGS) -c $< -o $(@:.o=.pre.S)
$(CCACHE) $(AS) $(ASFLAGS) $(@:.o=.pre.S) -o $@
ifneq ($(PP),1)
rm $(@:.o=.pre.S)
endif
Expand Down
12 changes: 6 additions & 6 deletions mk/obj.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ DEP_SRCS += $(C_SRCS) $(CPP_SRCS)
$(CPP_OBJS): $(OUT)/%.o: %.cpp | $$(@D)/
@echo "Elf: Compiling $(@F:.o=.cpp) ..."
ifeq ($(PP),1)
$(CCP) $(CPPFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.cpp)
$(CCACHE) $(CCP) $(CPPFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.cpp)
endif
$(CCP) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(CCACHE) $(CCP) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(C_OBJS): $(OUT)/%.o: %.c | $$(@D)/
@echo "Elf: Compiling $(@F:.o=.c) ..."
ifeq ($(PP),1)
$(CC) $(CCFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.c)
$(CCACHE) $(CC) $(CCFLAGS) $(CFLAGS) -E -p $< -o $(@:.o=.pre.c)
endif
$(CC) $(CCFLAGS) $(CFLAGS) -c $< -o $@
$(CCACHE) $(CC) $(CCFLAGS) $(CFLAGS) -c $< -o $@

$(S_OBJS): $(OUT)/%.o: %.S | $$(@D)/
@echo "Elf: Assembling $(@F:.o=.S) ..."
$(CC) -E $(CCFLAGS) $(CFLAGS) -c $< -o $(@:.o=.pre.S)
$(AS) $(ASFLAGS) $(@:.o=.pre.S) -o $@
$(CCACHE) $(CC) -E $(CCFLAGS) $(CFLAGS) -c $< -o $(@:.o=.pre.S)
$(CCACHE) $(AS) $(ASFLAGS) $(@:.o=.pre.S) -o $@
ifneq ($(PP),1)
rm $(@:.o=.pre.S)
endif
Expand Down
2 changes: 1 addition & 1 deletion mk/path.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ OUT ?= $(OUT_PATH)/$(PROJECT)

GET_PATH = $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

$(OUT)/%/:
./%/:
mkdir -p $@
10 changes: 8 additions & 2 deletions mk/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include mk/qemu.mk
include mk/picotool.mk

P_TARGETS += default cyancore check version copy_to_remote clean_remote
T_ALLOWLIST += list clean all_projects
T_ALLOWLIST += list clean all_projects clean_workspace setup_workspace
PROJECT_LIST := $(shell ls projects/ -I *.template -I *.src)

.PHONY: aux_target
Expand All @@ -33,13 +33,19 @@ all_projects:
make $$project; \
done

cyancore: version elf
cyancore: --prepare-cache version elf
$(info < / > Done !)

clean:
$(info < ! > Removing $(PROJECT) binaries ...)
rm -rf $(OUT)

setup_workspace: $(SIZE) get_qemu get_all_tc

clean_workspace: clean
$(info < / > Cleaning up workspace ...)
rm -rf $(CCACHE_DIR) $(TOOLS_ROOT)

list:
$(info Available projects are :)
echo $(PROJECT_LIST)
Expand Down
2 changes: 1 addition & 1 deletion mk/slib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ slib: $(SLIB)

$(SLIB): $(HEADER) $(LIB_OBJS)
echo "Generating $(notdir $@) ..."
$(LD) --shared -Wl,-soname,$(notdir $@) -o $@ $<
$(CCACHE) $(LD) --shared -Wl,-soname,$(notdir $@) -o $@ $<

$(HEADER): --dependency
cp $@ $(OUT)
Expand Down
2 changes: 1 addition & 1 deletion src/visor/services/kernel/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

KERNEL_DIR := $(GET_PATH)

$(eval $(call check_and_include KHELIOS,$(KERNEL_DIR)/helios/build.mk))
$(eval $(call check_and_include,KHELIOS,$(KERNEL_DIR)/helios/build.mk))

0 comments on commit 15ebc68

Please sign in to comment.