@@ -15,6 +15,16 @@ LINT_OS := $(shell uname)
1515LINT_OS_LOWER := $(shell echo $(LINT_OS ) | tr '[:upper:]' '[:lower:]')
1616LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST ) ) ) )
1717
18+ # flags required to successfully build malcontent with yara-x's C API
19+ CPPFLAGS ?= "-I$(LINT_ROOT ) /out/include"
20+ LDFLAGS :=
21+ PKGCONF_PATH ?= "$(LINT_ROOT ) /out/lib/pkgconfig"
22+ ifeq ($(LINT_OS ) ,Darwin)
23+ LDFLAGS="-L$(LINT_ROOT)/out/lib -Wl,-no_warn_duplicate_libraries,-rpath,$(LINT_ROOT)/out/lib,-lyara_x_capi"
24+ else ifeq ($(LINT_OS),Linux)
25+ LDFLAGS="-L$(LINT_ROOT)/out/lib -Wl,-rpath,$(LINT_ROOT)/out/lib,-lyara_x_capi,-no-pie"
26+ endif
27+
1828# yara-x adds an additional string for the platform (apple, unknown)
1929LINT_PLATFORM :=
2030ifeq ($(LINT_OS ) ,Darwin)
@@ -41,22 +51,22 @@ $(GOLANGCI_LINT_BIN):
4151 mv $(LINT_ROOT ) /out/linters/golangci-lint $@
4252
4353YARA_X_REPO ?= virusTotal/yara-x
44- YARA_X_VERSION ?= v1.12 .0
45- YARA_X_COMMIT ?= 466a624e381beefde7665433494887d80932a662
54+ YARA_X_VERSION ?= v1.13 .0
55+ YARA_X_COMMIT ?= d397e8c3feee79e91f4b389288ba244264da2813
4656YARA_X_SHA :=
4757ifeq ($(LINT_OS ) ,Darwin)
4858 ifeq ($(shell uname -m),arm64)
4959 LINT_ARCH = aarch64
50- YARA_X_SHA = 63100b4d6505c366d3c6af5145a26b961d2bf1646a4442716d81bb6f6a4dbee2
60+ YARA_X_SHA = 0931697b9cfe74cade4a7136610a5cd254ae3bed95831b413c6b54f5760d554f
5161 else
52- YARA_X_SHA = 29a50a3cf442206b9c116f3a322debc367215d4667cf99512550cbdca7c88fc0
62+ YARA_X_SHA = 226dce240b8d674db3c83b5c0b6d336268a46f1fbd6718fa9bdeb3735857f6c4
5363 endif
5464else ifeq ($(LINT_OS),Linux)
5565 ifeq ($(shell uname -m),arm64)
5666 LINT_ARCH = aarch64
57- YARA_X_SHA = 614cb7b5a738e1e6e3fe6b98bca207c2dfd012ad95d4a85d5e62a0eac985c554
67+ YARA_X_SHA = a50e9b593c5a6039c227f665b8ade1ea1c4bee3be5789add3e33f033cbf427ae
5868 else
59- YARA_X_SHA = f460a20b78b66b08b6d323f1d1ed00ab94328ae98a3f755f29692e49caa48cb7
69+ YARA_X_SHA = b93fb0b87016c60498c26b8a17d2617bbc49f5d5b1a291cde5b09658ce93bb69
6070 endif
6171endif
6272YARA_X_BIN := $(LINT_ROOT ) /out/linters/yr-$(YARA_X_VERSION ) -$(LINT_ARCH )
@@ -70,14 +80,20 @@ $(YARA_X_BIN):
7080
7181LINTERS += golangci-lint-lint
7282golangci-lint-lint : $(GOLANGCI_LINT_BIN )
73- find . -maxdepth 1 -name go.mod -print0 | xargs -0 -L1 -I{} /bin/sh -c ' "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)"' \;
83+ find . -maxdepth 1 -name go.mod -print0 | xargs -0 -L1 -I{} /bin/sh -c ' CGO_LDFLAGS=$(LDFLAGS) CGO_CPPFLAGS=$(CPPFLAGS) PKG_CONFIG_PATH=$(PKGCONF_PATH) "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)"' \;
7484
7585FIXERS += golangci-lint-fix
7686golangci-lint-fix : $(GOLANGCI_LINT_BIN )
87+ CGO_LDFLAGS=$(LDFLAGS ) \
88+ CGO_CPPFLAGS=$(CPPFLAGS ) \
89+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
7790 find . -maxdepth 1 -name go.mod -execdir " $( GOLANGCI_LINT_BIN) " run -c " $( GOLANGCI_LINT_CONFIG) " --fix \;
7891
7992FIXERS += modernize
8093modernize :
94+ CGO_LDFLAGS=$(LDFLAGS ) \
95+ CGO_CPPFLAGS=$(CPPFLAGS ) \
96+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
8197 go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
8298
8399LINTERS += yara-x-fmt
@@ -115,7 +131,7 @@ out/$(SAMPLES_REPO)/.decompressed-$(SAMPLES_COMMIT): out/${SAMPLES_REPO}/.git/co
115131
116132out/$(YARA_X_REPO ) /.git/commit-$(YARA_X_COMMIT ) :
117133 mkdir -p out/$(YARA_X_REPO )
118- test -d out/$(YARA_X_REPO ) /.git || git clone https://github.com/$(YARA_X_REPO ) .git out/$(YARA_X_REPO )
134+ test -d out/$(YARA_X_REPO ) /.git || git clone https://github.com/$(YARA_X_REPO ) .git out/$(YARA_X_REPO )
119135 rm out/$(YARA_X_REPO ) /.git/commit-* 2> /dev/null || true
120136 git -C out/$(YARA_X_REPO ) switch - || true
121137 git -C out/$(YARA_X_REPO ) pull --rebase --autostash
@@ -130,7 +146,7 @@ install-yara-x: out/$(YARA_X_REPO)/.git/commit-$(YARA_X_COMMIT)
130146 mkdir -p out/include
131147 cd out/$(YARA_X_REPO ) && \
132148 cargo install cargo-c --locked && \
133- cargo cinstall -p yara-x-capi --features=native-code-serialization --release --prefix=" $( LINT_ROOT) /out" --libdir=" $( LINT_ROOT) /out/lib"
149+ RUSTFLAGS= " -C target-feature=+crt-static " cargo cinstall -p yara-x-capi --features=native-code-serialization --profile release-lto --prefix=" $( LINT_ROOT) /out" --libdir=" $( LINT_ROOT) /out/lib" --crt-static --library-type= " staticlib "
134150
135151.PHONY : update-deps
136152update-deps :
@@ -140,6 +156,9 @@ update-deps:
140156# unit tests only
141157.PHONY : test
142158test :
159+ CGO_LDFLAGS=$(LDFLAGS ) \
160+ CGO_CPPFLAGS=$(CPPFLAGS ) \
161+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
143162 go test -race ./pkg/...
144163
145164FUZZ_TIME ?= 10s
@@ -149,9 +168,9 @@ fuzz:
149168 awk -F' [:(]' ' {gsub(/func /, "", $$2); dir=$$1; sub(/\/[^/]+$$/, "/", dir); print $$2, "./" dir}' | \
150169 while read -r func dir; do \
151170 echo " --- $$ func ($$ dir) ---" ; \
152- CGO_LDFLAGS=" -L $( LINT_ROOT ) /out/lib -Wl,-rpath, $( LINT_ROOT ) /out/lib " \
153- CGO_CPPFLAGS=" -I $( LINT_ROOT ) /out/include " \
154- PKG_CONFIG_PATH=" $( LINT_ROOT ) /out/lib/pkgconfig " \
171+ CGO_LDFLAGS=$( LDFLAGS ) \
172+ CGO_CPPFLAGS=$( CPPFLAGS ) \
173+ PKG_CONFIG_PATH=$( PKGCONF_PATH ) \
155174 go test -timeout 0 -fuzz=" ^$$ func$$ " -fuzztime=$(FUZZ_TIME ) " $$ dir" || exit 1; \
156175 done
157176
@@ -161,6 +180,9 @@ FUZZ_TARGET ?= FuzzExtractArchive
161180FUZZ_PKG ?= ./pkg/archive/
162181.PHONY : fuzz-continuous
163182fuzz-continuous :
183+ CGO_LDFLAGS=$(LDFLAGS ) \
184+ CGO_CPPFLAGS=$(CPPFLAGS ) \
185+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
164186 go test -fuzz=$(FUZZ_TARGET ) $(FUZZ_PKG )
165187
166188# unit tests only
@@ -174,28 +196,44 @@ coverage-html: out/coverage.html
174196# pop open the html page in a browser directly
175197.PHONY : coverage-browser
176198coverage-browser : out/mal.coverage
199+ CGO_LDFLAGS=$(LDFLAGS ) \
200+ CGO_CPPFLAGS=$(CPPFLAGS ) \
201+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
177202 go tool cover -html=$<
178203
179204# generate the html report
180205out/coverage.html : out/mal.coverage
206+ CGO_LDFLAGS=$(LDFLAGS ) \
207+ CGO_CPPFLAGS=$(CPPFLAGS ) \
208+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
181209 go tool cover -html=$< -o $@
182210
183211# we always want to regen the coverage data file
184212.PHONY : out/mal.coverage
185213out/mal.coverage :
186214 mkdir -p out
215+ CGO_LDFLAGS=$(LDFLAGS ) \
216+ CGO_CPPFLAGS=$(CPPFLAGS ) \
217+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
187218 go test -coverprofile $@ -race ./pkg/... -coverpkg ./pkg/...
188219
189220# integration tests only
190221.PHONY : integration
191222integration : out/$(SAMPLES_REPO ) /.decompressed-$(SAMPLES_COMMIT )
223+ CGO_LDFLAGS=$(LDFLAGS ) \
224+ CGO_CPPFLAGS=$(CPPFLAGS ) \
225+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
192226 go test -race -timeout 0 ./tests/...
193227
194228.PHONY : bench
195229bench : out/$(SAMPLES_REPO ) /.decompressed-$(SAMPLES_COMMIT )
230+ CGO_LDFLAGS=$(LDFLAGS ) \
231+ CGO_CPPFLAGS=$(CPPFLAGS ) \
232+ PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
196233 go test -run=^\$ $ -bench=. ./... -benchmem
197234
198- BENCH_CMD := go test -benchmem -run=^\$$ -bench ^BenchmarkRun\$$ github.com/chainguard-dev/malcontent/tests -args
235+ BENCH_CMD := CGO_LDFLAGS=$(LDFLAGS ) CGO_CPPFLAGS=$(CPPFLAGS ) PKG_CONFIG_PATH=$(PKGCONF_PATH ) \
236+ go test -benchmem -run=^\$$ -bench ^BenchmarkRun\$$ github.com/chainguard-dev/malcontent/tests -args
199237
200238.PHONY : bench-malcontent
201239bench-malcontent :
@@ -244,9 +282,9 @@ bench-windows:
244282.PHONY : out/mal
245283out/mal :
246284 mkdir -p out
247- CGO_LDFLAGS=" -L $( LINT_ROOT ) /out/lib -Wl,-rpath, $( LINT_ROOT ) /out/lib " \
248- CGO_CPPFLAGS=" -I $( LINT_ROOT ) /out/include " \
249- PKG_CONFIG_PATH=" $( LINT_ROOT ) /out/lib/pkgconfig " \
285+ CGO_LDFLAGS=$( LDFLAGS ) \
286+ CGO_CPPFLAGS=$( CPPFLAGS ) \
287+ PKG_CONFIG_PATH=$( PKGCONF_PATH ) \
250288 go build -o out/mal ./cmd/mal
251289
252290.PHONY : update-third-party
@@ -258,7 +296,7 @@ refresh-sample-testdata: out/$(SAMPLES_REPO)/.decompressed-$(SAMPLES_COMMIT) out
258296 MALCONTENT_UPX_PATH=$(shell which upx) ./out/mal refresh
259297
260298ARCH ?= $(shell uname -m)
261- CRANE_VERSION =v0.20.7
299+ CRANE_VERSION =v0.21.0
262300out/crane-$(ARCH ) -$(CRANE_VERSION ) :
263301 mkdir -p out
264302 GOBIN=$(CURDIR ) /out go install github.com/google/go-containerregistry/cmd/crane@$(CRANE_VERSION )
0 commit comments