Skip to content

Commit

Permalink
Comments/Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Jul 10, 2023
1 parent 9b21315 commit e400d7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ sudo dpkg -i /path/to/package.deb
library. Default is ON.
- `-DENABLE_GTESTS=ON|OFF`. Enable building and running GTest unit tests.
Default is ON.
- `-DENABLE_PROTOBUF_STATIC=ON|OFF`. Enable the use of static
protobuf libraries. Default is ON.
- `-DP4C_USE_PREINSTALLED_PROTOBUF=ON|OFF`. Try to find a system version of Protobuf instead of a CMake version.
- `-DENABLE_PROTOBUF_STATIC=ON|OFF`. Enable the use of static protobuf libraries. Default is ON.
Only has an effect when `P4C_USE_PREINSTALLED_PROTOBUF` is enabled.
- `-DENABLE_MULTITHREAD=ON|OFF`. Use multithreading. Default is
OFF.
- `-DBUILD_LINK_WITH_GOLD=ON|OFF`. Use Gold linker for build if available.
Expand Down Expand Up @@ -271,18 +272,16 @@ For documentation building:

`p4c` also depends on Google Protocol Buffers (Protobuf). `p4c` requires version
3.0 or higher, so the packaged version provided in Ubuntu 20.04 **should**
work. However, all our CI testing is done with a more recent version of Protobuf
(at the moment, 3.18.1), which we install from source. If you are experiencing
issues with the Protobuf version shipped with your OS distribution, we recommend
that we install Protobuf 3.18.1 from source. You can find instructions
[here](https://github.com/protocolbuffers/protobuf/blob/v3.18.1/src/README.md).
After cloning Protobuf and before you build, check-out version 3.18.1:
work. However, P4C typically installs its own version of Protobuf using CMake's Fetchcontent module
(at the moment, 3.21.12). If you are experiencing issues with the Protobuf version shipped with your OS distribution, we recommend that to install Protobuf 3.21.12 from source. You can find instructions
[here](https://github.com/protocolbuffers/protobuf/blob/v3.21.12/src/README.md).
After cloning Protobuf and before you build, check-out version 3.21.12:

`git checkout v3.18.1`
`git checkout v3.21.12`

Please note that while all Protobuf versions newer than 3.0 should work for
`p4c` itself, you may run into trouble with some extensions and other p4lang
projects unless you install version 3.18.1.
projects unless you install version 3.21.12.

### CMake
p4c requires a CMake version of at least 3.16.3 or higher. On older systems, a newer version of CMake can be installed using `pip3 install --user cmake==3.16.3`. We have a CI test on Ubuntu 18.04 that uses this option, but there is no guarantee that this will lead to a successful build.
Expand All @@ -292,7 +291,7 @@ p4c requires a CMake version of at least 3.16.3 or higher. On older systems, a n
```bash
sudo dnf install -y cmake g++ git automake libtool gc-devel bison flex \
libfl-devel gmp-devel boost-devel boost-iostreams boost-graph llvm pkg-config \
python3 python3-pip tcpdump protobuf-devel protobuf-static
python3 python3-pip tcpdump

sudo pip3 install -r requirements.txt
```
Expand Down Expand Up @@ -343,10 +342,7 @@ Installing on macOS:
```
Homebrew offers a `protobuf` formula. It installs version 3.2, which should
work for p4c itself but may cause problems with some extensions. It's
preferable to install Protocol Buffers 3.0 from source using the instructions
[here](https://github.com/google/protobuf/blob/master/src/README.md). Check
out the newest tag in the 3.0 series (`v3.0.2` as of this writing) before you
build.
preferable to use the version of Protobuf which is supplied with CMake's fetchcontent (3.21.12).

The `protobuf` formula requires the following CMake variables to be set,
otherwise CMake does not find the libraries or fails in linking. It is likely
Expand Down
14 changes: 8 additions & 6 deletions cmake/Protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
macro(p4c_obtain_protobuf)
option(
TOOLS_USE_PREINSTALLED_PROTOBUF
"Look for a preinstalled version of Protobuf instead of installing a prebuilt binary using FetchContent."
P4C_USE_PREINSTALLED_PROTOBUF
"Look for a preinstalled version of Protobuf in the system instead of installing a prebuilt binary using FetchContent."
OFF
)

if(TOOLS_USE_PREINSTALLED_PROTOBUF)
# If P4C_USE_PREINSTALLED_PROTOBUF is ON just try to find a preinstalled version of Protobuf.
if(P4C_USE_PREINSTALLED_PROTOBUF)
if(ENABLE_PROTOBUF_STATIC)
set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
Expand All @@ -19,9 +20,9 @@ macro(p4c_obtain_protobuf)
# dependency. https://protobuf.dev/news/2022-08-03/#abseil-dep We do not want abseil, so we stay
# with 21.x for now.
set(P4C_PROTOBUF_VERSION "21.12")
message("Fetching Protobuf version ${P4C_PROTOBUF_VERSION} for P4Tools...")
message("Fetching Protobuf version ${P4C_PROTOBUF_VERSION} for P4C...")

# Print out download state while setting up Z3.
# Print out download state while setting up Protobuf.
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET})
set(FETCHCONTENT_QUIET OFF)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests.")
Expand All @@ -36,7 +37,8 @@ macro(p4c_obtain_protobuf)
USES_TERMINAL_DOWNLOAD TRUE
GIT_PROGRESS TRUE
)
# Pull a different binary for MacOS.
# Pull a different protoc binary for MacOS.
# TODO: Should we build from scratch?
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
fetchcontent_declare(
protoc
Expand Down
2 changes: 0 additions & 2 deletions tools/install_fedora_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ sudo dnf install -y -q \
openssl-devel \
pkg-config \
procps-ng \
protobuf-devel \
protobuf-static \
python3 \
python3-pip \
python3-thrift \
Expand Down

0 comments on commit e400d7d

Please sign in to comment.