Skip to content

Commit

Permalink
make build supports selectively compiling some of the binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
adam committed Sep 26, 2024
1 parent d29ceb0 commit d43075c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 42 deletions.
46 changes: 15 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,35 @@ all:

$(QUIET) $(GO) generate bpf/kmesh/bpf2go/bpf2go.go

$(call printlog, BUILD, "kernel")
$(QUIET) make -C kernel/ko_src

$(QUIET) $(foreach app,$(BINARIES),$(call build_app,$(app));)

build_app_daemon:
$(call printlog, BUILD, $(APPS1))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)

$(call printlog, BUILD, "kernel")
$(QUIET) make -C kernel/ko_src

build_app_mdacore:
$(call printlog, BUILD, $(APPS2))
$(QUIET) cd oncn-mda && cmake . -B build && make -C build

build_app_cni:
$(call printlog, BUILD, $(APPS3))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)

build_app_ctl:
$(call printlog, BUILD, $(APPS4))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -o $(APPS4) $(GOFLAGS) ./ctl/main.go)

define build_app
$(if $(filter $1,$(BINARIES)),$(call build_$1))
endef


.PHONY: gen-proto
gen-proto:
$(QUIET) make -C api gen-proto
Expand Down Expand Up @@ -155,34 +166,7 @@ uninstall:

.PHONY: build
build:
VERSION=$(VERSION) ./kmesh_compile.sh

# Build kmesh-daemon if included in BINARIES
$(QUIET) ifneq ($(filter kmesh-daemon,$(BINARIES)),)
$(call printlog, BUILD, $(APPS1))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)
$(QUIET) endif

# Build mdacore if included in BINARIES
$(QUIET) ifneq ($(filter mdacore,$(BINARIES)),)
$(call printlog, BUILD, $(APPS2))
$(QUIET) cd oncn-mda && cmake . -B build && make -C build
$(QUIET) endif

# Build kmesh-cni if included in BINARIES
$(QUIET) ifneq ($(filter kmesh-cni,$(BINARIES)),)
$(call printlog, BUILD, $(APPS3))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)
$(QUIET) endif

# Build kmeshctl if included in BINARIES
$(QUIET) ifneq ($(filter kmeshctl,$(BINARIES)),)
$(call printlog, BUILD, $(APPS4))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -o $(APPS4) $(GOFLAGS) ./ctl/main.go)
$(QUIET) endif
VERSION=$(VERSION) BINARIES=$(BINARIES) ./kmesh_compile.sh

.PHONY: docker
docker: build
Expand Down
18 changes: 9 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function bpf_compile_range_adjust() {
}

function set_enhanced_kernel_env() {
# we use /usr/include/linux/bpf.h to determine the runtime environment’s
# support for kmesh. Considering the case of online image compilation, a
# we use /usr/include/linux/bpf.h to determine the runtime environment’s
# support for kmesh. Considering the case of online image compilation, a
# variable KERNEL_HEADER_LINUX_BPF is used here to specify the path of the
# source of macro definition.
# When using an online compiled image, /usr/include/linux/bpf.h in host
# machine will be mounted to config/linux-bpf.h.
# Otherwise, /usr/include/linux/bpf.h from the current compilation
# source of macro definition.
# When using an online compiled image, /usr/include/linux/bpf.h in host
# machine will be mounted to config/linux-bpf.h.
# Otherwise, /usr/include/linux/bpf.h from the current compilation
# environment will be obtained
export KERNEL_HEADER_LINUX_BPF=$ROOT_DIR/config/linux-bpf.h
if [ ! -f "$KERNEL_HEADER_LINUX_BPF" ]; then
Expand All @@ -46,8 +46,8 @@ function prepare() {
export C_INCLUDE_PATH=/usr/include/aarch64-linux-gnu:$C_INCLUDE_PATH
fi
export EXTRA_GOFLAGS="-gcflags=\"-N -l\" -buildmode=pie"
export EXTRA_CFLAGS="-O0 -g"
export EXTRA_CFLAGS="-O0 -g"

bpf_compile_range_adjust
}

Expand Down Expand Up @@ -93,7 +93,7 @@ fi

if [ -z "$1" -o "$1" == "-b" -o "$1" == "--build" ]; then
prepare
make
make BINARIES="$BINARIES"
exit
fi

Expand Down
3 changes: 2 additions & 1 deletion hack/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ function get_arch() {

function build_kmesh() {
local container_id=$1
local binaries=$2
docker exec $container_id git config --global --add safe.directory /kmesh
docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh
docker exec -e VERSION=$VERSION -e BINARIES="$binaries" $container_id sh /kmesh/build.sh
docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh -i
docker exec $container_id sh -c "$(declare -f copy_to_host); copy_to_host"
}
Expand Down
2 changes: 1 addition & 1 deletion kmesh_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
. $ROOT_DIR/hack/utils.sh

container_id=$(run_docker_container)
build_kmesh $container_id
build_kmesh $container_id $BINARIES
clean_container $container_id

sudo chmod -R a+r out/

0 comments on commit d43075c

Please sign in to comment.