Skip to content

[packages] add clang-format #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 26, 2025
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM ubuntu:22.04
FROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
# set out workspace
ENV WORKSPACE=/workspace
RUN mkdir -p ${WORKSPACE}
WORKDIR ${WORKSPACE}
COPY . ${WORKSPACE}
# Required to bypass Python's protection on system-wide package installations in Ubuntu 23.04+.
# This allows pip to install packages globally without using a virtual environment.
ENV PIP_BREAK_SYSTEM_PACKAGES=1
# Install and cleanup is done in one command to minimize the build cache size
RUN apt-get update -qq \
# Extract package names from install_apt_packages.sh
Expand All @@ -29,4 +32,4 @@ RUN apt-get update -qq \
# Build VTR
RUN rm -rf build && make -j$(nproc) && make install
# Container's default launch command
SHELL ["/bin/bash", "-c"]
SHELL ["/bin/bash", "-c"]
19 changes: 17 additions & 2 deletions doc/src/quickstart/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ If you cloned the repository, you will need to set up the git submodules (if you

> git submodule init
> git submodule update

VTR requires several system packages and Python packages to build and run the flow. Ubuntu users can install the required system packages using the following command (this works on Ubuntu 18.04, 20.04, 22.04 and 24.04, but you may require different packages on other Linux distributions). Our CI testing is on Ubuntu 24.04, so that is the best tested platform and recommended for development.

VTR requires several system and Python packages to build and run the flow. Ubuntu users can install the required system packages using the provided script or the command below. This setup works on Ubuntu 18.04, 20.04, 22.04, and 24.04, but note that some packages (such as ``clang-format-18``) are only available by default on Ubuntu 24.04. On older versions, this package will not be installed unless you manually add the appropriate LLVM APT repository.

To install ``clang-format-18`` on older Ubuntu versions (e.g., 20.04 or 22.04), you must add the LLVM repository manually. Note that this tool is only required if you want to run ``make format`` to automatically fix formatting issues in the code. It is not necessary for building or running VPR.

.. code-block:: bash

sudo apt install wget gnupg lsb-release
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18

After that, you can install ``clang-format-18`` using:

.. code-block:: bash

sudo apt install clang-format-18

.. code-block:: bash

Expand Down
5 changes: 5 additions & 0 deletions install_apt_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ sudo apt-get install -y \
# Required to build the documentation
sudo apt-get install -y \
sphinx-common

# Required for code formatting
sudo apt-get install -y \
clang-format-18
Comment on lines +43 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mention that install_apt_packages.sh works with Ubuntu 18, 20, 22 and 24 in the quick start docs, but I believe versions 18 to 22 do not have clang-format-18 in the default apt repos. You should either change the docs for this and remove support for the older versions, or alternatively add an if/else statement to the script to just not install clang-format-18 for the Ubuntu versions that don't have clang-format-18 and say that make format is only supported for Ubuntu 24.04 or newer in the docs. This way people on older Ubuntus can at least compile and use VTR with the same script, they just can't use make format.

You can use this command to check if clang-format-18 is available (it actually checks the local apt-cache but since we do a apt-get update in the script it should be up to date and reliable):

apt-cache search --names-only 'clang-format-18'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks! I added the condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @AmirhosseinPoolad , we decided to update the documentation to inform users that they may encounter issues on Ubuntu versions older than 24.04. We will also include instructions on how to resolve these issues.