-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): install scx dep in Makefile
- Loading branch information
1 parent
4d42505
commit 8497876
Showing
4 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scx |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
BASEDIR = $(abspath ../../) | ||
|
||
OUTPUT = ../../output | ||
|
||
LIBBPF_SRC = $(abspath ../../libbpf/src) | ||
LIBBPF_OBJ = $(abspath $(OUTPUT)/libbpf.a) | ||
|
||
CLANG = clang | ||
CC = $(CLANG) | ||
GO = go | ||
PKGCONFIG = pkg-config | ||
|
||
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g') | ||
|
||
# libbpf | ||
|
||
LIBBPF_OBJDIR = $(abspath ./$(OUTPUT)/libbpf) | ||
|
||
CFLAGS = -g -O2 -Wall -fpie -I$(abspath ../common) | ||
LDFLAGS = | ||
|
||
CGO_CFLAGS_STATIC = "-I$(abspath $(OUTPUT)) -I$(abspath ../common)" | ||
CGO_LDFLAGS_STATIC = "$(shell PKG_CONFIG_PATH=$(LIBBPF_OBJDIR) $(PKGCONFIG) --static --libs libbpf)" | ||
CGO_EXTLDFLAGS_STATIC = '-w -extldflags "-static"' | ||
SCX_FLAGS=-mcpu=v3 -mlittle-endian \ | ||
-I ../../libbpf/src/usr/include -I ../../libbpf/include/uapi \ | ||
-I scx/scheds/include/scx -I scx/scheds/include/bpf-compat | ||
|
||
CGO_CFLAGS_DYN = "-I. -I/usr/include/" | ||
CGO_LDFLAGS_DYN = "$(shell $(PKGCONFIG) --shared --libs libbpf)" | ||
|
||
MAIN = main | ||
|
||
.PHONY: $(MAIN) | ||
.PHONY: $(MAIN).go | ||
.PHONY: $(MAIN).bpf.c | ||
|
||
all: $(MAIN)-static | ||
|
||
.PHONY: libbpfgo | ||
.PHONY: libbpfgo-static | ||
.PHONY: libbpfgo-dynamic | ||
|
||
## libbpfgo | ||
|
||
libbpfgo-static: | ||
$(MAKE) -C $(BASEDIR) libbpfgo-static | ||
|
||
libbpfgo-dynamic: | ||
$(MAKE) -C $(BASEDIR) libbpfgo-dynamic | ||
|
||
outputdir: | ||
$(MAKE) -C $(BASEDIR) outputdir | ||
|
||
## test bpf dependency | ||
|
||
$(MAIN).bpf.o: $(MAIN).bpf.c | ||
@if [ ! -d "scx" ]; then \ | ||
git clone -b v1.0.9 https://github.com/sched-ext/scx.git; \ | ||
else \ | ||
echo "scx directory already exists, skipping clone"; \ | ||
fi | ||
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) $(SCX_FLAGS) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@ | ||
|
||
## test | ||
|
||
.PHONY: $(MAIN)-static | ||
.PHONY: $(MAIN)-dynamic | ||
|
||
$(MAIN)-static: libbpfgo-static | $(MAIN).bpf.o | ||
CC=$(CLANG) \ | ||
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \ | ||
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \ | ||
GOOS=linux GOARCH=$(ARCH) \ | ||
$(GO) build \ | ||
-tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \ | ||
-o $(MAIN)-static ./$(MAIN).go | ||
|
||
$(MAIN)-dynamic: libbpfgo-dynamic | $(MAIN).bpf.o | ||
CC=$(CLANG) \ | ||
CGO_CFLAGS=$(CGO_CFLAGS_DYN) \ | ||
CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \ | ||
$(GO) build -o ./$(MAIN)-dynamic ./$(MAIN).go | ||
|
||
## run | ||
|
||
.PHONY: run | ||
.PHONY: run-static | ||
.PHONY: run-dynamic | ||
|
||
run: run-static | ||
|
||
run-static: $(MAIN)-static | ||
sudo ./run.sh $(MAIN)-static | ||
|
||
run-dynamic: $(MAIN)-dynamic | ||
sudo ./run.sh $(MAIN)-dynamic | ||
|
||
clean: | ||
rm -f *.o *-static *-dynamic |