Skip to content

Commit cefdc44

Browse files
committed
CI installation refactoring.
ssad
1 parent df9e3ee commit cefdc44

File tree

5 files changed

+261
-27
lines changed

5 files changed

+261
-27
lines changed

.github/workflows/ci-test-debian.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
4040
- name: Run tests (Ubuntu 22.04)
4141
# Need to use sudo for the eBPF kernel tests.
42-
run: sudo -E ctest --output-on-failure --schedule-random
42+
run: |
43+
sudo -E env PATH="$PATH" poetry run ctest --output-on-failure --schedule-random
4344
working-directory: ./build
4445

4546
# Build with GCC and test Tofino backend on Ubuntu 22.04.
@@ -112,6 +113,7 @@ jobs:
112113
113114
- name: Run tests (Ubuntu 20.04)
114115
# Need to use sudo for the eBPF kernel tests.
115-
run: sudo -E ctest --output-on-failure --schedule-random
116+
run: |
117+
sudo -E env PATH="$PATH" poetry run ctest --output-on-failure --schedule-random
116118
working-directory: ./build
117119
if: matrix.unity == 'ON' && matrix.gtest == 'ON'

pyproject.toml

+40
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,43 @@ disable = [
5151
"missing-function-docstring",
5252
"too-few-public-methods",
5353
]
54+
55+
[tool.poetry]
56+
name = "p4c"
57+
version = "1.2.5.1"
58+
description = ""
59+
authors = ["Your Name <[email protected]>"]
60+
license = "Apache"
61+
readme = "README.md"
62+
package-mode = false
63+
64+
[tool.poetry.dependencies]
65+
python = "^3.8"
66+
pyroute2 = "0.7.3"
67+
ply = "3.11"
68+
ptf = "0.10.0"
69+
scapy = "2.5.0"
70+
clang-format = "18.1.0"
71+
googleapis-common-protos = "1.53.0"
72+
protobuf = [
73+
{version = "3.20.2", python = ">3.6"},
74+
{version = "3.19.2", python = "<=3.6"}
75+
]
76+
black = [
77+
{version = "24.3.0", python = ">3.6"},
78+
{version = "22.8.0", python = "<=3.6"}
79+
]
80+
isort = [
81+
{version = "5.13.2", python = ">3.6"},
82+
{version = "5.10.1", python = "<=3.6"}
83+
]
84+
grpcio = [
85+
{version = "1.67.0", python = ">3.6"},
86+
{version = "1.48.2", python = "<=3.6"}
87+
]
88+
p4runtime = "1.4.1"
89+
90+
91+
[build-system]
92+
requires = ["poetry-core"]
93+
build-backend = "poetry.core.masonry.api"

requirements.txt

-18
This file was deleted.

tools/ci-build.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ fi
104104

105105
sudo apt-get update
106106
sudo apt-get install -y --no-install-recommends ${P4C_DEPS}
107-
sudo pip3 install --upgrade pip
108-
sudo pip3 install -r ${P4C_DIR}/requirements.txt
107+
sudo apt-get install -y python3-venv
108+
curl -sSL https://install.python-poetry.org | python3 -
109+
poetry install
109110

110111
if [ "${BUILD_GENERATOR,,}" == "ninja" ] && [ ! $(command -v ninja) ]
111112
then
@@ -155,11 +156,6 @@ function build_bmv2() {
155156
fi
156157

157158
sudo apt-get update && sudo apt-get install -y --no-install-recommends ${P4C_RUNTIME_DEPS}
158-
159-
if [[ "${DISTRIB_RELEASE}" != "18.04" ]] ; then
160-
# To run PTF nanomsg tests. Not available on 18.04.
161-
sudo pip3 install nnpy
162-
fi
163159
}
164160

165161
if [[ "${ENABLE_BMV2}" == "ON" ]] ; then

tools/install.sh

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#!/bin/bash
2+
3+
THIS_DIR=$( cd -- "$( dirname -- "${0}" )" &> /dev/null && pwd )
4+
P4C_DIR=$(readlink -f ${THIS_DIR}/..)
5+
6+
# Get distribution info
7+
DISTRO=$(lsb_release -i | awk -F: '{print $2}' | xargs)
8+
VERSION=$(lsb_release -r | awk -F: '{print $2}' | xargs)
9+
10+
# Define supported distributions and versions
11+
SUPPORTED_DISTROS=("Ubuntu" "Pop")
12+
SUPPORTED_UBUNTU_VERSIONS=("20.04" "22.04" "24.04")
13+
14+
# Function to check if an element exists in an array
15+
contains() {
16+
local element
17+
for element in "${@:2}"; do
18+
if [[ "$element" == "$1" ]]; then
19+
return 0
20+
fi
21+
done
22+
return 1
23+
}
24+
25+
# Check distribution and version
26+
if contains "$DISTRO" "${SUPPORTED_DISTROS[@]}"; then
27+
if [[ "$DISTRO" == "Ubuntu" ]]; then
28+
if contains "$VERSION" "${SUPPORTED_UBUNTU_VERSIONS[@]}"; then
29+
echo "Supported distribution: $DISTRO $VERSION"
30+
exit 0
31+
else
32+
echo "Error: Unsupported Ubuntu version: $VERSION"
33+
exit 1
34+
fi
35+
else
36+
# Assume all versions of Pop!_OS and Linux Mint are supported
37+
echo "Supported distribution: $DISTRO $VERSION"
38+
fi
39+
else
40+
echo "Error: Unsupported distribution: $DISTRO"
41+
exit 1
42+
fi
43+
44+
# Whether to install dependencies required to run PTF-ebpf tests
45+
: "${INSTALL_PTF_EBPF_DEPENDENCIES:=OFF}"
46+
# The build generator to use. Defaults to Make.
47+
: "${BUILD_GENERATOR:="ninja"}"
48+
# BMv2 is enable by default.
49+
: "${ENABLE_BMV2:=ON}"
50+
# eBPF is enabled by default.
51+
: "${ENABLE_EBPF:=ON}"
52+
# This is the list of back ends that can be enabled.
53+
# Back ends can be enabled from the command line with "ENABLE_[backend]=TRUE/FALSE"
54+
ENABLE_BACKENDS=("TOFINO" "BMV2" "EBPF" "UBPF" "DPDK"
55+
"P4TC" "P4FMT" "P4TEST" "P4C_GRAPHS"
56+
"TEST_TOOLS"
57+
)
58+
function build_cmake_enabled_backend_string() {
59+
CMAKE_ENABLE_BACKENDS=""
60+
for backend in "${ENABLE_BACKENDS[@]}";
61+
do
62+
enable_var=ENABLE_${backend}
63+
if [ -n "${!enable_var}" ]; then
64+
echo "${enable_var}=${!enable_var} is set."
65+
CMAKE_ENABLE_BACKENDS+="-D${enable_var}=${!enable_var} "
66+
fi
67+
done
68+
}
69+
70+
71+
. /etc/lsb-release
72+
73+
# In Docker builds, sudo is not available. So make it a noop.
74+
if [ "$IN_DOCKER" == "TRUE" ]; then
75+
echo "Executing within docker container."
76+
function sudo() { command "$@"; }
77+
fi
78+
79+
80+
# ! ------ BEGIN CORE -----------------------------------------------
81+
P4C_DEPS="bison \
82+
flex \
83+
cmake \
84+
build-essential \
85+
ccache \
86+
ninja-build \
87+
g++ \
88+
git \
89+
lld \
90+
libboost-graph-dev \
91+
libboost-iostreams-dev \
92+
libfl-dev \
93+
python3 \
94+
python3-pip \
95+
python3-setuptools"
96+
97+
sudo apt-get update
98+
sudo apt-get install -y --no-install-recommends ${P4C_DEPS}
99+
100+
sudo apt-get install -y python3-poetry python3-venv
101+
poetry install
102+
poetry shell
103+
104+
if [ "${BUILD_GENERATOR,,}" == "ninja" ] && [ ! $(command -v ninja) ]
105+
then
106+
echo "Selected ninja as build generator, but ninja could not be found."
107+
exit 1
108+
fi
109+
110+
# ! ------ END CORE -----------------------------------------------
111+
112+
ccache --set-config max_size=1G
113+
114+
# ! ------ BEGIN BMV2 -----------------------------------------------
115+
function build_bmv2() {
116+
P4C_RUNTIME_DEPS_BOOST="libboost-graph1.7* libboost-iostreams1.7*"
117+
118+
P4C_RUNTIME_DEPS="cpp \
119+
${P4C_RUNTIME_DEPS_BOOST} \
120+
libgc1* \
121+
libgmp-dev \
122+
libnanomsg-dev"
123+
124+
sudo apt-get install -y wget ca-certificates
125+
# Add the p4lang opensuse repository.
126+
echo "deb http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_${DISTRIB_RELEASE}/ /" | sudo tee /etc/apt/sources.list.d/home:p4lang.list
127+
curl -fsSL https://download.opensuse.org/repositories/home:p4lang/xUbuntu_${DISTRIB_RELEASE}/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_p4lang.gpg > /dev/null
128+
P4C_RUNTIME_DEPS+=" p4lang-bmv2"
129+
130+
sudo apt-get update && sudo apt-get install -y --no-install-recommends ${P4C_RUNTIME_DEPS}
131+
132+
}
133+
134+
if [[ "${ENABLE_BMV2}" == "ON" ]] ; then
135+
build_bmv2
136+
fi
137+
# ! ------ END BMV2 -----------------------------------------------
138+
139+
# ! ------ BEGIN EBPF -----------------------------------------------
140+
function build_ebpf() {
141+
P4C_EBPF_DEPS="libpcap-dev \
142+
libelf-dev \
143+
zlib1g-dev \
144+
llvm \
145+
clang \
146+
tcpdump \
147+
iproute2 \
148+
iptables \
149+
net-tools"
150+
151+
sudo apt-get install -y --no-install-recommends ${P4C_EBPF_DEPS}
152+
}
153+
154+
function install_ptf_ebpf_test_deps() (
155+
P4C_PTF_PACKAGES="gcc-multilib \
156+
python3-six \
157+
libgmp-dev \
158+
libjansson-dev"
159+
sudo apt-get install -y --no-install-recommends ${P4C_PTF_PACKAGES}
160+
161+
git clone --depth 1 --recursive --branch v0.3.1 https://github.com/NIKSS-vSwitch/nikss /tmp/nikss
162+
pushd /tmp/nikss
163+
./build_libbpf.sh
164+
mkdir build
165+
cd build
166+
cmake -DCMAKE_BUILD_TYPE=Release -G "${BUILD_GENERATOR}" ..
167+
cmake --build . -- -j $(nproc)
168+
sudo cmake --install .
169+
170+
# install bpftool
171+
git clone --recurse-submodules --branch v7.3.0 https://github.com/libbpf/bpftool.git /tmp/bpftool
172+
cd /tmp/bpftool/src
173+
make "-j$(nproc)"
174+
sudo make install
175+
popd
176+
)
177+
178+
if [[ "${ENABLE_EBPF}" == "ON" ]] ; then
179+
build_ebpf
180+
if [[ "${INSTALL_PTF_EBPF_DEPENDENCIES}" == "ON" ]] ; then
181+
install_ptf_ebpf_test_deps
182+
fi
183+
fi
184+
# ! ------ END EBPF -----------------------------------------------
185+
186+
# ! ------ BEGIN DPDK -----------------------------------------------
187+
function build_dpdk() {
188+
# Replace existing Protobuf with one that works.
189+
# TODO: Debug protobuf mismatch.
190+
sudo -E pip3 uninstall -y protobuf
191+
sudo pip3 install protobuf==3.20.3 netaddr==0.9.0
192+
}
193+
194+
if [[ "${ENABLE_DPDK}" == "ON" ]]; then
195+
build_dpdk
196+
fi
197+
# ! ------ END DPDK -----------------------------------------------
198+
199+
# ! ------ BEGIN TOFINO --------------------------------------------
200+
201+
function build_tofino() {
202+
P4C_TOFINO_PACKAGES="rapidjson-dev"
203+
sudo apt-get install -y --no-install-recommends ${P4C_TOFINO_PACKAGES}
204+
sudo pip3 install jsl==0.2.4 pyinstaller==6.11.0
205+
}
206+
207+
if [[ "${ENABLE_TOFINO}" == "ON" ]]; then
208+
echo "Installing Tofino dependencies"
209+
build_tofino
210+
fi
211+
# ! ------ END TOFINO ----------------------------------------------
212+
213+
echo "Test image ready"
214+

0 commit comments

Comments
 (0)