Skip to content

Commit

Permalink
Set up Docker build and CI to get the version build right
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Aug 14, 2024
1 parent 7e23f9d commit d173607
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ FROM base AS build
ARG THREADS=8
ARG TARGETARCH

# If you didn't `make version` berfore building the Docker, you can provide a
# version value here to claim to be.
ARG VG_GIT_VERSION
ENV VG_GIT_VERSION=${VG_GIT_VERSION:-unknown}

RUN echo build > /stage.txt

RUN apt-get -qq -y update && \
Expand Down Expand Up @@ -56,22 +61,13 @@ RUN find . -name CMakeCache.txt | xargs rm -f
COPY Makefile /vg/Makefile
RUN . ./source_me.sh && CXXFLAGS="$(if [ -z "${TARGETARCH}" ] || [ "${TARGETARCH}" = "amd64" ] ; then echo " -march=nehalem "; fi)" CFLAGS="$(if [ -z "${TARGETARCH}" ] || [ "${TARGETARCH}" = "amd64" ] ; then echo " -march=nehalem "; fi)" make -j $((THREADS < $(nproc) ? THREADS : $(nproc))) deps

# Bring in the sources, which we need in order to build
# Bring in the sources, which we need in order to build.
COPY src /vg/src

# Build all the object files for vg, but don't link.
# Also pass the arch here
RUN . ./source_me.sh && CXXFLAGS="$(if [ -z "${TARGETARCH}" ] || [ "${TARGETARCH}" = "amd64" ] ; then echo " -march=nehalem "; fi)" make -j $((THREADS < $(nproc) ? THREADS : $(nproc))) objs

# Bring in any includes we pre-made, like the git version, if present
COPY include /vg/include

# Make sure version introspection is up to date
RUN rm -f obj/version.o && . ./source_me.sh && CXXFLAGS="$(if [ -z "${TARGETARCH}" ] || [ "${TARGETARCH}" = "amd64" ] ; then echo " -march=nehalem "; fi)" make -j $((THREADS < $(nproc) ? THREADS : $(nproc))) obj/version.o

# Announce the version file, which must exist by now
RUN ls /vg/include && cat /vg/include/vg_git_version.hpp

# Do the final build and link, knowing the version. Trim down the resulting binary but make sure to include enough debug info for profiling.
RUN . ./source_me.sh && CXXFLAGS="$(if [ -z "${TARGETARCH}" ] || [ "${TARGETARCH}" = "amd64" ] ; then echo " -march=nehalem "; fi)" make -j $((THREADS < $(nproc) ? THREADS : $(nproc))) static && strip -d bin/vg

Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ DEPS += $(INC_DIR)/BooPHF.h
DEPS += $(INC_DIR)/mio/mmap.hpp
DEPS += $(INC_DIR)/atomic_queue.h

.PHONY: clean clean-tests get-deps deps test set-path objs static static-docker docs man .pre-build
.PHONY: clean clean-tests get-deps deps test set-path objs static static-docker docs man .pre-build version

# Aggregate all libvg deps, and exe deps other than libvg
LIBVG_DEPS = $(OBJ) $(ALGORITHMS_OBJ) $(IO_OBJ) $(DEP_OBJ) $(DEPS)
Expand Down Expand Up @@ -866,8 +866,10 @@ $(LIB_DIR)/libxg.a: $(XG_DIR)/src/*.hpp $(XG_DIR)/src/*.cpp $(INC_DIR)/mmmultima

# Auto-git-versioning

# We need to scope this variable here
GIT_VERSION_FILE_DEPS =
# Can be overridden from the environment to supply a version if none is on disk.
VG_GIT_VERSION ?= unknown
# Clean old path
$(shell rm -f $(INC_DIR)/vg_git_version.hpp)
# Decide if .git exists and needs to be watched
ifeq ($(shell if [ -d .git ]; then echo present; else echo absent; fi),present)
# If so, try and make a git version file.
Expand All @@ -879,19 +881,20 @@ ifeq ($(shell if [ -d .git ]; then echo present; else echo absent; fi),present)
# If it's not the same as the old one, replace the old one.
# If it is the same, do nothing and don't rebuild dependent targets.
$(info Check Git)
# Clean old path
$(shell rm -f $(INC_DIR)/vg_git_version.hpp)
$(shell echo "#define VG_GIT_VERSION \"$(shell git describe --always --tags 2>/dev/null || echo git-error)\"" > $(SRC_DIR)/vg_git_version.hpp.tmp)
$(shell diff $(SRC_DIR)/vg_git_version.hpp.tmp $(SRC_DIR)/vg_git_version.hpp >/dev/null 2>/dev/null || cp $(SRC_DIR)/vg_git_version.hpp.tmp $(SRC_DIR)/vg_git_version.hpp)
$(shell rm -f $(SRC_DIR)/vg_git_version.hpp.tmp)
$(shell diff $(SRC_DIR)/vg_git_version.hpp.tmp $(SRC_DIR)/vg_git_version.hpp >/dev/null 2>/dev/null || cp $(SRC_DIR)/vg_git_version.hpp.tmp $(SRC_DIR)/vg_git_version.hpp)
$(shell rm -f $(SRC_DIR)/vg_git_version.hpp.tmp)
else
# Just use the version file we have, if any
# Just use the version file we have, if any.
$(info Do not check Git)
# Clean old path
$(shell rm -f $(INC_DIR)/vg_git_version.hpp)
$(shell if [ ! -e $(SRC_DIR)/vg_git_version.hpp ]; then touch $(SRC_DIR)/vg_git_version.hpp; fi;)
$(shell if [ ! -e $(SRC_DIR)/vg_git_version.hpp] ; then echo "#define VG_GIT_VERSION \"$(VG_GIT_VERSION)\"" > $(SRC_DIR)/vg_git_version.hpp ; fi)
endif


# We have a do-nothing target so we can "make version"
version:
@echo "Version information up to date"

# Build an environment version file.
# If it's not the same as the old one, replace the old one.
# If it is the same, do nothing and don't rebuild dependent targets.
Expand Down
4 changes: 2 additions & 2 deletions vgci/vgci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ then
# have priveleges to easily install dependencies

# Build the git version file first, so the Docker knows its version
make include/vg_git_version.hpp
make version

docker pull ubuntu:18.04
docker pull mirror.gcr.io/library/ubuntu:20.04
docker build --no-cache -t "${DOCKER_TAG}" -f Dockerfile .
if [ "$?" -ne 0 ]
then
Expand Down

0 comments on commit d173607

Please sign in to comment.