Skip to content

Commit 02deb23

Browse files
committed
Add bindist packaging for Ubuntu 24.04 x86_64
Add Dockerfile and install script to build and distribute precompiled binaries of p4c and behavioral-model (simple_switch_grpc) as a single tar.gz archive for Ubuntu 24.04. Ref: p4lang/project-ideas#39 Signed-off-by: Anamika AggarwaL <anamikaagg18@gmail.com>
1 parent 5f4d62d commit 02deb23

File tree

2 files changed

+303
-0
lines changed

2 files changed

+303
-0
lines changed

bindist/Dockerfile

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
FROM ubuntu:24.04 AS builder
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG BEHAVIORAL_MODEL_VERSION=main
5+
ARG PI_VERSION=main
6+
ARG P4C_VERSION=main
7+
8+
# Step 1: Install all build dependencies
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
autoconf automake bison build-essential clang cmake curl flex g++ git \
11+
libboost-dev libboost-filesystem-dev libboost-graph-dev \
12+
libboost-iostreams-dev libboost-program-options-dev libboost-system-dev \
13+
libboost-test-dev libboost-thread-dev libbz2-dev libevent-dev libffi-dev \
14+
libfl-dev libgc-dev libgflags-dev libgmp-dev libgrpc++-dev libgrpc-dev \
15+
libelf-dev liblzma-dev libpcap-dev libprotobuf-dev libreadline-dev \
16+
libssl-dev libtool libtool-bin llvm make net-tools patchelf pkg-config \
17+
protobuf-compiler protobuf-compiler-grpc python3-dev python3-pip \
18+
python3-venv tcpdump unzip valgrind wget \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
WORKDIR /build
22+
23+
# Step 2: Build Thrift 0.16.0
24+
RUN git clone --depth 1 --branch v0.16.0 https://github.com/apache/thrift.git thrift-0.16.0 \
25+
&& cd thrift-0.16.0 \
26+
&& ./bootstrap.sh \
27+
&& ./configure --with-cpp --with-python --without-java --without-ruby \
28+
--without-nodejs --without-go --without-erlang --without-lua \
29+
--without-php --without-swift --without-rs --without-dotnetcore \
30+
--without-haskell --without-perl --without-c_glib --without-d \
31+
--without-qt5 \
32+
&& make -j$(nproc) \
33+
&& make install \
34+
&& cd /build && rm -rf thrift-0.16.0
35+
36+
# Step 3: Build nanomsg 1.0.0
37+
RUN git clone --depth 1 --branch 1.0.0 https://github.com/nanomsg/nanomsg.git nanomsg-1.0.0 \
38+
&& cd nanomsg-1.0.0 \
39+
&& mkdir build && cd build \
40+
&& cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
41+
&& make -j$(nproc) \
42+
&& make install \
43+
&& cd /build && rm -rf nanomsg-1.0.0
44+
45+
RUN ldconfig
46+
47+
# Step 5: Build PI
48+
RUN git clone https://github.com/p4lang/PI.git \
49+
&& cd PI \
50+
&& if [ "$PI_VERSION" != "main" ]; then git checkout $PI_VERSION; fi \
51+
&& git submodule update --init --recursive \
52+
&& ./autogen.sh \
53+
&& ./configure --with-proto --without-internal-rpc --without-cli --without-bmv2 \
54+
&& make -j$(nproc) \
55+
&& make install \
56+
&& cd /build && rm -rf PI
57+
58+
RUN ldconfig
59+
60+
# Step 6: Build behavioral-model
61+
# Patches are from vm-ubuntu-24.04/patches/ in the tutorials repo.
62+
# Build context must be set to the tutorials/ root:
63+
# docker build -f bindist/Dockerfile -t p4-bindist .
64+
COPY vm-ubuntu-24.04/patches/behavioral-model-support-fedora.patch /build/patches/
65+
COPY vm-ubuntu-24.04/patches/behavioral-model-support-venv.patch /build/patches/
66+
RUN git clone https://github.com/p4lang/behavioral-model.git \
67+
&& cd behavioral-model \
68+
&& if [ "$BEHAVIORAL_MODEL_VERSION" != "main" ]; then git checkout $BEHAVIORAL_MODEL_VERSION; fi \
69+
&& git submodule update --init --recursive \
70+
&& patch -p1 < /build/patches/behavioral-model-support-fedora.patch \
71+
&& patch -p1 < /build/patches/behavioral-model-support-venv.patch \
72+
&& ./autogen.sh \
73+
&& ./configure --with-pi --with-thrift --enable-debugger \
74+
&& make -j$(nproc) \
75+
&& make install-strip \
76+
&& cd /build && rm -rf behavioral-model
77+
78+
RUN ldconfig
79+
80+
# Step 7: Build p4c with static linking
81+
RUN git clone --recurse-submodules https://github.com/p4lang/p4c.git \
82+
&& cd p4c \
83+
&& if [ "$P4C_VERSION" != "main" ]; then git checkout $P4C_VERSION && git submodule update --init --recursive; fi \
84+
&& mkdir build && cd build \
85+
&& cmake .. \
86+
-DCMAKE_BUILD_TYPE=Release \
87+
-DSTATIC_BUILD_WITH_DYNAMIC_GLIBC=ON \
88+
-DENABLE_TEST_TOOLS=OFF \
89+
-DCMAKE_INSTALL_PREFIX=/usr/local \
90+
&& make -j$(nproc) \
91+
&& make install \
92+
&& cd /build && rm -rf p4c
93+
94+
# Step 8: Collect artifacts into bindist
95+
RUN mkdir -p /build/bindist/p4-bindist-ubuntu2404-x86_64/{bin,lib,share}
96+
97+
# Copy p4c binaries
98+
RUN for bin in p4c p4c-bm2-ss p4c-bm2-psa p4c-bm2-pna p4c-dpdk p4c-ebpf \
99+
p4c-ubpf p4c-pna-p4tc p4c-graphs p4test; do \
100+
cp /usr/local/bin/$bin /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ 2>/dev/null || true; \
101+
done
102+
103+
# Copy behavioral-model binaries
104+
RUN cp /usr/local/bin/simple_switch /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ \
105+
&& cp /usr/local/bin/simple_switch_grpc /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ \
106+
&& cp /usr/local/bin/simple_switch_CLI /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/
107+
108+
# Copy bundled shared libraries (not available via apt on Ubuntu 24.04)
109+
RUN cp -a /usr/local/lib/libthrift*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \
110+
&& cp -a /usr/local/lib/libnanomsg*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \
111+
&& cp -a /usr/local/lib/libpi*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \
112+
&& cp -a /usr/local/lib/libbm*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \
113+
&& cp -a /usr/local/lib/libsimpleswitch*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \
114+
&& cp -a /usr/local/lib/libruntimestubs*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/
115+
116+
# Copy p4c share files
117+
RUN cp -r /usr/local/share/p4c /build/bindist/p4-bindist-ubuntu2404-x86_64/share/
118+
119+
# Fix RPATHs on behavioral-model binaries
120+
RUN for bin in simple_switch simple_switch_grpc; do \
121+
patchelf --set-rpath '$ORIGIN/../lib' /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/$bin; \
122+
done
123+
124+
# Copy install script
125+
COPY bindist/install.sh /build/bindist/p4-bindist-ubuntu2404-x86_64/install.sh
126+
RUN chmod +x /build/bindist/p4-bindist-ubuntu2404-x86_64/install.sh
127+
128+
# Create the tarball
129+
RUN cd /build/bindist \
130+
&& tar czf p4-bindist-ubuntu2404-x86_64.tar.gz p4-bindist-ubuntu2404-x86_64/
131+
132+
# Final stage: just the tarball
133+
FROM scratch
134+
COPY --from=builder /build/bindist/p4-bindist-ubuntu2404-x86_64.tar.gz /

bindist/install.sh

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/bin/bash
2+
# install.sh - Install script for p4-bindist (P4 binary distribution)
3+
# Target: Ubuntu 24.04 x86_64
4+
#
5+
# Usage:
6+
# sudo ./install.sh # Install to /usr/local (default)
7+
# sudo ./install.sh --prefix /opt/p4 # Install to custom prefix
8+
# sudo ./install.sh --uninstall # Remove installed files
9+
10+
set -e
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
PREFIX="/usr/local"
14+
UNINSTALL=0
15+
16+
# Parse arguments
17+
while [[ $# -gt 0 ]]; do
18+
case $1 in
19+
--prefix)
20+
PREFIX="$2"
21+
shift 2
22+
;;
23+
--uninstall)
24+
UNINSTALL=1
25+
shift
26+
;;
27+
--help)
28+
echo "Usage: $0 [--prefix /path] [--uninstall]"
29+
echo ""
30+
echo "Options:"
31+
echo " --prefix PATH Install to PATH (default: /usr/local)"
32+
echo " --uninstall Remove previously installed files"
33+
echo " --help Show this help"
34+
exit 0
35+
;;
36+
*)
37+
echo "Unknown option: $1"
38+
echo "Run '$0 --help' for usage."
39+
exit 1
40+
;;
41+
esac
42+
done
43+
44+
# Check we're running on Ubuntu 24.04
45+
check_os() {
46+
if [ -f /etc/os-release ]; then
47+
. /etc/os-release
48+
if [ "$ID" != "ubuntu" ] || [ "$VERSION_ID" != "24.04" ]; then
49+
echo "WARNING: This bindist was built for Ubuntu 24.04."
50+
echo "Detected: $ID $VERSION_ID"
51+
echo "It may not work correctly on this system."
52+
read -p "Continue anyway? [y/N] " -n 1 -r
53+
echo
54+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
55+
exit 1
56+
fi
57+
fi
58+
fi
59+
}
60+
61+
# Runtime apt dependencies that simple_switch_grpc and simple_switch need.
62+
# These are standard Ubuntu 24.04 packages.
63+
RUNTIME_DEPS=(
64+
python3
65+
patchelf
66+
libboost-filesystem1.83.0
67+
libboost-program-options1.83.0
68+
libboost-thread1.83.0
69+
libgmp10
70+
libpcap0.8t64
71+
libprotobuf32t64
72+
libgrpc++1.51t64
73+
libgrpc29t64
74+
libabsl20220623t64
75+
libre2-10
76+
libcares2
77+
)
78+
79+
install_runtime_deps() {
80+
echo "Installing runtime dependencies via apt..."
81+
apt-get update -qq
82+
apt-get install -y --no-install-recommends "${RUNTIME_DEPS[@]}"
83+
echo "Runtime dependencies installed."
84+
}
85+
86+
do_install() {
87+
echo "Installing p4-bindist to ${PREFIX}..."
88+
89+
# Create directories
90+
mkdir -p "${PREFIX}/bin"
91+
mkdir -p "${PREFIX}/lib/p4-bindist"
92+
mkdir -p "${PREFIX}/share/p4c"
93+
94+
# Copy binaries
95+
cp -f "${SCRIPT_DIR}/bin/"* "${PREFIX}/bin/"
96+
97+
# Copy bundled shared libraries to a dedicated directory (preserve symlinks)
98+
cp -a "${SCRIPT_DIR}/lib/"* "${PREFIX}/lib/p4-bindist/"
99+
100+
# Copy share files
101+
cp -rf "${SCRIPT_DIR}/share/p4c/"* "${PREFIX}/share/p4c/"
102+
103+
# Fix RPATHs to point to the actual install location
104+
for bin in simple_switch simple_switch_grpc; do
105+
if [ -f "${PREFIX}/bin/${bin}" ]; then
106+
patchelf --set-rpath "${PREFIX}/lib/p4-bindist" "${PREFIX}/bin/${bin}" 2>/dev/null || true
107+
fi
108+
done
109+
110+
# Update linker cache
111+
echo "${PREFIX}/lib/p4-bindist" > /etc/ld.so.conf.d/p4-bindist.conf
112+
ldconfig
113+
114+
# Save install manifest for uninstall
115+
MANIFEST="${PREFIX}/share/p4c/.p4-bindist-manifest"
116+
echo "${PREFIX}" > "${MANIFEST}"
117+
118+
echo ""
119+
echo "Installation complete!"
120+
echo ""
121+
echo "Installed binaries:"
122+
echo " p4c - P4 compiler driver"
123+
echo " p4c-bm2-ss - P4 compiler for BMv2 simple_switch"
124+
echo " simple_switch - BMv2 software switch"
125+
echo " simple_switch_grpc - BMv2 software switch with gRPC"
126+
echo " simple_switch_CLI - CLI for simple_switch"
127+
echo ""
128+
echo "Verify with:"
129+
echo " p4c --version"
130+
echo " simple_switch_grpc --version"
131+
}
132+
133+
do_uninstall() {
134+
echo "Uninstalling p4-bindist from ${PREFIX}..."
135+
136+
# Remove binaries
137+
for bin in p4c p4c-bm2-ss p4c-bm2-psa p4c-bm2-pna p4c-dpdk p4c-ebpf \
138+
p4c-ubpf p4c-pna-p4tc p4c-graphs p4test \
139+
simple_switch simple_switch_grpc simple_switch_CLI; do
140+
rm -f "${PREFIX}/bin/${bin}"
141+
done
142+
143+
# Remove bundled libraries
144+
rm -rf "${PREFIX}/lib/p4-bindist"
145+
146+
# Remove share files
147+
rm -rf "${PREFIX}/share/p4c"
148+
149+
# Remove linker config
150+
rm -f /etc/ld.so.conf.d/p4-bindist.conf
151+
ldconfig
152+
153+
echo "Uninstall complete."
154+
}
155+
156+
# Check for root
157+
if [ "$(id -u)" -ne 0 ]; then
158+
echo "This script must be run as root (use sudo)."
159+
exit 1
160+
fi
161+
162+
check_os
163+
164+
if [ "$UNINSTALL" -eq 1 ]; then
165+
do_uninstall
166+
else
167+
install_runtime_deps
168+
do_install
169+
fi

0 commit comments

Comments
 (0)