Skip to content

Commit

Permalink
fix build + make build static + create release on github (#86)
Browse files Browse the repository at this point in the history
Summary:
**What:**

Making dnswatch build great again

**Why:**

Broken builds are sad

**How:**

Makefile magic 🎩
**Risks:**

**Checklist**:

<!--
Have you done all of these things?
To check an item, place an "x" in the box like so: "- [x] Tests"
Add "N/A" to the end of each line that's irrelevant to your changes
-->

- [ ] Added tests, if you've added code that should be tested
- [ ] Updated the documentation, if you've changed APIs
- [x] Ensured the test suite passes
- [x] Made sure your code lints
- [x] Completed the Contributor License Agreement ("CLA")

Pull Request resolved: #86

Reviewed By: leoleovich

Differential Revision: D66815782

Pulled By: deathowl

fbshipit-source-id: da69cbdb7a4eee8413f87d20100e59fb32f1ab74
  • Loading branch information
deathowl authored and facebook-github-bot committed Dec 5, 2024
1 parent 81bc7c3 commit 1919034
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint_dnswatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
with:
go-version: 1.22.3
- name: "Install deps"
run: sudo apt-get update; sudo apt-get install -y libpcap0.8 libpcap0.8-dev make clang gcc-multilib libbpfcc-dev
run: sudo apt-get update; sudo apt-get install -y make clang gcc-multilib libsystemd-dev libcap-dev libpcap-dev
- name: "Install libbpf-1"
run: sudo bash .github/scripts/install_libbpf1.sh
- name: "Build all"
run: cd dnswatch; make
run: cd dnswatch; git submodule update --init --recursive; make
- name: "Run linter"
run: cd dnswatch; make lint
run: cd dnswatch; git submodule update --init --recursive; make lint
39 changes: 39 additions & 0 deletions .github/workflows/release_dnswatch_on_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release dnswatch binary
on: push


jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22.3
- name: "Install deps"
run: sudo apt-get update; sudo apt-get install -y make clang gcc-multilib libsystemd-dev libcap-dev libpcap-dev
- name: "Install libbpf-1"
run: sudo bash .github/scripts/install_libbpf1.sh
- name: "Build all"
run: cd dnswatch; git submodule update --init --recursive; make
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Release snapshot
id: release-snapshot
uses: actions/create-release@latest
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.date.outputs.date }}
release_name: ${{ steps.date.outputs.date }}
draft: false
prerelease: false
- name: Release
uses: softprops/action-gh-release@v2
if: github.ref == 'refs/heads/main'
with:
files: dnswatch/dnswatch
tag_name: ${{ steps.date.outputs.date }}
6 changes: 3 additions & 3 deletions .github/workflows/test_dnswatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
with:
go-version: 1.22.3
- name: "Install deps"
run: sudo apt-get update; sudo apt-get install -y libpcap0.8 libpcap0.8-dev make clang gcc-multilib libbpfcc-dev
run: sudo apt-get update; sudo apt-get install -y make clang gcc-multilib libsystemd-dev libcap-dev libpcap-dev
- name: "Install libbpf-1"
run: sudo bash .github/scripts/install_libbpf1.sh
- name: "Build all"
run: cd dnswatch; make
run: cd dnswatch; git submodule update --init --recursive; make
- name: Test
run: cd dnswatch; make test
run: cd dnswatch; git submodule update --init --recursive; make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dnswatch/blazesym"]
path = dnswatch/blazesym
url = https://github.com/libbpf/blazesym.git
1 change: 1 addition & 0 deletions dnswatch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blazesym_c.syso
19 changes: 13 additions & 6 deletions dnswatch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ SHELL := /bin/bash
all: build
.PHONY: all

LIBBLAZESYM_SRC := $(abspath ./blazesym/)
LIBBLAZESYM_INC := $(abspath $(LIBBLAZESYM_SRC)/capi/include)
LIBBLAZESYM_OBJ := $(abspath $(LIBBLAZESYM_SRC)/target/release/libblazesym_c.a)
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
bpf/vmlinux.h:
@which bpftool > /dev/null
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@
$(LIBBLAZESYM_SRC)/target/release/libblazesym_c.a::
$(Q)cd $(LIBBLAZESYM_SRC) && cargo build --package=blazesym-c --release
snoop/out/dnswatch_bpf_probe_core.o: bpf/vmlinux.h
clang -g -O2 -Wall -fpie -fno-stack-protector -I /usr/include/bpf -target bpf -D__TARGET_ARCH_x86 -I bpf -c bpf/dnswatch.bpf.c -o $@
build: snoop/out/dnswatch_bpf_probe_core.o
CGO_LDFLAGS="-lbpf -lbcc" CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/bcc -I /usr/include/pcap" go build .
test: snoop/out/dnswatch_bpf_probe_core.o
CGO_LDFLAGS="-lbpf -lbcc" CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/bcc -I /usr/include/pcap" go test -v -coverprofile=coverage.txt -covermode=atomic ./...
build: snoop/out/dnswatch_bpf_probe_core.o $(LIBBLAZESYM_SRC)/target/release/libblazesym_c.a
CGO_LDFLAGS=" -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release) -lsystemd -lcap -lblazesym_c -libverbs -lnl-route-3 -lnl-3 -lzstd -lbpf -ldbus-1 -static " CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/pcap -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release)" go build .
test: snoop/out/dnswatch_bpf_probe_core.o $(LIBBLAZESYM_SRC)/target/release/libblazesym_c.a
CGO_LDFLAGS=" -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release) -lsystemd -lcap -lblazesym_c -libverbs -lnl-route-3 -lnl-3 -lzstd -lbpf -ldbus-1 -static " CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/pcap -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release)" go test -v -coverprofile=coverage.txt -covermode=atomic ./...
install_linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ~
lint: snoop/out/dnswatch_bpf_probe_core.o install_linter
CGO_LDFLAGS="-lbpf -lbcc" CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/bcc -I /usr/include/pcap" ~/golangci-lint run -v ./...
lint: snoop/out/dnswatch_bpf_probe_core.o install_linter $(LIBBLAZESYM_SRC)/target/release/libblazesym_c.a
CGO_LDFLAGS=" -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release) -lsystemd -lcap -lblazesym_c -libverbs -lnl-route-3 -lnl-3 -lzstd -lbpf -ldbus-1 -static " CGO_CFLAGS="-I /usr/include/bpf -I /usr/include/pcap -I $(LIBBLAZESYM_INC) -L /usr/lib -L $(abspath $(LIBBLAZESYM_SRC)/target/release)" ~/golangci-lint run -v ./...
clean:
rm -f snoop/out/dnswatch_bpf_probe_core.o
rm -f bpf/vmlinux.h
rm -rf $(LIBBLAZESYM_OBJ)
1 change: 1 addition & 0 deletions dnswatch/blazesym
Submodule blazesym added at ee7ead
4 changes: 2 additions & 2 deletions dnswatch/snoop/blazesym/blazesym.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package blazesym

/*
// @fb-only: #include "blazesym/blazesym.h" // @manual=fbsource//third-party/rust:blazesym-c-cxx
#include "blazesym_c/blazesym_c.h" // @oss-only
#include "blazesym.h" // @oss-only
// HACK
// The generated struct in cgo does not contain syms for blazesym result
// see:
Expand Down Expand Up @@ -86,7 +86,7 @@ type Symbol struct {
}

// UnknownSymbol returns a symbol representing an unknown symbol.
var UnknownSymbol Symbol = Symbol{Name: unknownSymbol}
var UnknownSymbol = Symbol{Name: unknownSymbol}

func stackToPtr(stack []uint64) (*C.uint64_t, C.size_t) {
var result *C.uint64_t
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ github.com/Azure/go-autorest/autorest/to v0.2.0/go.mod h1:GunWKJp1AEqgMaGLV+iocm
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/DataDog/appsec-internal-go v1.5.0/go.mod h1:pEp8gjfNLtEOmz+iZqC8bXhu0h4k7NUsW/qiQb34k1U=
github.com/DataDog/datadog-agent/pkg/obfuscate v0.48.0/go.mod h1:HzySONXnAgSmIQfL6gOv9hWprKJkx8CicuXuUbmgWfo=
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.1/go.mod h1:Vc+snp0Bey4MrrJyiV2tVxxJb6BmLomPvN1RgAvjGaQ=
github.com/DataDog/datadog-go/v5 v5.3.0/go.mod h1:XRDJk1pTc00gm+ZDiBKsjh7oOOtJfYfglVCmFb8C2+Q=
github.com/DataDog/go-libddwaf/v2 v2.3.2/go.mod h1:gsCdoijYQfj8ce/T2bEDNPZFIYnmHluAgVDpuQOWMZE=
Expand Down

0 comments on commit 1919034

Please sign in to comment.