xref: /aosp_15_r20/external/cpu_features/bazel/ci/Makefile (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1*eca53ba6SRoland LevillainPROJECT := cpu_features
2*eca53ba6SRoland LevillainBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
3*eca53ba6SRoland LevillainSHA1 := $(shell git rev-parse --verify HEAD)
4*eca53ba6SRoland Levillain
5*eca53ba6SRoland Levillain# General commands
6*eca53ba6SRoland Levillain.PHONY: help
7*eca53ba6SRoland LevillainBOLD=\e[1m
8*eca53ba6SRoland LevillainRESET=\e[0m
9*eca53ba6SRoland Levillain
10*eca53ba6SRoland Levillainhelp:
11*eca53ba6SRoland Levillain	@echo -e "${BOLD}SYNOPSIS${RESET}"
12*eca53ba6SRoland Levillain	@echo -e "\tmake <target> [NOCACHE=1]"
13*eca53ba6SRoland Levillain	@echo
14*eca53ba6SRoland Levillain	@echo -e "${BOLD}DESCRIPTION${RESET}"
15*eca53ba6SRoland Levillain	@echo -e "\ttest build inside docker container to have a reproductible build."
16*eca53ba6SRoland Levillain	@echo
17*eca53ba6SRoland Levillain	@echo -e "${BOLD}MAKE TARGETS${RESET}"
18*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}help${RESET}: display this help and exit."
19*eca53ba6SRoland Levillain	@echo
20*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}<platform>_<stage>${RESET}: build <stage> docker image using an Ubuntu:latest x86_64 base image."
21*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}save_<platform>_<stage>${RESET}: Save the <stage> docker image."
22*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}sh_<platform>_<stage>${RESET}: run a container using the <stage> docker image (debug purpose)."
23*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}clean_<platform>_<stage>${RESET}: Remove cache and docker image."
24*eca53ba6SRoland Levillain	@echo
25*eca53ba6SRoland Levillain	@echo -e "\tWith ${BOLD}<platform>${RESET}:"
26*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}amd64${RESET} (linux/amd64)"
27*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}arm64${RESET} (linux/arm64)"
28*eca53ba6SRoland Levillain	@echo
29*eca53ba6SRoland Levillain	@echo -e "\tWith ${BOLD}<stage>${RESET}:"
30*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}env${RESET}"
31*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}devel${RESET}"
32*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}build${RESET}"
33*eca53ba6SRoland Levillain	@echo -e "\t\t${BOLD}test${RESET}"
34*eca53ba6SRoland Levillain	@echo -e "\te.g. 'make amd64_build'"
35*eca53ba6SRoland Levillain	@echo
36*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}clean${RESET}: Remove cache and ALL docker images."
37*eca53ba6SRoland Levillain	@echo
38*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
39*eca53ba6SRoland Levillain	@echo -e "\t${BOLD}VERBOSE=1${RESET}: use 'docker build --progress=plain' when building container."
40*eca53ba6SRoland Levillain	@echo
41*eca53ba6SRoland Levillain	@echo -e "branch: $(BRANCH)"
42*eca53ba6SRoland Levillain	@echo -e "sha1: $(SHA1)"
43*eca53ba6SRoland Levillain
44*eca53ba6SRoland Levillain# Need to add cmd_platform to PHONY otherwise target are ignored since they do not
45*eca53ba6SRoland Levillain# contain recipe (using FORCE do not work here)
46*eca53ba6SRoland Levillain.PHONY: all
47*eca53ba6SRoland Levillainall: build
48*eca53ba6SRoland Levillain
49*eca53ba6SRoland Levillain# Delete all implicit rules to speed up makefile
50*eca53ba6SRoland LevillainMAKEFLAGS += --no-builtin-rules
51*eca53ba6SRoland Levillain.SUFFIXES:
52*eca53ba6SRoland Levillain# Remove some rules from gmake that .SUFFIXES does not remove.
53*eca53ba6SRoland LevillainSUFFIXES =
54*eca53ba6SRoland Levillain# Keep all intermediate files
55*eca53ba6SRoland Levillain# ToDo: try to remove it later
56*eca53ba6SRoland Levillain.SECONDARY:
57*eca53ba6SRoland Levillain
58*eca53ba6SRoland Levillain# Docker image name prefix.
59*eca53ba6SRoland LevillainIMAGE := ${PROJECT}
60*eca53ba6SRoland Levillain
61*eca53ba6SRoland LevillainDOCKER_BUILDX_CMD := docker buildx build
62*eca53ba6SRoland Levillainifdef NOCACHE
63*eca53ba6SRoland LevillainDOCKER_BUILDX_CMD := ${DOCKER_BUILDX_CMD} --no-cache
64*eca53ba6SRoland Levillainendif
65*eca53ba6SRoland Levillainifdef VERBOSE
66*eca53ba6SRoland LevillainDOCKER_BUILDX_CMD := ${DOCKER_BUILDX_CMD} --progress=plain
67*eca53ba6SRoland Levillainendif
68*eca53ba6SRoland LevillainDOCKER_RUN_CMD := docker run --rm --init --net=host
69*eca53ba6SRoland Levillain
70*eca53ba6SRoland Levillain############
71*eca53ba6SRoland Levillain## NATIVE ##
72*eca53ba6SRoland Levillain############
73*eca53ba6SRoland Levillain# ref: https://go.dev/doc/install/source#environment
74*eca53ba6SRoland Levillain# ref: https://github.com/containerd/containerd/blob/269548fa27e0089a8b8278fc4fc781d7f65a939b/platforms/platforms.go#L80-L94
75*eca53ba6SRoland LevillainPLATFORMS := amd64 arm64
76*eca53ba6SRoland LevillainSTAGES := env devel build test
77*eca53ba6SRoland Levillain
78*eca53ba6SRoland Levillaindefine make-platform-stage-target =
79*eca53ba6SRoland Levillain$1_$2: docker/Dockerfile
80*eca53ba6SRoland Levillain	${DOCKER_BUILDX_CMD} \
81*eca53ba6SRoland Levillain --platform linux/$1 \
82*eca53ba6SRoland Levillain --build-arg PLATFORM="$1" \
83*eca53ba6SRoland Levillain --target=$2 \
84*eca53ba6SRoland Levillain --tag ${IMAGE}:$1_$2 \
85*eca53ba6SRoland Levillain -f $$< ../..
86*eca53ba6SRoland Levillain
87*eca53ba6SRoland Levillainsave_$1_$2: cache/$1/docker_$2.tar
88*eca53ba6SRoland Levillaincache/$1/docker_$2.tar: $1_$2
89*eca53ba6SRoland Levillain	@rm -f $$@
90*eca53ba6SRoland Levillain	mkdir -p cache/$1
91*eca53ba6SRoland Levillain	docker save ${IMAGE}:$1_$2 -o $$@
92*eca53ba6SRoland Levillain
93*eca53ba6SRoland Levillainsh_$1_$2: $1_$2
94*eca53ba6SRoland Levillain	${DOCKER_RUN_CMD} --platform linux/$1 -it --name ${IMAGE}_$1_$2 ${IMAGE}:$1_$2
95*eca53ba6SRoland Levillain
96*eca53ba6SRoland Levillainclean_$1_$2:
97*eca53ba6SRoland Levillain	docker image rm -f ${IMAGE}:$1_$2 2>/dev/null
98*eca53ba6SRoland Levillain	rm -f cache/$1/docker_$2.tar
99*eca53ba6SRoland Levillainendef
100*eca53ba6SRoland Levillain
101*eca53ba6SRoland Levillaindefine make-platform-target =
102*eca53ba6SRoland Levillain$(foreach stage,$(STAGES),$(eval $(call make-platform-stage-target,$1,$(stage))))
103*eca53ba6SRoland Levillain
104*eca53ba6SRoland Levillain# merge
105*eca53ba6SRoland Levillain.PHONY: clean_$1
106*eca53ba6SRoland Levillainclean_$1: $(addprefix clean_$1_, $(STAGES))
107*eca53ba6SRoland Levillain	-rmdir cache/$1
108*eca53ba6SRoland Levillainendef
109*eca53ba6SRoland Levillain
110*eca53ba6SRoland Levillain$(foreach platform,$(PLATFORMS),$(eval $(call make-platform-target,$(platform))))
111*eca53ba6SRoland Levillain
112*eca53ba6SRoland Levillain## MERGE ##
113*eca53ba6SRoland Levillain.PHONY: clean
114*eca53ba6SRoland Levillainclean: $(addprefix clean_, $(PLATFORMS))
115*eca53ba6SRoland Levillain	docker container prune -f
116*eca53ba6SRoland Levillain	docker image prune -f
117*eca53ba6SRoland Levillain	-rmdir cache
118*eca53ba6SRoland Levillain
119*eca53ba6SRoland Levillain.PHONY: distclean
120*eca53ba6SRoland Levillaindistclean: clean
121*eca53ba6SRoland Levillain	-docker container rm -f $$(docker container ls -aq)
122*eca53ba6SRoland Levillain	-docker image rm -f $$(docker image ls -aq)
123