From cb58b97bc9f87a4dd92c37e162d6ac10964191f3 Mon Sep 17 00:00:00 2001 From: Gray Liang Date: Sat, 20 Jan 2024 18:08:04 +0800 Subject: [PATCH] Build with trace only if possible --- .gitignore | 1 + .gitmodules | 3 +++ .gitmodules.d.mk | 1 + Makefile | 10 ++++++++-- cmd/trace.go | 3 +++ control/kern/headers | 2 +- go.mod | 4 ++-- go.sum | 4 ++++ trace/kern/headers | 2 +- 9 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 55e2e3b21a..7d42ba92ad 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ outline.json go-mod/ node_modules/ *.log +.build_tags diff --git a/.gitmodules b/.gitmodules index 60253801d1..1e34e9af94 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "control/kern/headers"] path = control/kern/headers url = https://github.com/daeuniverse/dae_bpf_headers +[submodule "trace/kern/headers"] + path = trace/kern/headers + url = https://github.com/daeuniverse/dae_bpf_headers diff --git a/.gitmodules.d.mk b/.gitmodules.d.mk index d9e0ec9e31..9e52742dcc 100644 --- a/.gitmodules.d.mk +++ b/.gitmodules.d.mk @@ -1 +1,2 @@ submodule_paths=control/kern/headers +submodule_paths=trace/kern/headers diff --git a/Makefile b/Makefile index ecc34878f7..061489568e 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ MAX_MATCH_SET_LEN ?= 64 CFLAGS := -DMAX_MATCH_SET_LEN=$(MAX_MATCH_SET_LEN) $(CFLAGS) NOSTRIP ?= n STRIP_PATH := $(shell command -v $(STRIP) 2>/dev/null) +BUILD_TAGS_FILE := .build_tags ifeq ($(strip $(NOSTRIP)),y) STRIP_FLAG := -no-strip else ifeq ($(wildcard $(STRIP_PATH)),) @@ -47,7 +48,7 @@ dae: export CGO_ENABLED=0 endif dae: ebpf @echo $(CFLAGS) - go build -o $(OUTPUT) $(BUILD_ARGS) . + go build -tags=$(shell cat $(BUILD_TAGS_FILE)) -o $(OUTPUT) $(BUILD_ARGS) . ## End Dae Build ## Begin Git Submodules @@ -74,6 +75,8 @@ submodule submodules: $(submodule_paths) clean-ebpf: @rm -f control/bpf_bpf*.go && \ rm -f control/bpf_bpf*.o + @rm -f trace/bpf_bpf*.go && \ + rm -f trace/bpf_bpf*.o fmt: go fmt ./... @@ -82,10 +85,13 @@ ebpf: export BPF_CLANG := $(CLANG) ebpf: export BPF_STRIP_FLAG := $(STRIP_FLAG) ebpf: export BPF_CFLAGS := $(CFLAGS) ebpf: export BPF_TARGET := $(TARGET) +ebpf: export BPF_TRACE_TARGET := $(GOARCH) ebpf: submodule clean-ebpf @unset GOOS && \ unset GOARCH && \ unset GOARM && \ echo $(STRIP_FLAG) && \ - go generate ./control/control.go + go generate ./control/control.go && \ + go generate ./trace/trace.go && echo trace > $(BUILD_TAGS_FILE) || echo > $(BUILD_TAGS_FILE) + ## End Ebpf diff --git a/cmd/trace.go b/cmd/trace.go index 43802a9316..613c1ad269 100644 --- a/cmd/trace.go +++ b/cmd/trace.go @@ -1,3 +1,6 @@ +//go:build trace +// +build trace + /* * SPDX-License-Identifier: AGPL-3.0-only * Copyright (c) 2022-2024, daeuniverse Organization diff --git a/control/kern/headers b/control/kern/headers index d72c67ed8f..e4da1c9601 160000 --- a/control/kern/headers +++ b/control/kern/headers @@ -1 +1 @@ -Subproject commit d72c67ed8f5a7d11774b5cd88734e2ffe6847721 +Subproject commit e4da1c9601e1c3797d02c481a462b66588477495 diff --git a/go.mod b/go.mod index 365956cabe..cbdd1a4641 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/adrg/xdg v0.4.0 github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df github.com/bits-and-blooms/bloom/v3 v3.5.0 - github.com/cilium/ebpf v0.11.0 + github.com/cilium/ebpf v0.12.3 github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d github.com/daeuniverse/outbound v0.0.0-20240101085641-7932e7df927d github.com/daeuniverse/softwind v0.0.0-20231230065827-eed67f20d2c1 @@ -24,7 +24,7 @@ require ( github.com/x-cray/logrus-prefixed-formatter v0.5.2 golang.org/x/crypto v0.12.0 golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 - golang.org/x/sys v0.11.0 + golang.org/x/sys v0.14.1-0.20231108175955-e4099bfacb8c google.golang.org/protobuf v1.31.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) diff --git a/go.sum b/go.sum index 85bc2952ca..fd2620ee65 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/bits-and-blooms/bloom/v3 v3.5.0 h1:AKDvi1V3xJCmSR6QhcBfHbCN4Vf8FfxeWk github.com/bits-and-blooms/bloom/v3 v3.5.0/go.mod h1:Y8vrn7nk1tPIlmLtW2ZPV+W7StdVMor6bC1xgpjMZFs= github.com/cilium/ebpf v0.11.0 h1:V8gS/bTCCjX9uUnkUFUpPsksM8n1lXBAvHcpiFk1X2Y= github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUgWsVs= +github.com/cilium/ebpf v0.12.3 h1:8ht6F9MquybnY97at+VDZb3eQQr8ev79RueWeVaEcG4= +github.com/cilium/ebpf v0.12.3/go.mod h1:TctK1ivibvI3znr66ljgi4hqOT8EYQjz1KWBfb1UVgM= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d h1:hnC39MjR7xt5kZjrKlef7DXKFDkiX8MIcDXYC/6Jf9Q= github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d/go.mod h1:VGWGgv7pCP5WGyHGUyb9+nq/gW0yBm+i/GfCNATOJ1M= @@ -198,6 +200,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.1-0.20231108175955-e4099bfacb8c h1:3kC/TjQ+xzIblQv39bCOyRk8fbEeJcDHwbyxPUU2BpA= +golang.org/x/sys v0.14.1-0.20231108175955-e4099bfacb8c/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/trace/kern/headers b/trace/kern/headers index d72c67ed8f..e4da1c9601 160000 --- a/trace/kern/headers +++ b/trace/kern/headers @@ -1 +1 @@ -Subproject commit d72c67ed8f5a7d11774b5cd88734e2ffe6847721 +Subproject commit e4da1c9601e1c3797d02c481a462b66588477495