diff --git a/Xargo.toml b/Xargo.toml new file mode 100644 index 00000000000000..475fb71ed15ac2 --- /dev/null +++ b/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] diff --git a/cargo-build-bpf b/cargo-build-bpf new file mode 100755 index 00000000000000..62f037236604e8 --- /dev/null +++ b/cargo-build-bpf @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +usage() { + cat </dev/null; echo Success; } diff --git a/sdk/bpf/rust/xargo-build.sh b/sdk/bpf/rust/xargo-build.sh new file mode 100755 index 00000000000000..4b26f0c98e8264 --- /dev/null +++ b/sdk/bpf/rust/xargo-build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +bpf_sdk=$(cd "$(dirname "$0")/.." && pwd) +# shellcheck source=sdk/bpf/env.sh +source "$bpf_sdk"/env.sh +set -x +exec "$XARGO" build --target "$XARGO_TARGET" --release "$@" diff --git a/sdk/bpf/scripts/dump.sh b/sdk/bpf/scripts/dump.sh new file mode 100755 index 00000000000000..47ea7e9aeb1002 --- /dev/null +++ b/sdk/bpf/scripts/dump.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +bpf_sdk=$(cd "$(dirname "$0")/.." && pwd) +# shellcheck source=sdk/bpf/env.sh +source "$bpf_sdk"/env.sh + +so="$1" +if [[ -z $so ]]; then + echo "Usage: $0 bpf-program.so" + exit 1 +fi + +if [[ ! -r $so ]]; then + echo "Error: File not found or readable: $so" + exit 1 +fi + +if ! command -v rustfilt > /dev/null; then + echo "Error: rustfilt not found. It can be installed by running: cargo install rustfilt" + exit 1 +fi +if ! command -v readelf > /dev/null; then + if [[ $(uname) = Darwin ]]; then + echo "Error: readelf not found. It can be installed by running: brew install binutils" + else + echo "Error: readelf not found." + fi + exit 1 +fi + +dump="${so%.*}"_dump.txt +dump_mangled=$(basename "$so")_dump-mangled.txt + +( + set -ex + ls -la "$so" > "$dump_mangled" + readelf -aW "$so" >>"$dump_mangled" + "$OBJDUMP" -print-imm-hex --source --disassemble "$so" >> "$dump_mangled" + sed s/://g < "$dump_mangled" | rustfilt > "$dump" +) +rm -f "$dump_mangled" + +if [[ ! -f "$dump" ]]; then + echo "Error: Failed to create $dump" + exit 1 +fi + +echo "Created $dump" diff --git a/sdk/bpf/scripts/install.sh b/sdk/bpf/scripts/install.sh index 41a7bb158c6afc..e7cd6b889fb39b 100755 --- a/sdk/bpf/scripts/install.sh +++ b/sdk/bpf/scripts/install.sh @@ -84,19 +84,25 @@ clone() { } # Install xargo -( - set -ex - # shellcheck disable=SC2154 - if [[ -n $rust_stable ]]; then - cargo +"$rust_stable" install xargo - else - cargo install xargo +version=0.3.22 +if [[ ! -e xargo-$version.md ]]; then + ( + args=() + # shellcheck disable=SC2154 + if [[ -n $rust_stable ]]; then + args+=(+"$rust_stable") + fi + args+=(install xargo --version "$version" --root xargo) + set -ex + cargo "${args[@]}" + xargo --version >xargo-$version.md 2>&1 + ) + exitcode=$? + # shellcheck disable=SC2181 + if [[ $exitcode -ne 0 ]]; then + rm -rf xargo-$version.md + exit 1 fi - xargo --version >xargo.md 2>&1 -) -# shellcheck disable=SC2181 -if [[ $? -ne 0 ]]; then - exit 1 fi # Install Criterion diff --git a/sdk/bpf/scripts/objcopy.sh b/sdk/bpf/scripts/objcopy.sh new file mode 100755 index 00000000000000..1e44719e77724f --- /dev/null +++ b/sdk/bpf/scripts/objcopy.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +bpf_sdk=$(cd "$(dirname "$0")/.." && pwd) +# shellcheck source=sdk/bpf/env.sh +source "$bpf_sdk"/env.sh +exec "$bpf_sdk"/dependencies/llvm-native/bin/llvm-objcopy "$@"