diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..62e22294e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,9 @@ +[env] +CC_aarch64_unknown_linux_musl = "aarch64-linux-musl-gcc" +CC_x86_64_unknown_linux_musl = "x86_64-linux-musl-gcc" + +# Zydis CMake config requires a C++ compiler for the test cases but the musl +# toolchain doesn't have one. We simply force the compiler to `g++` here to +# trick CMake into passing the check for a C++ compiler: it isn't actually +# used anyway. +TARGET_CXX = "g++" diff --git a/.github/workflows/env/action.yml b/.github/workflows/env/action.yml index 983601bd8..3b15d1408 100644 --- a/.github/workflows/env/action.yml +++ b/.github/workflows/env/action.yml @@ -28,10 +28,29 @@ runs: sudo apt-get update -y sudo apt-get install -y curl unzip gcc-aarch64-linux-gnu \ - libc6-arm64-cross qemu-user-binfmt libc6:arm64 + libc6-arm64-cross qemu-user-binfmt libc6:arm64 \ + musl-dev:amd64 musl-dev:arm64 musl-tools binutils-aarch64-linux-gnu - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod cache-dependency-path: go.sum id: go + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-unknown-linux-musl,aarch64-unknown-linux-musl + toolchain: 1.77 + - name: Install protoc + shell: bash + env: + PB_URL: "https://github.com/protocolbuffers/protobuf/releases/download/v24.4/" + PB_FILE: "protoc-24.4-linux-x86_64.zip" + INSTALL_DIR: "/usr/local" + run: | + wget -nv "$PB_URL/$PB_FILE" + sudo unzip "$PB_FILE" -d "$INSTALL_DIR" 'bin/*' 'include/*' + sudo chmod +xr "$INSTALL_DIR/bin/protoc" + sudo find "$INSTALL_DIR/include" -type d -exec chmod +x {} \; + sudo find "$INSTALL_DIR/include" -type f -exec chmod +r {} \; + rm "$PB_FILE" diff --git a/.github/workflows/push-docker-image.yml b/.github/workflows/push-docker-image.yml index 451990bc3..2e47aca8d 100644 --- a/.github/workflows/push-docker-image.yml +++ b/.github/workflows/push-docker-image.yml @@ -12,8 +12,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up environment - uses: ./.github/workflows/env - name: Login to Docker Hub uses: docker/login-action@v3 with: diff --git a/.github/workflows/unit-test-on-pull-request.yml b/.github/workflows/unit-test-on-pull-request.yml index b76864395..b42b3fb60 100644 --- a/.github/workflows/unit-test-on-pull-request.yml +++ b/.github/workflows/unit-test-on-pull-request.yml @@ -69,33 +69,11 @@ jobs: restore-keys: | coredumps-${{ matrix.target_arch }} coredumps- + - name: Direct Rust test + run: make rust-tests - name: Tests run: make test TARGET_ARCH=${{ matrix.target_arch }} - test-rust: - name: Test rust components - runs-on: ubuntu-24.04 - steps: - - name: Clone code - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - name: Install protoc - env: - PB_URL: "https://github.com/protocolbuffers/protobuf/releases/download/v24.4/" - PB_FILE: "protoc-24.4-linux-x86_64.zip" - INSTALL_DIR: "/usr/local" - run: | - wget -q "$PB_URL/$PB_FILE" - sudo unzip "$PB_FILE" -d "$INSTALL_DIR" 'bin/*' 'include/*' - sudo chmod +xr "$INSTALL_DIR/bin/protoc" - sudo find "$INSTALL_DIR/include" -type d -exec chmod +x {} \; - sudo find "$INSTALL_DIR/include" -type f -exec chmod +r {} \; - rm "$PB_FILE" - - name: Tests - run: | - cargo test - check-ebpf-blobs: name: Check for differences in the eBPF binary blobs runs-on: ubuntu-24.04 diff --git a/Dockerfile b/Dockerfile index ad50a242e..3ff4ec6f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN cross_debian_arch=$(uname -m | sed -e 's/aarch64/amd64/' -e 's/x86_64/arm64 cross_pkg_arch=$(uname -m | sed -e 's/aarch64/x86-64/' -e 's/x86_64/aarch64/'); \ apt-get update -y && \ apt-get dist-upgrade -y && \ - apt-get install -y wget make git clang-17 unzip libc6-dev g++ gcc pkgconf \ + apt-get install -y curl wget make git clang-17 unzip libc6-dev g++ gcc pkgconf \ gcc-${cross_pkg_arch}-linux-gnu libc6-${cross_debian_arch}-cross && \ apt-get clean autoclean && \ apt-get autoremove --yes @@ -33,7 +33,7 @@ RUN PB_FILE="protoc-24.4-linux-x86_64.zip"; \ INSTALL_DIR="/usr/local"; \ \ - wget -q "$PB_URL/$PB_FILE" \ + wget -nv "$PB_URL/$PB_FILE" \ && unzip "$PB_FILE" -d "$INSTALL_DIR" 'bin/*' 'include/*' \ && chmod +xr "$INSTALL_DIR/bin/protoc" \ && find "$INSTALL_DIR/include" -type d -exec chmod +x {} \; \ @@ -43,4 +43,13 @@ RUN # Append to /etc/profile for login shells RUN echo 'export PATH="/usr/local/go/bin:$PATH"' >> /etc/profile +# Create .cargo directory +RUN mkdir -p /root/.cargo + +# Install rustup and cargo +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.77 + +# Add cargo to PATH +RUN echo 'export PATH="/root/.cargo/bin:$PATH"' >> /etc/profile + ENTRYPOINT ["/bin/bash", "-l", "-c"] diff --git a/Makefile b/Makefile index a3812803c..fb2e41135 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all all-common clean ebpf generate test test-deps protobuf docker-image agent legal \ integration-test-binaries codespell lint linter-version debug debug-agent ebpf-profiler \ - format-ebpf + format-ebpf rust-components rust-targets rust-tests vanity-import-check vanity-import-fix SHELL := /usr/bin/env bash @@ -73,9 +73,26 @@ generate: ebpf: generate $(MAKE) $(EBPF_FLAGS) -C support/ebpf -ebpf-profiler: generate ebpf +ebpf-profiler: generate ebpf rust-components go build $(GO_FLAGS) -tags $(GO_TAGS) +rust-targets: +ifeq ($(TARGET_ARCH),arm64) + rustup target add aarch64-unknown-linux-musl +else ifeq ($(TARGET_ARCH),amd64) + rustup target add x86_64-unknown-linux-musl +endif + +rust-components: rust-targets +ifeq ($(TARGET_ARCH),arm64) + cargo build --lib --release --target aarch64-unknown-linux-musl +else ifeq ($(TARGET_ARCH),amd64) + cargo build --lib --release --target x86_64-unknown-linux-musl +endif + +rust-tests: rust-targets + cargo test + GOLANGCI_LINT_VERSION = "v1.63.4" lint: generate vanity-import-check $(MAKE) lint -C support/ebpf @@ -88,12 +105,10 @@ format-ebpf: linter-version: @echo $(GOLANGCI_LINT_VERSION) -.PHONY: vanity-import-check vanity-import-check: @go install github.com/jcchavezs/porto/cmd/porto@latest @porto --include-internal -l . || ( echo "(run: make vanity-import-fix)"; exit 1 ) -.PHONY: vanity-import-fix vanity-import-fix: $(PORTO) @go install github.com/jcchavezs/porto/cmd/porto@latest @porto --include-internal -w .