diff --git a/.gitignore b/.gitignore index 1b0152c..ad4875e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode .build .deps +.settings/language.settings.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ddfa3e..7db3714 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,11 @@ env: - PARALLELMFLAGS="-j2" - PORTABLE_WORSPACE=1 matrix: - - MARCH=amd64 CHECK_TARGET=memcheck - - MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check before_script: -- make MARCH=$MARCH +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: -- make MARCH=$MARCH $CHECK_TARGET +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET diff --git a/Makefile b/Makefile index 49a896e..06a4e5e 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ DOCKER_BUILDKIT ?= VERBOSE ?= BUILDVERBOSE ?= BUILDTARGET ?= +BUILDTYPE ?= Debug MARCH ?= $(call march,$(BUILDTARGET)) PROJECT_NAME ?= webfuse @@ -24,8 +25,8 @@ OUT ?= $(PROJECT_ROOT)/.build UID ?= $(shell id -u) -CONTAINER_USER ?= $(UID) -CONTAINER_GROUP ?= $(shell id -g) +CONTAINER_USER ?= user +CONTAINER_GROUP ?= user CONTAINER_CGROUP_PARENT ?= HOST_CONTAINER ?= $(shell $(PROJECT_ROOT)/build/get_container_id.sh) @@ -41,6 +42,11 @@ UBUNTU_CODENAME ?= bionic # Dependencies +DUMB_INIT_VERISON ?= 1.2.2 +DOCKER_BUILDARGS += DUMB_INIT_VERISON=$(DUMB_INIT_VERISON) +FETCH_TARGETS += $(OUT)/dumb-init-$(DUMB_INIT_VERISON).tar.gz +$(OUT)/dumb-init-$(DUMB_INIT_VERISON).tar.gz: URL := https://github.com/Yelp/dumb-init/archive/v${DUMB_INIT_VERISON}.tar.gz + GTEST_VERSION ?= 1.8.1 DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION) FETCH_TARGETS += $(OUT)/googletest-release-$(GTEST_VERSION).tar.gz @@ -93,21 +99,24 @@ $(addprefix $(OUT)/docker/,$(UBUNTU_TARGETS)): CODENAME := $(UBUNTU_CODENAME) # Common rule target configuration CMAKEFLAGS += '-GNinja' +CMAKEFLAGS += '-DCMAKE_BUILD_TYPE=$(BUILDTYPE)' BUILDSILENT := $(if $(BUILDVERBOSE),,1) $(BUILDSILENT)NINJAFLAGS += -v -DOCKER_RUNFLAGS += --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined +DOCKER_RUNFLAGS += --device /dev/fuse +DOCKER_RUNFLAGS += --cap-add SYS_ADMIN +DOCKER_RUNFLAGS += --security-opt apparmor:unconfined + +DOCKER_RUNFLAGS += --cap-add SYS_PTRACE +DOCKER_RUNFLAGS += --security-opt seccomp=unconfined DOCKER_RUNFLAGS += --interactive DOCKER_RUNFLAGS += --rm -DOCKER_RUNFLAGS += --init DOCKER_RUNFLAGS += --user $(CONTAINER_USER):$(CONTAINER_GROUP) DOCKER_RUNFLAGS += --env SOURCE_DATE_EPOCH DOCKER_RUNFLAGS += --env BUILDTIME DOCKER_RUNFLAGS += --env NINJA_STATUS -DOCKER_RUNFLAGS += $(addprefix --volumes-from ,$(HOST_CONTAINER)) -DOCKER_RUNFLAGS += $(addprefix --cgroup-parent ,$(CONTAINER_CGROUP_PARENT)) DOCKER_BUILDARGS += CODENAME=$(CODENAME) DOCKER_BUILDARGS += PARALLELMFLAGS=$(PARALLELMFLAGS) @@ -118,10 +127,12 @@ DOCKER_BUILDARGS += OUT=$(CONTAINER_OUT) DOCKER_BUILDFLAGS += --rm DOCKER_BUILDFLAGS += $(addprefix --build-arg ,$(DOCKER_BUILDARGS)) +OUT_TARGETS += $(addprefix $(OUT)/,$(TARGETS)) + OUT_DIRS += $(OUT) OUT_DIRS += $(OUT)/docker OUT_DIRS += $(OUT)/src -OUT_DIRS += $(addprefix $(OUT)/,$(TARGETS)) +OUT_DIRS += $(addsuffix /$(BUILDTYPE),$(OUT_TARGETS)) BUILD_TARGETS += $(addprefix build-,$(TARGETS)) CHECK_TARGETS += $(addprefix check-,$(TARGETS)) @@ -129,7 +140,7 @@ CLEAN_TARGETS += $(addprefix clean-,$(TARGETS)) RUN_TARGETS += $(addprefix run-,$(firstword $(TARGETS))) EXTRACT_TARGETS += $(patsubst $(OUT)/%.tar.gz,$(OUT)/src/%,$(FETCH_TARGETS)) DISCOVER_CC_TARGETS += $(addprefix discover-cc-,$(firstword $(TARGETS))) -RULE_TARGETS = $(addprefix $(OUT)/,$(addsuffix /rules.mk,$(TARGETS))) +RULE_TARGETS += $(addsuffix /rules.mk,$(OUT_TARGETS)) TARGETS := $(sort $(TARGETS)) @@ -139,33 +150,36 @@ echo_if_silent = VERBOSE=1 $(VERBOSE)echo_if_silent = echo $1 $(VERBOSE)SILENT := @ -$(HOST_CONTAINER)container_run_volumes += '$(realpath $(PROJECT_ROOT)):$(CONTAINER_PROJECT_ROOT):cached' -$(HOST_CONTAINER)container_run_volumes += '$(realpath $(OUT)/$1):$(CONTAINER_OUT)/$1:delegated' +$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(PROJECT_ROOT)):$(CONTAINER_PROJECT_ROOT):cached' +$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(OUT)/$1):$(CONTAINER_OUT)/$1:delegated' +image_run_volumes += $(addprefix --volumes-from ,$2) -container_name = $(REGISTRY_PREFIX)$(subst -,/,$1)/$(PROJECT_NAME):$(VERSION) -container_run = $(DOCKER) run $(DOCKER_RUNFLAGS) $3 \ - $(addprefix --volume ,$(call container_run_volumes,$1)) \ - --workdir '$(CONTAINER_OUT)/$1' \ - $(call container_name,$1) \ +image_name = $(REGISTRY_PREFIX)$(subst -,/,$1)/$(PROJECT_NAME):$(VERSION) +image_run = $(DOCKER) run $(DOCKER_RUNFLAGS) \ + $(call image_run_volumes,$1,$(HOST_CONTAINER)) \ + $(addprefix --cgroup-parent ,$(CONTAINER_CGROUP_PARENT)) \ + --workdir '$(CONTAINER_OUT)/$1/$(BUILDTYPE)' \ + $3 \ + $(call image_name,$1) \ $2 image_rule = \ $$(OUT)/docker/$1: $$(OUT)/docker/$1.dockerfile $$(EXTRACT_TARGETS) $$(PROJECT_ROOT)/Makefile; \ - $(SILENT)$$(call image,$1) + $$(SILENT)$$(call image,$1) image = \ - $(call echo_if_silent,docker build $(call container_name,$1) $(OUT)) \ - && $(DOCKER) build $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(call container_name,$1) $(OUT) + $(call echo_if_silent,TARGET=$1 docker build $(call image_name,$1) $(OUT)) \ + && $(DOCKER) build $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(call image_name,$1) $(OUT) configure_rule = \ - $$(OUT)/$1/CMakeCache.txt: $$(PROJECT_ROOT)/CMakeLists.txt $$(OUT)/docker/$1; \ - $(SILENT)$$(call configure,$1) + $$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt: $$(PROJECT_ROOT)/CMakeLists.txt $$(OUT)/docker/$1 | $$(OUT)/$1/$$(BUILDTYPE)/gdbserver; \ + $$(SILENT)$$(call configure,$1) configure = \ $(call run,$1,sh -c 'cmake $(CMAKEFLAGS) $(CONTAINER_PROJECT_ROOT) && $(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $@) $(realpath $(dir $@))') \ && touch $(addprefix $(dir $@)/,include_dirs.txt) $@ build_rule = \ - build-$1: $$(OUT)/$1/CMakeCache.txt; \ - $(SILENT)$$(call build,$1) + build-$1: $$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt; \ + $$(SILENT)$$(call build,$1) build = $(call run,$1,ninja $(PARALLELMFLAGS) $(NINJAFLAGS) $(GOALS)) check_rule = \ @@ -173,30 +187,44 @@ check_rule = \ memcheck_rule = \ memcheck-$1: build-$1; \ - $(SILENT)$$(call memcheck,$1) + $$(SILENT)$$(call memcheck,$1) memcheck = $(call run,$1,ctest -T memcheck $(CTESTFLAGS)) run_rule = \ run-$1: $$(OUT)/docker/$1; \ - $(SILENT)$$(call run,$1,/bin/bash,--tty) || true -run = $(call echo_if_silent,TARGET=$1 $2) && $(call container_run,$1,$2,$3) + $$(SILENT)$$(call run,$1,bash,--tty) || true +run = $(call echo_if_silent,TARGET=$1 BUILDTYPE=$(BUILDTYPE) $2) && $(call image_run,$1,$2,$3) clean_rule = \ clean-$1: ; \ - $(SILENT)-$$(call clean,$1) + $$(SILENT)-$$(call clean,$1) clean = rm -rf $(OUT)/$1 discover_cc_settings_rule = \ - $$(OUT)/$1/include_dirs.txt: $$(OUT)/$1/CMakeCache.txt; \ - $(SILENT)$$(call discover_cc_settings,$1) + $$(OUT)/$1/$$(BUILDTYPE)/include_dirs.txt: $$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt; \ + $$(SILENT)$$(call discover_cc_settings,$1) discover_cc_settings = \ $(call run,$1,$(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $<) $(realpath $(dir $<))) discover_cc_rule = \ - discover-cc-$1: $$(OUT)/$1/include_dirs.txt; \ - $(SILENT)$$(call discover_cc,$1) + discover-cc-$1: $$(OUT)/$1/$$(BUILDTYPE)/include_dirs.txt; \ + $$(SILENT)$$(call discover_cc,$1) discover_cc = cat $< +wrapper_rule = \ + $$(OUT)/$1/$$(BUILDTYPE)/gdbserver: $$(PROJECT_ROOT)/build/run_image.template $$(OUT)/docker/$1; \ + $$(SILENT)$$(call wrapper,$1) +wrapper = \ + $(call echo_if_silent,generating $@) \ + && sed \ + -e 's@%PROJECT_ROOT%@$(abspath $(PROJECT_ROOT))@g' \ + -e 's@%DOCKER%@$(DOCKER)@g' \ + -e 's@%RUNFLAGS%@$(DOCKER_RUNFLAGS) $(call image_run_volumes,$1)@g' \ + -e 's@%IMAGE%@$(call image_name,$1)@g' \ + -e 's@%RUNCMD%@$(notdir $@)@g' \ + $< > $@ \ + && chmod +x $@ + # Rules ifneq ($(MAKECMDGOALS),distclean) @@ -224,6 +252,8 @@ $(RULE_TARGETS): $(PROJECT_ROOT)/Makefile | $(OUT_DIRS) echo '$(call discover_cc_settings_rule,$(TARGET))'; \ echo; \ echo '$(call discover_cc_rule,$(TARGET))'; \ + echo; \ + echo '$(call wrapper_rule,$(TARGET))'; \ } > $@ .PHONY: all build-% @@ -259,7 +289,6 @@ debug-print-%: @printf '%s\n' '$*:' $($*) $(CHECK_TARGETS): GOALS := test -$(CHECK_TARGETS) $(MEMCHECK_TARGETS): CONTAINER_USER := user $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): $(SILENT) \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 543b826..317e5e2 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -11,61 +11,79 @@ RUN set -x \ ninja-build \ pkg-config \ rsync \ - valgrind \ - && rm -rf /var/lib/apt/lists/* + gdb \ + gdbserver \ + valgrind COPY src /usr/local/src ARG PARALLELMFLAGS=-j2 +ARG DUMB_INIT_VERISON=1.2.2 + +RUN set -x \ + && builddeps="xxd" \ + && apt install --yes --no-install-recommends $builddeps \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ + && cp -R "/usr/local/src/dumb-init-$DUMB_INIT_VERISON" . \ + && cd dumb-init-$DUMB_INIT_VERISON \ + && make "$PARALLELMFLAGS" \ + && chmod +x dumb-init \ + && mv dumb-init /usr/local/bin/dumb-init \ + && dumb-init --version \ + && rm -rf "$builddir" \ + && apt purge -y $builddeps + ARG GTEST_VERSION=1.8.1 RUN set -x \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake "/usr/local/src/googletest-release-$GTEST_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out + && rm -rf "$builddir" ARG FUSE_VERSION=3.1.1 RUN set -x \ - && apt update \ - && apt install --yes --no-install-recommends \ - libtool \ - automake \ - gettext \ + && builddeps="libtool automake gettext" \ + && apt install --yes --no-install-recommends $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out \ - && rm -rf /var/lib/apt/lists/* + && rm -rf "$builddir" \ + && apt purge -y $builddeps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt update \ && apt install --yes --no-install-recommends \ + ca-certificates \ openssl \ libssl-dev \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out \ - && rm -rf /var/lib/apt/lists/* + && rm -rf "$builddir" ARG JANSSON_VERSION=2.12 RUN set -x \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake -DJANSSON_BUILD_DOCS=OFF "/usr/local/src/jansson-$JANSSON_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out + && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" @@ -81,3 +99,5 @@ RUN set -x \ WORKDIR "$OUT" +ENTRYPOINT ["dumb-init", "--"] + diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index f605e0c..e0a1f31 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -13,60 +13,78 @@ RUN set -x \ ninja-build \ pkg-config \ rsync \ - && rm -rf /var/lib/apt/lists/* + gdb \ + gdbserver COPY src /usr/local/src ARG PARALLELMFLAGS=-j2 +ARG DUMB_INIT_VERISON=1.2.2 + +RUN set -x \ + && builddeps="xxd" \ + && apt install --yes --no-install-recommends $builddeps \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ + && cp -R "/usr/local/src/dumb-init-$DUMB_INIT_VERISON" . \ + && cd dumb-init-$DUMB_INIT_VERISON \ + && make "$PARALLELMFLAGS" \ + && chmod +x dumb-init \ + && mv dumb-init /usr/local/bin/dumb-init \ + && dumb-init --version \ + && rm -rf "$builddir" \ + && apt purge -y $builddeps + ARG GTEST_VERSION=1.8.1 RUN set -x \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake "/usr/local/src/googletest-release-$GTEST_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out + && rm -rf "$builddir" ARG FUSE_VERSION=3.1.1 RUN set -x \ - && apt update \ - && apt install --yes --no-install-recommends \ - libtool \ - automake \ - gettext \ + && builddeps="libtool automake gettext" \ + && apt install --yes --no-install-recommends $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out \ - && rm -rf /var/lib/apt/lists/* + && rm -rf "$builddir" \ + && apt purge -y $builddeps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt update \ && apt install --yes --no-install-recommends \ + ca-certificates \ openssl \ libssl-dev \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out \ - && rm -rf /var/lib/apt/lists/* + && rm -rf "$builddir" ARG JANSSON_VERSION=2.12 RUN set -x \ - && mkdir -p /tmp/out \ - && cd /tmp/out \ + && builddir="/tmp/out" \ + && mkdir -p "$builddir" \ + && cd "$builddir" \ && cmake -DJANSSON_BUILD_DOCS=OFF "/usr/local/src/jansson-$JANSSON_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf /tmp/out + && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" @@ -82,3 +100,5 @@ RUN set -x \ WORKDIR "$OUT" +ENTRYPOINT ["dumb-init", "--"] + diff --git a/build/discover_cc_settings.sh b/build/discover_cc_settings.sh index 61a08fd..276c13b 100755 --- a/build/discover_cc_settings.sh +++ b/build/discover_cc_settings.sh @@ -41,6 +41,7 @@ fi { echo '#include <...> search starts here:' + # shellcheck disable=SC1117 sed -n -e "s@\(.*\)@$INCLUDE_DIRS_PREFIX\1@p" "$INCLUDE_DIRS_TMPFILE" echo 'End of search list.' } > "$INCLUDE_DIRS_FILE" diff --git a/.settings/language.settings.xml b/build/language.settings.xml similarity index 69% rename from .settings/language.settings.xml rename to build/language.settings.xml index dc364b8..910ca28 100644 --- a/.settings/language.settings.xml +++ b/build/language.settings.xml @@ -2,7 +2,22 @@ - + + + + + + + + + + + + + + + + diff --git a/build/run_image.template b/build/run_image.template new file mode 100644 index 0000000..d199b1e --- /dev/null +++ b/build/run_image.template @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +PROJECT_ROOT="${PROJECT_ROOT:-%PROJECT_ROOT%}" + +DOCKER="${DOCKER:-%DOCKER%}" +IMAGE="${IMAGE:-%IMAGE%}" +NETWORK="${NETWORK:-host}" +HOST_CONTAINER="${HOST_CONTAINER:-"$("$PROJECT_ROOT/build/get_container_id.sh")"}" + +# shellcheck disable=SC2162 +read -a ADDITIONAL_RUNFLAGS <<< "$RUNFLAGS" + +RUNFLAGS=() + +# shellcheck disable=SC2191 +RUNFLAGS+=( %RUNFLAGS% ) + +if [[ -n "$HOST_CONTAINER" ]]; then + RUNFLAGS+=( --volumes-from "$HOST_CONTAINER" ) +fi + +RUNFLAGS+=( --network "$NETWORK" ) + +if [[ -n "$CONTAINER_CGROUP_PARENT" ]]; then + RUNFLAGS+=( --cgroup-parent "$CONTAINER_CGROUP_PARENT" ) +fi + +RUNFLAGS+=( --workdir "$PWD" ) + +RUNCMD=( %RUNCMD% ) + +set -- "${RUNFLAGS[@]}" "${ADDITIONAL_RUNFLAGS[@]}" "$IMAGE" "${RUNCMD[@]}" "$@" + +exec "$DOCKER" run "$@"