Skip to content

Commit

Permalink
chore(ci): install scx dep in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 committed Feb 24, 2025
1 parent 4d42505 commit 8497876
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 5 deletions.
5 changes: 1 addition & 4 deletions selftest/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ 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 /lib/modules/$(shell uname -r)/build/tools/sched_ext/include/scx -I /lib/modules/$(shell uname -r)/build/tools/sched_ext/include/bpf-compat

CGO_CFLAGS_DYN = "-I. -I/usr/include/"
CGO_LDFLAGS_DYN = "$(shell $(PKGCONFIG) --shared --libs libbpf)"
Expand Down Expand Up @@ -55,7 +52,7 @@ outputdir:
## test bpf dependency

$(MAIN).bpf.o: $(MAIN).bpf.c
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) $(SCX_FLAGS) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@

## test

Expand Down
1 change: 1 addition & 0 deletions selftest/common/vmlinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ struct task_struct {
pid_t tgid;
struct task_struct *parent;
struct sched_ext_entity scx;
short unsigned int migration_disabled;
char comm[16];
};

Expand Down
1 change: 1 addition & 0 deletions selftest/struct-ops/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scx
1 change: 0 additions & 1 deletion selftest/struct-ops/Makefile

This file was deleted.

100 changes: 100 additions & 0 deletions selftest/struct-ops/Makefile
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

0 comments on commit 8497876

Please sign in to comment.