Skip to content

Commit

Permalink
Merge branch 'master' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechou committed Jul 23, 2024
2 parents 140a194 + 6fff5b7 commit d2efa54
Show file tree
Hide file tree
Showing 87 changed files with 2,504 additions and 2,101 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: Consecutive
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLines
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ name: test
on: [push, pull_request]
jobs:

# style-check:
# runs-on: ubuntu-24.04
# steps:
# - uses: actions/checkout@v3
# - run: sudo apt install clang-format yapf3
# - run: ./scripts/style.sh

tests:
# needs: style-check
runs-on: ubuntu-24.04
strategy:
matrix:
Expand All @@ -25,11 +17,7 @@ jobs:
with:
submodules: 'recursive'
- run: ./depends/setup.sh
- run: ./scripts/style.sh
- run: ./scripts/configure.sh -d -t --${{ matrix.cc }}
- run: ./scripts/build.sh
- run: ./scripts/test.sh
# - if: matrix.cc == 'gcc'
# uses: codecov/codecov-action@v3
# with:
# gcov: true
# gcov_args: '-l'
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[submodule "vcpkg"]
path = depends/vcpkg
url = https://github.com/microsoft/vcpkg.git
ignore = dirty
[submodule "libnet"]
path = third_party/libnet/libnet
url = https://github.com/libnet/libnet.git
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(VECTORSZ 4000 CACHE STRING "Memory allocation for spin state vector")
include("CheckTypeSize")
check_type_size("void *" SIZEOF_VOID_P)
check_type_size("int" SIZEOF_INT)
add_compile_options(-Wall -Wextra -Werror)
add_compile_options(-Wall -Wextra -Werror -O2)

#
# release/debug compile flags
Expand All @@ -63,7 +63,7 @@ add_subdirectory(third_party/bpftool EXCLUDE_FROM_ALL)
add_subdirectory(third_party/libbpf EXCLUDE_FROM_ALL)
add_subdirectory(third_party/libnet EXCLUDE_FROM_ALL)
find_package(boost_program_options CONFIG REQUIRED)
find_package(boost_stacktrace_addr2line CONFIG REQUIRED)
find_package(boost_stacktrace_backtrace CONFIG REQUIRED)
find_package(boost_stacktrace_basic CONFIG REQUIRED)
find_package(boost_stacktrace_noop CONFIG REQUIRED)
find_package(BpfObject REQUIRED)
Expand All @@ -80,10 +80,14 @@ find_package(ZLIB REQUIRED) # required by `FindBpfObject.cmake`

#
# stacktrace
# https://www.boost.org/doc/libs/master/doc/html/stacktrace/configuration_and_build.html
#
add_library(stacktrace_config INTERFACE)
target_compile_definitions(stacktrace_config INTERFACE BOOST_STACKTRACE_LINK)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_addr2line dl)
# libbacktrace is already linked statically with Boost::stacktrace_backtrace
# through our patched vcpkg, so `-lbacktrace` is not needed.
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_backtrace dl)
else()
target_link_libraries(stacktrace_config INTERFACE Boost::stacktrace_noop)
endif()
Expand Down
4 changes: 2 additions & 2 deletions depends/neo-dev/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ depends=(base-devel curl git clang yapf elfutils libelf zlib binutils libcap
autoconf automake libtool
zip unzip # utils required by vcpkg
linux-headers # openssl
glibc # libpthread
gcc gcc-libs # libstdc++
glibc # libpthread
gcc gcc-libs # libstdc++
libnl docker spin-git)
makedepends=()
checkdepends=()
Expand Down
136 changes: 95 additions & 41 deletions depends/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,47 @@ die() {
exit 1
}

[ $UID -eq 0 ] && die 'Please run this script without root privilege'
if [[ $UID -eq 0 ]]; then
die 'Please run this script without root privilege'
fi

#
# Output a short name of the Linux distribution
# Output a short name (v:DISTRO) of the Linux distribution
#
get_distro() {
export DISTRO

if test -f /etc/os-release; then # freedesktop.org and systemd
. /etc/os-release
echo "$NAME" | cut -f 1 -d ' ' | tr '[:upper:]' '[:lower:]'
source /etc/os-release
DISTRO="$(echo "$NAME" | cut -f 1 -d ' ' | tr '[:upper:]' '[:lower:]')"
elif type lsb_release >/dev/null 2>&1; then # linuxbase.org
lsb_release -si | tr '[:upper:]' '[:lower:]'
DISTRO="$(lsb_release -si | tr '[:upper:]' '[:lower:]')"
elif test -f /etc/lsb-release; then
# shellcheck source=/dev/null
source /etc/lsb-release
echo "$DISTRIB_ID" | tr '[:upper:]' '[:lower:]'
DISTRO="$(echo "$DISTRIB_ID" | tr '[:upper:]' '[:lower:]')"
elif test -f /etc/arch-release; then
echo "arch"
DISTRO="arch"
elif test -f /etc/debian_version; then
# Older Debian, Ubuntu
echo "debian"
DISTRO="debian"
elif test -f /etc/SuSe-release; then
# Older SuSE
echo "opensuse"
DISTRO="opensuse"
elif test -f /etc/fedora-release; then
# Older Fedora
echo "fedora"
DISTRO="fedora"
elif test -f /etc/redhat-release; then
# Older Red Hat, CentOS
echo "centos"
DISTRO="centos"
elif type uname >/dev/null 2>&1; then
# Fall back to uname
uname -s
DISTRO="$(uname -s)"
else
die 'Unable to determine the distribution'
fi
}

#
# Set up docker engine quick and dirty
#
get_docker() {
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
rm -f ./get-docker.sh

# Add the current user to group `docker` if they aren't in it already.
if ! getent group docker | grep -qw "$USER"; then
sudo gpasswd -a "$USER" docker
fi
}

#
# Build and install the package with PKGBUILD
#
Expand Down Expand Up @@ -172,19 +162,80 @@ aur_install() {
git clone "https://aur.archlinux.org/$TARGET.git"
fi

DISTRO="$(get_distro)"
if [ "$DISTRO" = "arch" ]; then
if [[ "$DISTRO" == "arch" ]]; then
(makepkg_arch "$TARGET" "$@")
else
(makepkg_manual "$TARGET" "$@")
fi
rm -rf "$TARGET"
}

#
# Set up LLVM repository for Ubuntu
#
add_llvm_repo_for_ubuntu() {
local llvm_version="$1"
local code_name="${UBUNTU_CODENAME:-}"
local signature="/etc/apt/trusted.gpg.d/apt.llvm.org.asc"
local sources_list="/etc/apt/sources.list.d/llvm.list"
export llvm_release_name="llvm-toolchain-$code_name-$llvm_version"

# check distribution
if [[ "${DISTRO:-}" != "ubuntu" ]]; then
die "The Linux distribution is not ubuntu: ${DISTRO:-}"
fi
if [[ -z "$code_name" ]]; then
die "Unrecognizable ubuntu code name: $code_name"
fi

# check if the repo exists
if ! wget -q --method=HEAD "http://apt.llvm.org/$code_name" &>/dev/null; then
die "Failed to connect to http://apt.llvm.org/$code_name"
fi

# download GPG key once
if [[ ! -f "$signature" ]]; then
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee "$signature"
fi

cat <<EOF | sudo tee "$sources_list"
deb http://apt.llvm.org/$code_name/ $llvm_release_name main
deb-src http://apt.llvm.org/$code_name/ $llvm_release_name main
EOF
sudo apt-get update -y -qq
}

#
# Set up docker engine quick and dirty
#
get_docker() {
if command -v docker >/dev/null 2>&1; then
return
fi

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
rm -f ./get-docker.sh

# Add the current user to group `docker` if they aren't in it already.
if ! getent group docker | grep -qw "$USER"; then
sudo gpasswd -a "$USER" docker
fi
}

#
# Install spin-git from the AUR
#
get_spin() {
if ! command -v spin >/dev/null 2>&1; then
aur_install spin-git
fi
}

main() {
DISTRO="$(get_distro)"
get_distro

if [ "$DISTRO" = "arch" ]; then
if [[ "$DISTRO" == "arch" ]]; then
if ! pacman -Q paru >/dev/null 2>&1; then
aur_install paru --asdeps --needed --noconfirm --removemake
fi
Expand All @@ -208,7 +259,8 @@ main() {
paru -Sy --asdeps --needed --noconfirm --removemake "${depends[@]}"
makepkg_arch neo-dev -srcfi --asdeps --noconfirm

elif [ "$DISTRO" = "ubuntu" ]; then
elif [[ "$DISTRO" == "ubuntu" ]]; then
llvm_version=18
script_deps=(build-essential curl git)
style_deps=(clang-format yapf3)
bpf_deps=(elfutils libelf-dev zlib1g-dev binutils-dev libcap-dev clang llvm libc6-dev libc6-dev-i386)
Expand All @@ -221,18 +273,20 @@ main() {
zip unzip # utils required by vcpkg
linux-libc-dev # openssl
libpthread-stubs0-dev
libstdc++-12-dev # TODO: Try 13.
libstdc++-13-dev
libnl-3-200 libnl-3-dev libnl-genl-3-200 libnl-genl-3-dev)
llvm_pkgs=("clang-$llvm_version" "lld-$llvm_version"
"clang-tools-$llvm_version" "clang-format-$llvm_version"
"clang-tidy-$llvm_version" "llvm-$llvm_version-dev"
"llvm-$llvm_version-tools" "libc++-$llvm_version-dev"
"libc++abi-$llvm_version-dev")

sudo apt update -y -qq
sudo apt install -y -qq "${depends[@]}"

if ! command -v docker >/dev/null 2>&1; then
get_docker
fi
if ! command -v spin >/dev/null 2>&1; then
aur_install spin-git
fi
add_llvm_repo_for_ubuntu "$llvm_version"
sudo apt-get update -y -qq
sudo apt-get install -y -qq "${depends[@]}"
sudo apt-get install -y -qq -t "$llvm_release_name" "${llvm_pkgs[@]}"
get_docker
get_spin

else
die "Unsupported distribution: $DISTRO"
Expand Down
2 changes: 1 addition & 1 deletion depends/vcpkg
Submodule vcpkg updated 1222 files
24 changes: 2 additions & 22 deletions depends/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,9 @@
"version": "0.0.1",
"homepage": "https://github.com/netarch/neo",
"dependencies": [
"vcpkg-cmake",
"vcpkg-tool-ninja",
"vcpkg-pkgconfig-get-modules",
"boost-program-options",
"boost-stacktrace",
{
"name": "curl",
"features": [
"brotli",
"c-ares",
"gssapi",
"http2",
"idn",
"idn2",
"ldap",
"openssl",
"psl",
"ssh",
"ssl",
"zstd"
]
},
"curl",
"pcapplusplus",
"rapidjson",
"spdlog",
Expand All @@ -35,8 +16,7 @@
"features": [
"xxhsum"
]
},
"zlib"
}
],
"features": {
"tests": {
Expand Down
Loading

0 comments on commit d2efa54

Please sign in to comment.