From ccc3a51e4cdbc7c34ce461829b8983e2ee010f5b Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 25 Oct 2021 16:06:43 +0200 Subject: [PATCH] ci: Add docker based test framework * Add documentation * Add .dockerignore: minimize docker context size to improve speed * Add Makefile: to easily run various docker stages * Add a CMake sample project to check CMake install rules --- .dockerignore | 31 ++++ ci/Makefile | 240 +++++++++++++++++++++++++ ci/README.md | 66 +++++++ ci/doc/docker.dot | 64 +++++++ ci/doc/docker.svg | 312 +++++++++++++++++++++++++++++++++ ci/doc/generate_image.sh | 7 + ci/docker/amd64/Dockerfile | 48 +++++ ci/docker/toolchain/Dockerfile | 34 ++++ ci/sample/CMakeLists.txt | 22 +++ ci/sample/main.cpp | 11 ++ 10 files changed, 835 insertions(+) create mode 100644 .dockerignore create mode 100644 ci/Makefile create mode 100644 ci/README.md create mode 100644 ci/doc/docker.dot create mode 100644 ci/doc/docker.svg create mode 100755 ci/doc/generate_image.sh create mode 100644 ci/docker/amd64/Dockerfile create mode 100644 ci/docker/toolchain/Dockerfile create mode 100644 ci/sample/CMakeLists.txt create mode 100644 ci/sample/main.cpp diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..716b782 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# Project Files unneeded by docker +ci/Makefile +ci/docker +ci/doc +ci/cache +.git +.gitignore +.github +.dockerignore +.clang-format +appveyor.yml +.travis.yml +AUTHORS +CONTRIBUTING.md +CONTRIBUTORS +LICENSE +README.md + +build/ +cmake_build/ +build_cross/ +cmake-build-*/ +out/ + +# Editor directories and files +.idea/ +.vagrant/ +.vscode/ +.vs/ +*.user +*.swp diff --git a/ci/Makefile b/ci/Makefile new file mode 100644 index 0000000..47ea30a --- /dev/null +++ b/ci/Makefile @@ -0,0 +1,240 @@ +PROJECT := cpu_features +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +SHA1 := $(shell git rev-parse --verify HEAD) + +# General commands +.PHONY: help +BOLD=\e[1m +RESET=\e[0m + +help: + @echo -e "${BOLD}SYNOPSIS${RESET}" + @echo -e "\tmake [NOCACHE=1]" + @echo + @echo -e "${BOLD}DESCRIPTION${RESET}" + @echo -e "\ttest build inside docker container to have a reproductible build." + @echo + @echo -e "${BOLD}MAKE TARGETS${RESET}" + @echo -e "\t${BOLD}help${RESET}: display this help and exit." + @echo + @echo -e "\t${BOLD}amd64_${RESET}: build docker image using an Ubuntu:latest x86_64 base image." + @echo -e "\t${BOLD}save_amd64_${RESET}: Save the docker image." + @echo -e "\t${BOLD}sh_amd64_${RESET}: run a container using the docker image (debug purpose)." + @echo -e "\t${BOLD}clean_amd64_${RESET}: Remove cache and docker image." + @echo + @echo -e "\tWith ${BOLD}${RESET}:" + @echo -e "\t\t${BOLD}env${RESET}" + @echo -e "\t\t${BOLD}devel${RESET}" + @echo -e "\t\t${BOLD}build${RESET}" + @echo -e "\t\t${BOLD}test${RESET}" + @echo -e "\t\t${BOLD}install_env${RESET}" + @echo -e "\t\t${BOLD}install_devel${RESET}" + @echo -e "\t\t${BOLD}install_build${RESET}" + @echo -e "\t\t${BOLD}install_test${RESET}" + @echo -e "\te.g. 'make amd64_build'" + @echo + @echo -e "\t${BOLD}_${RESET}: build docker image for a specific toolchain target." + @echo -e "\t${BOLD}save__${RESET}: Save the docker image for a specific platform." + @echo -e "\t${BOLD}sh__${RESET}: run a container using the docker image specified (debug purpose)." + @echo -e "\t${BOLD}clean__${RESET}: Remove cache and docker image." + @echo + @echo -e "\tWith ${BOLD}${RESET}:" + @echo -e "\t\t${BOLD}arm-linux-gnueabihf${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}armv8l-linux-gnueabihf${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}arm-linux-gnueabi${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}armeb-linux-gnueabihf${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}armeb-linux-gnueabi${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}aarch64-linux-gnu${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}aarch64_be-linux-gnu${RESET} (linaro toolchain)" + @echo -e "\t\t${BOLD}mips32${RESET} (codespace toolchain)" + @echo -e "\t\t${BOLD}mips64${RESET} (codespace toolchain)" + @echo -e "\t\t${BOLD}mips32el${RESET} (codespace toolchain)" + @echo -e "\t\t${BOLD}mips64el${RESET} (codespace toolchain)" + @echo + @echo -e "\tWith ${BOLD}${RESET}:" + @echo -e "\t\t${BOLD}env${RESET}" + @echo -e "\t\t${BOLD}devel${RESET}" + @echo -e "\t\t${BOLD}build${RESET}" + @echo -e "\t\t${BOLD}test${RESET}" + @echo -e "\te.g. 'make aarch64_test'" + @echo + @echo -e "\t${BOLD}${RESET}: build the vagrant virtual machine." + @echo -e "\t${BOLD}clean_${RESET}: Remove virtual machine for the specified vm." + @echo + @echo -e "\t${BOLD}${RESET}:" + @echo -e "\t\t${BOLD}freebsd${RESET} (FreeBSD)" + @echo + @echo -e "\t${BOLD}clean${RESET}: Remove cache and ALL docker images." + @echo + @echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)." + @echo + @echo -e "branch: $(BRANCH)" + @echo -e "sha1: $(SHA1)" + +# Need to add cmd_platform to PHONY otherwise target are ignored since they do not +# contain recipe (using FORCE do not work here) +.PHONY: all +all: build + +# Delete all implicit rules to speed up makefile +MAKEFLAGS += --no-builtin-rules +.SUFFIXES: +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = +# Keep all intermediate files +# ToDo: try to remove it later +.SECONDARY: + +# Docker image name prefix. +IMAGE := ${PROJECT} + +ifdef NOCACHE +DOCKER_BUILD_CMD := docker build --no-cache +else +DOCKER_BUILD_CMD := docker build +endif + +DOCKER_RUN_CMD := docker run --rm --init --net=host + +# $* stem +# $< first prerequist +# $@ target name + +############ +## NATIVE ## +############ +STAGES = env devel build test install_env install_devel install_build install_test + +targets_amd64 = $(addprefix amd64_, $(STAGES)) +.PHONY: $(targets_amd64) +$(targets_amd64): amd64_%: docker/amd64/Dockerfile + #@docker image rm -f ${IMAGE}:amd64_$* 2>/dev/null + ${DOCKER_BUILD_CMD} \ + --tag ${IMAGE}:amd64_$* \ + --target=$* \ + -f $< \ + .. + +#$(info Create targets: save_amd64 $(addprefix save_amd64_, $(STAGES)) (debug).) +save_targets_amd64 = $(addprefix save_amd64_, $(STAGES)) +.PHONY: $(save_targets_amd64) +$(save_targets_amd64): save_amd64_%: cache/amd64/docker_%.tar +cache/amd64/docker_%.tar: amd64_% + @rm -f $@ + mkdir -p cache/amd64 + docker save ${IMAGE}:amd64_$* -o $@ + +#$(info Create targets: $(addprefix sh_amd64_, $(STAGES)) (debug).) +sh_targets_amd64 = $(addprefix sh_amd64_, $(STAGES)) +.PHONY: $(sh_targets_amd64) +$(sh_targets_amd64): sh_amd64_%: amd64_% + ${DOCKER_RUN_CMD} -it --name ${IMAGE}_amd64_$* ${IMAGE}:amd64_$* + +#$(info Create targets: $(addprefix clean_amd64_, $(STAGES)).) +clean_targets_amd64 = $(addprefix clean_amd64_, $(STAGES)) +.PHONY: clean_amd64 $(clean_targets_amd64) +clean_amd64: $(clean_targets_amd64) +$(clean_targets_amd64): clean_amd64_%: + docker image rm -f ${IMAGE}:amd64_$* 2>/dev/null + rm -f cache/amd64/docker_$*.tar + + +############### +## TOOLCHAIN ## +############### +TOOLCHAIN_TARGETS = \ + arm-linux-gnueabihf armv8l-linux-gnueabihf arm-linux-gnueabi armeb-linux-gnueabihf armeb-linux-gnueabi \ + aarch64-linux-gnu aarch64_be-linux-gnu \ + mips32 mips32el mips64 mips64el +TOOLCHAIN_STAGES = env devel build test +define toolchain-stage-target = +#$$(info STAGE: $1) +#$$(info Create targets: toolchain_$1 $(addsuffix _$1, $(TOOLCHAIN_TARGETS)).) +targets_toolchain_$1 = $(addsuffix _$1, $(TOOLCHAIN_TARGETS)) +.PHONY: toolchain_$1 $$(targets_toolchain_$1) +toolchain_$1: $$(targets_toolchain_$1) +$$(targets_toolchain_$1): %_$1: docker/toolchain/Dockerfile + #@docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null + ${DOCKER_BUILD_CMD} \ + --tag ${IMAGE}:$$*_$1 \ + --build-arg TARGET=$$* \ + --target=$1 \ + -f $$< \ + .. + +#$$(info Create targets: save_toolchain_$1 $(addprefix save_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))) (debug).) +save_targets_toolchain_$1 = $(addprefix save_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))) +.PHONY: save_toolchain_$1 $$(save_targets_toolchain_$1) +save_toolchain_$1: $$(save_targets_toolchain_$1) +$$(save_targets_toolchain_$1): save_%_$1: cache/%/docker_$1.tar +cache/%/docker_$1.tar: %_$1 + @rm -f $$@ + mkdir -p cache/$$* + docker save ${IMAGE}:$$*_$1 -o $$@ + +#$$(info Create targets: $(addprefix sh_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))) (debug).) +sh_targets_toolchain_$1 = $(addprefix sh_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))) +.PHONY: $$(sh_targets_toolchain_$1) +$$(sh_targets_toolchain_$1): sh_%_$1: %_$1 + ${DOCKER_RUN_CMD} -it --name ${IMAGE}_$$*_$1 ${IMAGE}:$$*_$1 + +#$$(info Create targets: clean_toolchain_$1 $(addprefix clean_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))).) +clean_targets_toolchain_$1 = $(addprefix clean_, $(addsuffix _$1, $(TOOLCHAIN_TARGETS))) +.PHONY: clean_toolchain_$1 $$(clean_targets_toolchain_$1) +clean_toolchain_$1: $$(clean_targets_toolchain_$1) +$$(clean_targets_toolchain_$1): clean_%_$1: + docker image rm -f ${IMAGE}:$$*_$1 2>/dev/null + rm -f cache/$$*/docker_$1.tar +endef + +$(foreach stage,$(TOOLCHAIN_STAGES),$(eval $(call toolchain-stage-target,$(stage)))) + +## MERGE ## +.PHONY: clean_toolchain +clean_toolchain: $(addprefix clean_toolchain_, $(TOOLCHAIN_STAGES)) + -rmdir $(addprefix cache/, $(TOOLCHAIN_TARGETS)) + +.PHONY: env devel build test +env: amd64_env toolchain_env +devel: amd64_devel toolchain_devel +build: amd64_build toolchain_build +test: amd64_test toolchain_test + +.PHONY: install_env install_devel install_build install_test +install_env: amd64_install_env +install_devel: amd64_install_devel +install_build: amd64_install_build +install_test: amd64_install_test + +############# +## VAGRANT ## +############# +VMS = freebsd + +vms_targets = $(addsuffix _build, $(VMS)) +.PHONY: $(vms_targets) +$(vms_targets): %_build: vagrant/%/Vagrantfile + @cd vagrant/$* && vagrant destroy -f + cd vagrant/$* && vagrant up + +clean_vms_targets = $(addprefix clean_, $(VMS)) +.PHONY: clean_vms $(clean_vms_targets) +clean_vms: $(clean_vms_targets) +$(clean_vms_targets): clean_%: + cd vagrant/$* && vagrant destroy -f + -rm -rf vagrant/$*/.vagrant + +########### +## CLEAN ## +########### +.PHONY: clean +clean: clean_amd64 clean_toolchain clean_vms + docker container prune -f + docker image prune -f + -rmdir cache + +.PHONY: distclean +distclean: clean + -docker container rm -f $$(docker container ls -aq) + -docker image rm -f $$(docker image ls -aq) + -vagrant box remove -f generic/freebsd12 diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000..a507c65 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,66 @@ +# GitHub-CI Status +| OS | x86_64 | AArch64 | ARM | MIPS | +|:-------- | :----: | :-----: | :-: | :--: | +| FreeBSD | [![Status][freebsd_svg]][freebsd_link] | N/A | N/A | N/A | +| Linux | [![Status][linux_svg]][linux_link] | [![Status][linux_aarch64_svg]][linux_aarch64_link] | [![Status][linux_arm_svg]][linux_arm_link] | [![Status][linux_mips_svg]][linux_mips_link] | +| MacOS | [![Status][macos_svg]][macos_link] | N/A | N/A | N/A | +| Windows | [![Status][windows_svg]][windows_link] | N/A | N/A | N/A | + +[freebsd_svg]: https://github.com/google/cpu_features/actions/workflows/x86_freebsd.yml/badge.svg?branch=master +[freebsd_link]: https://github.com/google/cpu_features/actions/workflows/x86_freebsd.yml + +[linux_svg]: https://github.com/google/cpu_features/actions/workflows/x86_linux.yml/badge.svg?branch=master +[linux_link]: https://github.com/google/cpu_features/actions/workflows/x86_linux.yml +[linux_aarch64_svg]: https://github.com/google/cpu_features/actions/workflows/aarch64_linux.yml/badge.svg?branch=master +[linux_aarch64_link]: https://github.com/google/cpu_features/actions/workflows/aarch64_linux.yml +[linux_arm_svg]: https://github.com/google/cpu_features/actions/workflows/arm_linux.yml/badge.svg?branch=master +[linux_arm_link]: https://github.com/google/cpu_features/actions/workflows/arm_linux.yml +[linux_mips_svg]: https://github.com/google/cpu_features/actions/workflows/mips_linux.yml/badge.svg?branch=master +[linux_mips_link]: https://github.com/google/cpu_features/actions/workflows/mips_linux.yml + +[macos_svg]: https://github.com/google/cpu_features/actions/workflows/x86_darwin.yml/badge.svg?branch=master +[macos_link]: https://github.com/google/cpu_features/actions/workflows/x86_darwin.yml + +[windows_svg]: https://github.com/google/cpu_features/actions/workflows/x86_windows.yml/badge.svg?branch=master +[windows_link]: https://github.com/google/cpu_features/actions/workflows/x86_windows.yml + +## Makefile/Docker testing +To test the build on various distro, we are using docker containers and a Makefile for orchestration. + +pros: +* You are independent of third party CI runner config + (e.g. [github action virtual-environnments](https://github.com/actions/virtual-environments)). +* You can run it locally on your linux system. +* Most CI provide runners with docker and Makefile installed. + +cons: +* Only GNU/Linux distro supported. + +### Usage +To get the help simply type: +```sh +make +``` + +note: you can also use from top directory +```sh +make --directory=ci +``` + +### Example +For example to test mips32 inside an container: +```sh +make mips32_test +``` + +### Docker layers +Dockerfile is splitted in several stages. + +![docker](doc/docker.svg) + + +## Makefile/Vagrant testing +To test build for FreeBSD we are using Vagrant and VirtualBox box. + +This is similar to the docker stuff but use `vagrant` as `docker` cli and +VirtuaBox to replace the docker engine daemon. diff --git a/ci/doc/docker.dot b/ci/doc/docker.dot new file mode 100644 index 0000000..a00ef1f --- /dev/null +++ b/ci/doc/docker.dot @@ -0,0 +1,64 @@ +@startdot +digraph DockerDeps { + //rankdir=BT; + rankdir=TD; + node [shape=cylinder, style="rounded,filled", color=black, fillcolor=royalblue]; + DISTRO_IMG [label="ubuntu:latest"]; + PKG [label="packages\ne.g. cmake, g++", shape=box3d]; + SRC [label="git repo", shape=folder]; + SPL [label="sample", shape=folder]; + + subgraph clusterDockerfile { + ENV_IMG [label="cpu_features:amd64_env\nenv"]; + DEVEL_IMG [label="cpu_features:amd64_devel\ndevel"]; + BUILD_IMG [label="cpu_features:amd64_build\nbuild"]; + TEST_IMG [label="cpu_features:amd64_test\ntest"]; + INSTALL_ENV_IMG [label="cpu_features:amd64_install_env\ninstall_env"]; + INSTALL_DEVEL_IMG [label="cpu_features:amd64_install_devel\ninstall_devel"]; + INSTALL_BUILD_IMG [label="cpu_features:amd64_install_build\ninstall_build"]; + INSTALL_TEST_IMG [label="cpu_features:amd64_install_test\ninstall_test"]; + + ENV_IMG -> DEVEL_IMG; + DEVEL_IMG -> BUILD_IMG; + BUILD_IMG -> TEST_IMG; + + ENV_IMG -> INSTALL_ENV_IMG; + BUILD_IMG -> INSTALL_ENV_IMG [label="copy install", style="dashed"]; + INSTALL_ENV_IMG -> INSTALL_DEVEL_IMG; + SPL -> INSTALL_DEVEL_IMG [label="copy", style="dashed"]; + INSTALL_DEVEL_IMG -> INSTALL_BUILD_IMG; + INSTALL_BUILD_IMG -> INSTALL_TEST_IMG; + + color=royalblue; + label = "docker/amd64/Dockerfile"; + } + DISTRO_IMG -> ENV_IMG; + PKG -> ENV_IMG [label="install", style="dashed"]; + SRC -> DEVEL_IMG [label="copy", style="dashed"]; + + subgraph clusterCache { + node [shape=note, style="rounded,filled", color=black, fillcolor=royalblue]; + ENV_TAR [label="docker_amd64_env.tar"]; + DEVEL_TAR [label="docker_amd64_devel.tar"]; + BUILD_TAR [label="docker_amd64_build.tar"]; + TEST_TAR [label="docker_amd64_test.tar"]; + INSTALL_ENV_TAR [label="docker_amd64_install_env.tar"]; + INSTALL_DEVEL_TAR [label="docker_amd64_install_devel.tar"]; + INSTALL_BUILD_TAR [label="docker_amd64_install_build.tar"]; + INSTALL_TEST_TAR [label="docker_amd64_install_test.tar"]; + + edge [color=red]; + ENV_IMG -> ENV_TAR [label="make save_amd64_env"]; + DEVEL_IMG -> DEVEL_TAR [label="make save_amd64_devel"]; + BUILD_IMG -> BUILD_TAR [label="make save_amd64_build"]; + TEST_IMG -> TEST_TAR [label="make save_amd64_test"]; + INSTALL_ENV_IMG -> INSTALL_ENV_TAR [label="make save_amd64_install_env"]; + INSTALL_DEVEL_IMG -> INSTALL_DEVEL_TAR [label="make save_amd64_install_devel"]; + INSTALL_BUILD_IMG -> INSTALL_BUILD_TAR [label="make save_amd64_install_build"]; + INSTALL_TEST_IMG -> INSTALL_TEST_TAR [label="make save_amd64_install_test"]; + + color=royalblue; + label = "cache/amd64/"; + } +} +@enddot diff --git a/ci/doc/docker.svg b/ci/doc/docker.svg new file mode 100644 index 0000000..bd9bd6d --- /dev/null +++ b/ci/doc/docker.svg @@ -0,0 +1,312 @@ + + + + + + +DockerDeps + + +clusterDockerfile + +docker/amd64/Dockerfile + + +clusterCache + +cache/amd64/ + + + +DISTRO_IMG + + +ubuntu:latest + + + +ENV_IMG + + +cpu_features:amd64_env +env + + + +DISTRO_IMG->ENV_IMG + + + + + +PKG + + + + +packages +e.g. cmake, g++ + + + +PKG->ENV_IMG + + +install + + + +SRC + +git repo + + + +DEVEL_IMG + + +cpu_features:amd64_devel +devel + + + +SRC->DEVEL_IMG + + +copy + + + +SPL + +sample + + + +INSTALL_DEVEL_IMG + + +cpu_features:amd64_install_devel +install_devel + + + +SPL->INSTALL_DEVEL_IMG + + +copy + + + +ENV_IMG->DEVEL_IMG + + + + + +INSTALL_ENV_IMG + + +cpu_features:amd64_install_env +install_env + + + +ENV_IMG->INSTALL_ENV_IMG + + + + + +ENV_TAR + + + +docker_amd64_env.tar + + + +ENV_IMG->ENV_TAR + + +make save_amd64_env + + + +BUILD_IMG + + +cpu_features:amd64_build +build + + + +DEVEL_IMG->BUILD_IMG + + + + + +DEVEL_TAR + + + +docker_amd64_devel.tar + + + +DEVEL_IMG->DEVEL_TAR + + +make save_amd64_devel + + + +TEST_IMG + + +cpu_features:amd64_test +test + + + +BUILD_IMG->TEST_IMG + + + + + +BUILD_IMG->INSTALL_ENV_IMG + + +copy install + + + +BUILD_TAR + + + +docker_amd64_build.tar + + + +BUILD_IMG->BUILD_TAR + + +make save_amd64_build + + + +TEST_TAR + + + +docker_amd64_test.tar + + + +TEST_IMG->TEST_TAR + + +make save_amd64_test + + + +INSTALL_ENV_IMG->INSTALL_DEVEL_IMG + + + + + +INSTALL_ENV_TAR + + + +docker_amd64_install_env.tar + + + +INSTALL_ENV_IMG->INSTALL_ENV_TAR + + +make save_amd64_install_env + + + +INSTALL_BUILD_IMG + + +cpu_features:amd64_install_build +install_build + + + +INSTALL_DEVEL_IMG->INSTALL_BUILD_IMG + + + + + +INSTALL_DEVEL_TAR + + + +docker_amd64_install_devel.tar + + + +INSTALL_DEVEL_IMG->INSTALL_DEVEL_TAR + + +make save_amd64_install_devel + + + +INSTALL_TEST_IMG + + +cpu_features:amd64_install_test +install_test + + + +INSTALL_BUILD_IMG->INSTALL_TEST_IMG + + + + + +INSTALL_BUILD_TAR + + + +docker_amd64_install_build.tar + + + +INSTALL_BUILD_IMG->INSTALL_BUILD_TAR + + +make save_amd64_install_build + + + +INSTALL_TEST_TAR + + + +docker_amd64_install_test.tar + + + +INSTALL_TEST_IMG->INSTALL_TEST_TAR + + +make save_amd64_install_test + + + diff --git a/ci/doc/generate_image.sh b/ci/doc/generate_image.sh new file mode 100755 index 0000000..15f1774 --- /dev/null +++ b/ci/doc/generate_image.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -ex + +rm -f ./*.svg ./*.png +for i in *.dot; do + plantuml -Tsvg "$i"; +done diff --git a/ci/docker/amd64/Dockerfile b/ci/docker/amd64/Dockerfile new file mode 100644 index 0000000..9b25e28 --- /dev/null +++ b/ci/docker/amd64/Dockerfile @@ -0,0 +1,48 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/ubuntu +FROM ubuntu:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=/usr/local/bin:$PATH +RUN apt-get update -qq \ +&& DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \ + ninja-build python3 pkgconf libglib2.0-dev \ +&& apt-get clean \ +&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +ENTRYPOINT ["/usr/bin/bash", "-c"] +CMD ["/usr/bin/bash"] + +# Install CMake 3.21.3 +RUN wget "https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.sh" \ +&& chmod a+x cmake-3.21.3-linux-x86_64.sh \ +&& ./cmake-3.21.3-linux-x86_64.sh --prefix=/usr/local/ --skip-license \ +&& rm cmake-3.21.3-linux-x86_64.sh + +FROM env AS devel +WORKDIR /home/project +COPY . . + +FROM devel AS build +RUN cmake -version +RUN cmake -S. -Bbuild +RUN cmake --build build --target all -v +RUN cmake --build build --target install -v + +FROM build AS test +ENV CTEST_OUTPUT_ON_FAILURE=1 +RUN cmake --build build --target test -v + +# Test install rules +FROM env AS install_env +COPY --from=build /usr/local /usr/local/ + +FROM install_env AS install_devel +WORKDIR /home/sample +COPY ci/sample . + +FROM install_devel AS install_build +RUN cmake -S. -Bbuild +RUN cmake --build build --target all -v + +FROM install_build AS install_test +RUN cmake --build build --target test diff --git a/ci/docker/toolchain/Dockerfile b/ci/docker/toolchain/Dockerfile new file mode 100644 index 0000000..1bf25ed --- /dev/null +++ b/ci/docker/toolchain/Dockerfile @@ -0,0 +1,34 @@ +# Create a virtual environment with all tools installed +# ref: https://hub.docker.com/_/ubuntu +FROM ubuntu:latest AS env +LABEL maintainer="corentinl@google.com" +# Install system build dependencies +ENV PATH=/usr/local/bin:$PATH +RUN apt-get update -qq \ +&& DEBIAN_FRONTEND=noninteractive apt-get install -yq git wget libssl-dev build-essential \ + ninja-build python3 pkgconf libglib2.0-dev \ +&& apt-get clean \ +&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +ENTRYPOINT ["/usr/bin/bash", "-c"] +CMD ["/usr/bin/bash"] + +# Install CMake 3.21.3 +RUN wget "https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.sh" \ +&& chmod a+x cmake-3.21.3-linux-x86_64.sh \ +&& ./cmake-3.21.3-linux-x86_64.sh --prefix=/usr/local/ --skip-license \ +&& rm cmake-3.21.3-linux-x86_64.sh + +FROM env AS devel +WORKDIR /home/project +COPY . . + +ARG TARGET +ENV TARGET ${TARGET:-unknown} + +FROM devel AS build +RUN cmake -version +RUN ./scripts/run_integration.sh build + +FROM build AS test +RUN ./scripts/run_integration.sh qemu +RUN ./scripts/run_integration.sh test diff --git a/ci/sample/CMakeLists.txt b/ci/sample/CMakeLists.txt new file mode 100644 index 0000000..b60e92f --- /dev/null +++ b/ci/sample/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.15) +project(Sample VERSION 1.0.0 LANGUAGES CXX) + +include(CTest) +find_package(CpuFeatures REQUIRED) + +add_executable(sample main.cpp) +target_compile_features(sample PUBLIC cxx_std_11) +set_target_properties(sample PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + VERSION ${PROJECT_VERSION}) +target_link_libraries(sample PRIVATE CpuFeatures::cpu_features) + +if(BUILD_TESTING) + add_test(NAME sample_test COMMAND sample) +endif() + +include(GNUInstallDirs) +install(TARGETS sample + EXPORT SampleTargets + DESTINATION ${CMAKE_INSTALL_BIN_DIR}) diff --git a/ci/sample/main.cpp b/ci/sample/main.cpp new file mode 100644 index 0000000..45ec651 --- /dev/null +++ b/ci/sample/main.cpp @@ -0,0 +1,11 @@ +#include + +#include "cpuinfo_x86.h" + +using namespace cpu_features; + +int main(int /*argc*/, char** /*argv*/) { + static const X86Features features = GetX86Info().features; + std::cout << std::endl; + return 0; +}