build against libre2-dev if found (#2255)
This commit is contained in:
parent
3cc6b2c0d0
commit
edd062522d
4 changed files with 49 additions and 13 deletions
12
Dockerfile
12
Dockerfile
|
@ -7,9 +7,19 @@ WORKDIR /go/src/crowdsec
|
|||
|
||||
COPY . .
|
||||
|
||||
# Alpine does not ship a static version of re2, we can build it ourselves
|
||||
# Later versions require 'abseil', which is likewise not available in its static form
|
||||
ENV RE2_VERSION=2023-03-01
|
||||
|
||||
# wizard.sh requires GNU coreutils
|
||||
RUN apk add --no-cache git gcc libc-dev make bash gettext binutils-gold coreutils && \
|
||||
RUN apk add --no-cache git g++ gcc libc-dev make bash gettext binutils-gold coreutils icu-static re2-dev pkgconfig && \
|
||||
wget https://github.com/google/re2/archive/refs/tags/${RE2_VERSION}.tar.gz && \
|
||||
tar -xzf ${RE2_VERSION}.tar.gz && \
|
||||
cd re2-${RE2_VERSION} && \
|
||||
make && \
|
||||
make install && \
|
||||
echo "githubciXXXXXXXXXXXXXXXXXXXXXXXX" > /etc/machine-id && \
|
||||
cd - && \
|
||||
make clean release DOCKER_BUILD=1 && \
|
||||
cd crowdsec-v* && \
|
||||
./wizard.sh --docker-mode && \
|
||||
|
|
|
@ -12,7 +12,7 @@ ENV DEBCONF_NOWARNINGS="yes"
|
|||
|
||||
# wizard.sh requires GNU coreutils
|
||||
RUN apt-get update && \
|
||||
apt-get install -y -q git gcc libc-dev make bash gettext binutils-gold coreutils tzdata && \
|
||||
apt-get install -y -q git gcc libc-dev make bash gettext binutils-gold coreutils tzdata libre2-dev && \
|
||||
echo "githubciXXXXXXXXXXXXXXXXXXXXXXXX" > /etc/machine-id && \
|
||||
make clean release DOCKER_BUILD=1 && \
|
||||
cd crowdsec-v* && \
|
||||
|
|
46
Makefile
46
Makefile
|
@ -3,6 +3,9 @@ include mk/platform.mk
|
|||
BUILD_REQUIRE_GO_MAJOR ?= 1
|
||||
BUILD_REQUIRE_GO_MINOR ?= 20
|
||||
|
||||
GOCMD = go
|
||||
GOTEST = $(GOCMD) test
|
||||
|
||||
BUILD_CODENAME ?= alphaga
|
||||
|
||||
CROWDSEC_FOLDER = ./cmd/crowdsec
|
||||
|
@ -14,8 +17,21 @@ PLUGINS_DIR = ./plugins/notifications
|
|||
CROWDSEC_BIN = crowdsec$(EXT)
|
||||
CSCLI_BIN = cscli$(EXT)
|
||||
|
||||
# Directory for the release files
|
||||
RELDIR = crowdsec-$(BUILD_VERSION)
|
||||
|
||||
GO_MODULE_NAME = github.com/crowdsecurity/crowdsec
|
||||
|
||||
# see if we have libre2-dev installed for C++ optimizations
|
||||
RE2_CHECK := $(shell pkg-config --libs re2 2>/dev/null)
|
||||
|
||||
#--------------------------------------
|
||||
#
|
||||
# Define MAKE_FLAGS and LD_OPTS for the sub-makefiles in cmd/ and plugins/
|
||||
#
|
||||
|
||||
MAKE_FLAGS = --no-print-directory GOARCH=$(GOARCH) GOOS=$(GOOS) RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
|
||||
|
||||
LD_OPTS_VARS= \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
|
||||
|
@ -28,30 +44,37 @@ ifneq (,$(DOCKER_BUILD))
|
|||
LD_OPTS_VARS += -X '$(GO_MODULE_NAME)/pkg/cwversion.System=docker'
|
||||
endif
|
||||
|
||||
ifdef BUILD_STATIC
|
||||
$(warning WARNING: The BUILD_STATIC variable is deprecated and has no effect. Builds are static by default since v1.5.0.)
|
||||
GO_TAGS := netgo,osusergo,sqlite_omit_load_extension
|
||||
|
||||
ifneq (,$(RE2_CHECK))
|
||||
# += adds a space that we don't want
|
||||
GO_TAGS := $(GO_TAGS),re2_cgo
|
||||
LD_OPTS_VARS += -X '$(GO_MODULE_NAME)/pkg/cwversion.Libre2=C++'
|
||||
endif
|
||||
|
||||
export LD_OPTS=-ldflags "-s -w -extldflags '-static' $(LD_OPTS_VARS)" \
|
||||
-trimpath -tags netgo,osusergo,sqlite_omit_load_extension
|
||||
-trimpath -tags $(GO_TAGS)
|
||||
|
||||
ifneq (,$(TEST_COVERAGE))
|
||||
LD_OPTS += -cover
|
||||
endif
|
||||
|
||||
GOCMD = go
|
||||
GOTEST = $(GOCMD) test
|
||||
|
||||
RELDIR = crowdsec-$(BUILD_VERSION)
|
||||
|
||||
# flags for sub-makefiles
|
||||
MAKE_FLAGS = --no-print-directory GOARCH=$(GOARCH) GOOS=$(GOOS) RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
|
||||
#--------------------------------------
|
||||
|
||||
.PHONY: build
|
||||
build: pre-build goversion crowdsec cscli plugins
|
||||
|
||||
.PHONY: pre-build
|
||||
pre-build:
|
||||
ifdef BUILD_STATIC
|
||||
$(warning WARNING: The BUILD_STATIC variable is deprecated and has no effect. Builds are static by default since v1.5.0.)
|
||||
endif
|
||||
$(info Building $(BUILD_VERSION) ($(BUILD_TAG)) for $(GOOS)/$(GOARCH))
|
||||
ifneq (,$(RE2_CHECK))
|
||||
$(info Using C++ regexp library)
|
||||
else
|
||||
$(info Fallback to WebAssembly regexp library. To use the C++ version, make sure you have installed libre2-dev and pkg-config.)
|
||||
endif
|
||||
$(info )
|
||||
|
||||
.PHONY: all
|
||||
|
@ -75,10 +98,11 @@ clean: testclean
|
|||
$(MAKE) -C $(PLUGINS_DIR)/$(plugin) clean $(MAKE_FLAGS); \
|
||||
)
|
||||
|
||||
|
||||
.PHONY: cscli
|
||||
cscli: goversion
|
||||
@$(MAKE) -C $(CSCLI_FOLDER) build $(MAKE_FLAGS)
|
||||
|
||||
.PHONY: crowdsec
|
||||
crowdsec: goversion
|
||||
@$(MAKE) -C $(CROWDSEC_FOLDER) build $(MAKE_FLAGS)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ var (
|
|||
Constraint_scenario = ">= 1.0, < 3.0"
|
||||
Constraint_api = "v1"
|
||||
Constraint_acquis = ">= 1.0, < 2.0"
|
||||
Libre2 = "WebAssembly"
|
||||
)
|
||||
|
||||
func ShowStr() string {
|
||||
|
@ -38,6 +39,7 @@ func Show() {
|
|||
log.Printf("BuildDate: %s", version.BuildDate)
|
||||
log.Printf("GoVersion: %s", version.GoVersion)
|
||||
log.Printf("Platform: %s\n", System)
|
||||
log.Printf("libre2: %s\n", Libre2)
|
||||
log.Printf("Constraint_parser: %s", Constraint_parser)
|
||||
log.Printf("Constraint_scenario: %s", Constraint_scenario)
|
||||
log.Printf("Constraint_api: %s", Constraint_api)
|
||||
|
|
Loading…
Reference in a new issue