From 36e2c6c8bef2102e2cc00b724557f09cbea79d27 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:02:37 +0100 Subject: [PATCH] make: improve re2/wasm check (#3335) --- Makefile | 57 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 4b7f0b746fe..f8ae66e1cb6 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ BUILD_RE2_WASM ?= 0 # for your distribution (look for libre2.a). See the Dockerfile for an example of how to build it. BUILD_STATIC ?= 0 -# List of plugins to build +# List of notification plugins to build PLUGINS ?= $(patsubst ./cmd/notification-%,%,$(wildcard ./cmd/notification-*)) #-------------------------------------- @@ -86,6 +86,11 @@ export CGO_LDFLAGS_ALLOW=-Wl,--(push|pop)-state.* # this will be used by Go in the make target, some distributions require it export PKG_CONFIG_PATH:=/usr/local/lib/pkgconfig:$(PKG_CONFIG_PATH) +#-------------------------------------- +# +# Choose the re2 backend. +# + ifeq ($(call bool,$(BUILD_RE2_WASM)),0) ifeq ($(PKG_CONFIG),) $(error "pkg-config is not available. Please install pkg-config.") @@ -93,35 +98,28 @@ endif ifeq ($(RE2_CHECK),) RE2_FAIL := "libre2-dev is not installed, please install it or set BUILD_RE2_WASM=1 to use the WebAssembly version" +# if you prefer to build WASM instead of a critical error, comment out RE2_FAIL and uncomment RE2_MSG. +# RE2_MSG := Fallback to WebAssembly regexp library. To use the C++ version, make sure you have installed libre2-dev and pkg-config. else # += 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++' +RE2_MSG := Using C++ regexp library endif -endif - -# Build static to avoid the runtime dependency on libre2.so -ifeq ($(call bool,$(BUILD_STATIC)),1) -BUILD_TYPE = static -EXTLDFLAGS := -extldflags '-static' else -BUILD_TYPE = dynamic -EXTLDFLAGS := +RE2_MSG := Using WebAssembly regexp library endif -# Build with debug symbols, and disable optimizations + inlining, to use Delve -ifeq ($(call bool,$(DEBUG)),1) -STRIP_SYMBOLS := -DISABLE_OPTIMIZATION := -gcflags "-N -l" +ifeq ($(call bool,$(BUILD_RE2_WASM)),1) else -STRIP_SYMBOLS := -s -DISABLE_OPTIMIZATION := +ifneq (,$(RE2_CHECK)) +endif endif #-------------------------------------- - +# # Handle optional components and build profiles, to save space on the final binaries. - +# # Keep it safe for now until we decide how to expand on the idea. Either choose a profile or exclude components manually. # For example if we want to disable some component by default, or have opt-in components (INCLUDE?). @@ -182,6 +180,23 @@ endif #-------------------------------------- +ifeq ($(call bool,$(BUILD_STATIC)),1) +BUILD_TYPE = static +EXTLDFLAGS := -extldflags '-static' +else +BUILD_TYPE = dynamic +EXTLDFLAGS := +endif + +# Build with debug symbols, and disable optimizations + inlining, to use Delve +ifeq ($(call bool,$(DEBUG)),1) +STRIP_SYMBOLS := +DISABLE_OPTIMIZATION := -gcflags "-N -l" +else +STRIP_SYMBOLS := -s +DISABLE_OPTIMIZATION := +endif + export LD_OPTS=-ldflags "$(STRIP_SYMBOLS) $(EXTLDFLAGS) $(LD_OPTS_VARS)" \ -trimpath -tags $(GO_TAGS) $(DISABLE_OPTIMIZATION) @@ -197,17 +212,13 @@ build: build-info crowdsec cscli plugins ## Build crowdsec, cscli and plugins .PHONY: build-info build-info: ## Print build information $(info Building $(BUILD_VERSION) ($(BUILD_TAG)) $(BUILD_TYPE) for $(GOOS)/$(GOARCH)) - $(info Excluded components: $(EXCLUDE_LIST)) + $(info Excluded components: $(if $(EXCLUDE_LIST),$(EXCLUDE_LIST),none)) ifneq (,$(RE2_FAIL)) $(error $(RE2_FAIL)) endif -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 $(RE2_MSG)) ifeq ($(call bool,$(DEBUG)),1) $(info Building with debug symbols and disabled optimizations)