Skip to content

Add binary distribution (bindist) packaging for Ubuntu 24.04 x86_64#727

Open
Anamika1608 wants to merge 3 commits intop4lang:masterfrom
Anamika1608:bindist-ubuntu2404-x86_64
Open

Add binary distribution (bindist) packaging for Ubuntu 24.04 x86_64#727
Anamika1608 wants to merge 3 commits intop4lang:masterfrom
Anamika1608:bindist-ubuntu2404-x86_64

Conversation

@Anamika1608
Copy link

This PR adds the initial infrastructure for creating a binary distribution (bindist) of p4c and behavioral-model for Ubuntu 24.04 x86_64, as discussed in p4lang/project-ideas#39.

What this adds

Two files under a new bindist/ directory:

Dockerfile - Automates the full build pipeline:

  • Builds thrift 0.16.0 and nanomsg 1.0.0 from source (not available as apt packages)
  • Builds PI from source
  • Builds behavioral-model with PI, thrift, and debugger support
  • Builds p4c with STATIC_BUILD_WITH_DYNAMIC_GLIBC=ON so the compiler binaries only depend on glibc
  • Collects all artifacts into a single directory, fixes RPATHs on behavioral-model binaries using $ORIGIN/../lib for relocatability
  • Packages everything into p4-bindist-ubuntu2404-x86_64.tar.gz

Usage (from the tutorials/ root):

docker build -f bindist/Dockerfile -t p4-bindist .
docker create --name tmp p4-bindist
docker cp tmp:/p4-bindist-ubuntu2404-x86_64.tar.gz .
docker rm tmp

Specific versions can be pinned via build args:

docker build -f bindist/Dockerfile \
  --build-arg P4C_VERSION=v1.2.5.11 \
  --build-arg BEHAVIORAL_MODEL_VERSION=<sha> \
  -t p4-bindist .

install.sh - End-user install script included in the tarball. After extracting:

tar xzf p4-bindist-ubuntu2404-x86_64.tar.gz
cd p4-bindist-ubuntu2404-x86_64
sudo ./install.sh

It installs runtime apt dependencies (libboost, libgrpc, libprotobuf, libpcap, python3, etc.), copies binaries to /usr/local/bin, copies bundled shared libraries (thrift, nanomsg, PI, BMv2 libs) to /usr/local/lib/p4-bindist, and updates RPATHs and ldconfig. Supports --prefix for custom install location and --uninstall to remove everything.

What the tarball contains

  • Binaries: p4c, p4c-bm2-ss, p4c-bm2-psa, p4c-bm2-pna, p4c-dpdk, p4c-ebpf, p4c-ubpf, p4c-pna-p4tc, p4c-graphs, p4test, simple_switch, simple_switch_grpc, simple_switch_CLI
  • Bundled shared libs: thrift 0.16.0, nanomsg 1.0.0, PI libraries, BMv2 runtime libraries (these are not available via apt on Ubuntu 24.04)
  • p4c data files: p4include headers and driver configs under share/p4c/

Testing done

I manually ran each build step inside a Docker container (Ubuntu 24.04 x86_64) and verified:

  • p4c builds successfully with STATIC_BUILD_WITH_DYNAMIC_GLIBC=ON on Ubuntu 24.04 (this was previously only tested on 22.04 in CI)
  • p4c-bm2-ss only depends on glibc (libc.so.6, libm.so.6) after static linking
  • simple_switch_grpc finds bundled libs via $ORIGIN/../lib RPATH
  • On a fresh Ubuntu 24.04 container, after extracting the tarball and running install.sh, both p4c --version and simple_switch_grpc --version work correctly

Still to do

  • GitHub Actions workflow to automate the build and upload the tarball as a release artifact
  • More thorough testing (compile and run a sample P4 program end to end)
  • The Dockerfile itself has not been tested as a single docker build run yet (each step was tested individually)

Ref: p4lang/project-ideas#39

@jafingerhut
Copy link
Collaborator

Thank you for developing this. I will try this out some time in the next few days, and look it over a bit for reviewing it.

One quick question: Is it quick and easy in the Dockerfile to enable this for processors with aarch64 architecture, too? I know that all of the projects build on aarch64 Ubuntu 24.04 Linux running in VirtualBox on an Apple Silicon Mac, so I'm hoping that is a fairly small change to what you have done so far.

@Dscano
Copy link
Contributor

Dscano commented Mar 9, 2026

Welcome @Anamika1608!

It looks like this is your first contribution. We noticed the DCO (Developer Certificate of Origin) check might fail if your commits aren't signed.

To fix this, please ensure every commit has a Signed-off-by: Name <email> line. You can do this automatically by using the -s flag: git commit -s -m "Your message"

For existing commits, you can fix them with: git commit --amend --signoff or git rebase -i HEAD~N --signoff (where N is the number of commits)

The Developer Community DCO guide also provides helpful tips on fixing DCO inconveniences. Setting a commit hook in the git repository will automate adding the DCO signoff. See https://github.com/p4lang/governance/wiki/P4-DCO-Guidelines for information.

@jafingerhut
Copy link
Collaborator

jafingerhut commented Mar 10, 2026

I tried checking out the branch with your changes on an x86_64 Ubuntu 24.04 Linux system running in VirtualBox. After installing docker, I ran this command:

docker build -f bindist/Dockerfile -t p4-bindist . |& tee log-docker-build.txt

It appears that building the dependencies, behavioral-model, and p4c all succeeded, but there was a failure after that in copying some files around. See the attached log file.

Have you run the command above successfully, without errors?
log-docker-build.txt

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>
Brace expansion {bin,lib,share} is a bash feature that does not work
in Docker's /bin/sh. Replace with explicit mkdir calls for each
directory.

Signed-off-by: Anamika AggarwaL <anamikaagg18@gmail.com>
@Anamika1608 Anamika1608 force-pushed the bindist-ubuntu2404-x86_64 branch from 60fd2e7 to 2e371b1 Compare March 10, 2026 12:55
p4c requires the GNU C preprocessor (cpp) at runtime to handle
#include directives in P4 source files. Without it, compilation
fails with "cpp: not found".

Signed-off-by: Anamika <anamika@users.noreply.github.com>
Signed-off-by: Anamika AggarwaL <anamikaagg18@gmail.com>
@Anamika1608
Copy link
Author

hi @jafingerhut, I pushed another fix, added cpp (GNU C preprocessor) to the runtime dependencies in
install.sh. Without it, p4c fails when processing #include directives in P4 source files.

I tested the full pipeline on a fresh Ubuntu 24.04 container: extract tarball → run install.sh →
compile a P4 program with p4c-bm2-ss → load it in simple_switch -- all working. I also verified the
uninstall path works cleanly.

I wasn't able to do a complete end-to-end Dockerfile build on my machine since I'm on an Apple Silicon
Mac and the x86_64 emulation runs out of memory during p4c's LTO linking phase. Steps 1–6 (Thrift,
nanomsg, PI, behavioral-model) all build successfully in Docker -- it's only the p4c step that needs
more memory than QEMU emulation allows. This shouldn't be an issue on a native x86_64 machine.

Regarding aarch64 -- yes, it should be a small change. The Dockerfile and build steps are
architecture-agnostic. The main changes would be:

  1. Build with --platform linux/arm64 instead of linux/amd64
  2. Rename the output directory/tarball from x86_64 to aarch64
  3. Verify the runtime apt package names in install.sh are the same on arm64

I can parameterize the architecture using Docker's TARGETARCH so a single Dockerfile handles both, or
set it up with docker buildx for multi-arch builds. Happy to add that once the x86_64 version looks
good to you.

@jafingerhut
Copy link
Collaborator

jafingerhut commented Mar 10, 2026

I tried following the instructions in the first comment with the version of this PR just after commit 3.

There were no obvious errors from executing this command:

docker build -f bindist/Dockerfile -t p4-bindist .

I am attaching the log, in case it helps diagnose any issues.

However, the next command gave an error, as shown below:

$ docker create --name tmp p4-bindist
Error response from daemon: no command specified

Out of curiosity, I went ahead and tried the next command, which also gave an error:

$ docker cp tmp:/p4-bindist-ubuntu2404-x86_64.tar.gz .
Error response from daemon: No such container: tmp

I suspect that if you switch your focus to implementing and testing this for aarch64 Ubuntu 24.04 Linux first, which you can run natively on your own computer, you can probably iterate such testing much faster than waiting for me to do so. (Note: I mean by running VirtualBox on your Apple Silicon Mac, and installing aarch64 Ubuntu 24.04 Linux as a VM on it. There is no need to boot Linux on the bare hardware. If you want instructions to assist in doing so, you can find them here: https://github.com/p4lang/tutorials/blob/master/vm-ubuntu-24.04/README-create-vm-using-iso-installer.md )

I would also recommend adding a bindist/README.md file to your PR that gives the sequence of commands to run, as after this PR is closed, no one will think to look here for them.

log-docker-build (1).txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants