Skip to content

Commit

Permalink
Update llvm script and move test to make
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Anh Duong <anh.duong@kyber.network>
  • Loading branch information
vietanhduong committed Dec 26, 2023
1 parent 6b4fa93 commit c998482
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ jobs:
sudo docker cp "$ID:/usr/local/bin/clang-amd64" /usr/local/bin
sudo docker cp "$ID:/usr/local/bin/clang-arm64" /usr/local/bin
docker rm $ID
ls -lah /usr/local/bin/clang*
- name: Run Test
run: |
sudo apt-get install -y make
TEST_CC=$(which clang) go test ./... -v -exec=sudo -count=1
- name: Build examples
run: make -C examples CC=$(which clang) BUILD_BPF=1 build-all
sudo apt-get install -y make && \
make test &&
make build-examples
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SHELL = /usr/bin/env bash
DOCKER ?= docker
GO ?= go

CLANG ?= $$(which clang)
LLVM_VERSION = 15.0.7

IMAGE_REPO = ghcr.io/vietanhduong
Expand All @@ -11,8 +13,13 @@ CURRENT_SHORT_COMMIT = $$(git rev-parse --short HEAD)

.PHONY: build-examples
build-examples:
make -C examples build-all
make -C examples CC=$(CLANG) BUILD_BPF=1 build-all

.PHONY: test
test:
sudo TEST_CC=$(CLANG) $(GO) test ./... -v -count=1

## DOCKER
.PHONY: push-llvm
push-llvm: build-llvm
$(DOCKER) push $(LLVM_IMAGE):$(LLVM_VERSION)
Expand Down
5 changes: 5 additions & 0 deletions compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/vietanhduong/wbpf"
)

func Test_Compile(t *testing.T) {
Expand Down Expand Up @@ -71,6 +72,10 @@ func Test_Compile(t *testing.T) {
require.Nil(t, err)
require.False(t, info.IsDir())
require.NotZero(t, info.Size())

mod, err := wbpf.NewModule(wbpf.WithElfFile(output))
require.NoError(t, err, "Failed to new wbpf module")
mod.Close()
})
}
}
15 changes: 5 additions & 10 deletions docker/llvm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ FROM ubuntu:22.04 as builder
ARG LLVM_VERSION=15.0.7
ENV LLVM_VERSION=${LLVM_VERSION}

COPY install_deps.sh /install_deps.sh
COPY *.sh /

RUN /install_deps.sh

COPY build_llvm_native.sh /build_llvm_native.sh

RUN /build_llvm_native.sh

COPY build_llvm_cross_aarch64.sh /build_llvm_cross_aarch64.sh

RUN /build_llvm_cross_aarch64.sh
RUN /install_deps.sh && \
/download_llvm.sh && \
/build_llvm_native.sh \
/build_llvm_cross_aarch64.sh

FROM ubuntu:22.04 as rootfs

Expand Down
6 changes: 1 addition & 5 deletions docker/llvm/build_llvm_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ set -o errexit
set -o pipefail
set -o nounset

mkdir -p /src/llvm/llvm/build-native &&
curl -sSL "https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${LLVM_VERSION}.tar.gz" |
tar -xzf - --strip-components=1 -C /src/llvm

cd /src/llvm/llvm/build-native
mkdir -p /src/llvm/llvm/build-native && cd $_

cmake .. -G "Ninja" \
-DLLVM_TARGETS_TO_BUILD="BPF" \
Expand Down
12 changes: 12 additions & 0 deletions docker/llvm/download_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -o xtrace
set -o errexit
set -o pipefail
set -o nounset

LLVM_SRC=/src/llvm

mkdir -p $LLVM_SRC &&
curl -sSL "https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${LLVM_VERSION}.tar.gz" |
tar -xzf - --strip-components=1 -C $LLVM_SRC
Binary file modified examples/kprobe/kprobe.bpf.o
Binary file not shown.

0 comments on commit c998482

Please sign in to comment.