Skip to content

Commit

Permalink
CI: Find protobuf and pass it to cmake on macOS (p4lang#3896)
Browse files Browse the repository at this point in the history
* Find protbuf and pass it to cmake on macOS

* CI: Don't allow static protobuf on macOS

Co-developed-by: Vladimir Still <git@vstill.eu>
Co-developed-by: David Bolvansky <david.bolvansky@intel.com>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>

* Add note about Protobuf & CMake on macOS in README

Co-developed-by: Vladimir Still <git@vstill.eu>
Co-developed-by: David Bolvansky <david.bolvansky@intel.com>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>

* Fix typo, add link to homebrew PR

---------

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Co-authored-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
  • Loading branch information
vlstill and rst0git authored Feb 16, 2023
1 parent daa55c8 commit 341079a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
- name: Run tests (Ubuntu 18.04)
run: |
sudo -E docker run --privileged -w /p4c/build -e $CTEST_PARALLEL_LEVEL p4c ctest --output-on-failure --schedule-random
# Build and test p4c on Fedora.
test-fedora-linux:
strategy:
Expand Down Expand Up @@ -205,8 +205,19 @@ jobs:
echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH
- name: Build (MacOS)
# for some reason, brew does not install protobuf in a way cmake would be
# able to find it. Also, the library needs to be specified manually in
# order for the compiler to be correctly linked with protobuf.
# Also, there are no static protobuf libs in homebrew.
# See also https://github.com/Homebrew/homebrew-core/pull/122277
run: |
./bootstrap.sh -DENABLE_GC=ON -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_UNIFIED_COMPILATION=ON && cd build && make -j2
PROTOBUF=`brew --prefix --installed protobuf`
./bootstrap.sh -DENABLE_GC=ON -DCMAKE_BUILD_TYPE=RELEASE \
-DENABLE_UNIFIED_COMPILATION=ON \
-DProtobuf_INCLUDE_DIR=$PROTOBUF/include \
-DProtobuf_LIBRARY=$PROTOBUF/lib/libprotobuf.dylib \
-DENABLE_PROTOBUF_STATIC=OFF
make -Cbuild -j2
- name: Run tests (MacOS)
# TODO: Renable gtest. Unit tests currently fail on MacOS.
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The code contains seven sample backends:
https://doc.dpdk.org/guides/rel_notes/release_20_11.html,
* p4c-ebpf: can be used to generate C code which can be compiled to [eBPF](https://en.wikipedia.org/wiki/Berkeley_Packet_Filter)
and then loaded in the Linux kernel. The eBPF backend currently implements two architecture models:
[ebpf_model.p4 for packet filtering](./backends/ebpf/README.md) and [the fully-featured PSA (Portable Switch Architecture) model](./backends/ebpf/psa/README.md).
[ebpf_model.p4 for packet filtering](./backends/ebpf/README.md) and [the fully-featured PSA (Portable Switch Architecture) model](./backends/ebpf/psa/README.md).
* p4test: a source-to-source P4 translator which can be used for
testing, learning compiler internals and debugging,
* p4c-graphs: can be used to generate visual representations of a P4 program;
Expand Down Expand Up @@ -346,6 +346,18 @@ Installing on macOS:
out the newest tag in the 3.0 series (`v3.0.2` as of this writing) before you
build.

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
that manually installed Protobuf will require similar treatment.

```
PB_PREFIX="$(brew --prefix --installed protobuf)"
./bootstrap.sh \
-DProtobuf_INCLUDE_DIR="${PB_PREFIX}/include/" \
-DProtobuf_LIBRARY="${PB_PREFIX}/lib/libprotobuf.dylib" \
-DENABLE_PROTOBUF_STATIC=OFF
```

## Garbage collector

P4c relies on [BDW garbage collector](https://github.com/ivmai/bdwgc)
Expand Down

0 comments on commit 341079a

Please sign in to comment.