8000 Fix CMake build support by sudhanshu112233shukla · Pull Request #1303 · p4lang/behavioral-model · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix CMake build support #1303

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

sudhanshu112233shukla
Copy link
Contributor

This PR implements a comprehensive CMake build system for the behavioral-model project, providing an alternative to the existing autotools build system while maintaining full compatibility with all supported platforms.

Key changes:

  • Added top-level CMakeLists.txt with project configuration, version extraction from VERSION file, and build options matching the autotools configuration
  • Created FindThrift.cmake and FindgRPC.cmake modules to properly detect and configure external dependencies
  • Implemented directory-specific CMakeLists.txt files for all major components (src, third_party, include, tests, targets, tools)
  • Added proper dependency management with imported targets for cleaner build definitions
  • Maintained feature parity with all autotools build options:
    • WITH_NANOMSG, WITH_THRIFT, WITH_PI, WITH_PDFIXED, WITH_TARGETS
    • ENABLE_DEBUGGER, ENABLE_COVERAGE, ENABLE_LOGGING_MACROS, ENABLE_ELOGGER
    • ENABLE_MODULES, ENABLE_UNDETERMINISTIC_TESTS, ENABLE_WERROR, ENABLE_WP4_16_STACKS
  • Added platform-specific configurations to ensure compatibility across Linux, macOS, and Windows
  • Created detailed documentation for building with CMake in README.cmake.md
  • Added CI workflow configuration to test the CMake build in various configurations

The implementation ensures that all existing functionality works correctly with the new build system, and all tests pass. This provides developers with a modern, cross-platform build alternative while maintaining backward compatibility.

Fixes #1254

@@ -1,36 +0,0 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove these?

Copy link
Contributor Author
@sudhanshu112233shukla sudhanshu112233shukla Apr 27, 2025

Choose a reason for hiding this comment

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

The removal of install_deps.sh was unintentional sir. This script is essential for setting up the build environment and installing dependencies, regardless of whether we're using autotools or CMake for building. I'll restore this file in the next revision of the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert the file to the original version please? The blank line changes are just adding unnecessary noise to the PR. (I suggest a separate PR if you're wanting to adjust whitespace for readability.)

README.md Outdated
@@ -1,340 +0,0 @@
# BEHAVIORAL MODEL (bmv2)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not remove the top level README.md file.

If parts of its contents should change because of changes in the rest of your PR, then please do propose changes to it.

10000
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure sir I'll do it soon.

@jafingerhut
Copy link
Contributor

It looks like cmake is not installed, is the reason for two of the failing CI tests. Probably there needs to be some sudo apt install -y cmake added somewhere early in the build scripts to enable those tests to progress further.

The DCO check is also failing. If you look at this PR's Github page, and click on the line for the "DCO" test, it gives detailed instructions on how you can enbale that check to pass.

@sudhanshu112233shukla
Copy link
Contributor Author

It looks like cmake is not installed, is the reason for two of the failing CI tests. Probably there needs to be some sudo apt install -y cmake added somewhere early in the build scripts to enable those tests to progress further.

The DCO check is also failing. If you look at this PR's Github page, and click on the line for the "DCO" test, it gives detailed instructions on how you can enbale that check to pass.

sure sir i will fix it soon...

echo "Adding cmake repository..."
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo apt-add-repository -y ppa:kitware/cmake
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to add this repository? cmake should be in the default repositories for Ubuntu 22.04/24.04

And you're doing an install of cmake in the cmake.yml workflow without adding a new ppa.


jobs:
build:
runs-on: ubuntu-20.04
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to build on 20.04? The existing tests are using either ubuntu-latest or ubuntu-22.04

name: ${{ matrix.config.name }}

steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move to v4 to use the same version as the other workflows.
May need to add:

      with:
        submodules: recursive

Copy link
Contributor Author
@sudhanshu112233shukla sudhanshu112233shukla May 25, 2025

Choose a reason for hiding this comment

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

sure sir !I’ll update actions/checkout to v4 and include submodules: recursive to align with the other workflow.

@@ -38,16 +38,42 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Install system dependencies
run: |
echo "Adding cmake repository..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you doing cmake installation here and not in the Dockerfile(s)?

Comment on lines 67 to 72
- name: Prepare build directory
run: |
docker run --rm -w /behavioral-model bm /bin/bash -c "
mkdir -p build &&
cd build &&
cmake -DWITH_PDFIXED=ON -DWITH_PI=ON -DWITH_STRESS_TESTS=ON -DENABLE_DEBUGGER=ON -DENABLE_WERROR=ON -DENABLE_COVERAGE=$GCOV .."
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already handled in the Dockerfile?

@@ -0,0 +1,43 @@
# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to include the current source dir?
Applies to all the other target CMakeLists.txt files.

# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need the current binary dir?

)

# Create l2_switch executable
add_executable(l2_switch
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you hitting any issue having a library and executable with the same name? A Google search indicates that this used to be a problem -- but perhaps its not any more?

This was the recommended solution for having a library and executable with the same name: https://discourse.cmake.org/t/how-to-use-the-same-name-for-a-target-and-a-library/5044

@@ -0,0 +1,16 @@
# spdlog is a header-only library, so we just need to install the headers
file(GLOB_RECURSE SPDLOG_HEADERS "bm/spdlog/*.h" "bm/spdlog/*.cc")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this doing anything? I don't see SPDLOG_HEADERS used anywhere.

Comment on lines 31 to 32
${THRIFT_GEN_CPP_DIR}/Standard.cpp
${THRIFT_GEN_CPP_DIR}/Standard.h
Copy link
Contributor

Choose a reason for hiding this comment

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

These files will appear multiple times in the ALL_THRIFT_CPP_FILES var (once for each iteration). Should we care? Probably not too dangerous as it is only being used in the add_library call.

@grg
Copy link
Contributor
grg commented May 7, 2025

A few high-level comments from my initial review:

  • It looks like you've committed a testing version of the top-level CMakeLists.txt -- the current one isn't pulling in the cmake files from child directories.
  • The docker/github workflow files need a little cleanup.
  • You've committed a few local test files that should be removed.

@grg
Copy link
Contributor
grg commented May 29, 2025

@sudhanshu112233shukla I'd started looking at addressing some of the build issues since you were busy wrapping up your semester.

Changes I'd made are in: #1305
Let me know if you'd like to sync up on the changes.

(At least one of your changes from today has gone a bit too far: you've replaced some ubuntu-latest with ubuntu-22.04 in the test.yaml file.)

@sudhanshu112233shukla
Copy link
Contributor Author

@sudhanshu112233shukla I'd started looking at addressing some of the build issues since you were busy wrapping up your semester.

Changes I'd made are in: #1305 Let me know if you'd like to sync up on the changes.

(At least one of your changes from today has gone a bit too far: you've replaced some ubuntu-latest with ubuntu-22.04 in the test.yaml file.)

yes sir !!

(At least one of your changes from today has gone a bit too far: you've replaced some ubuntu-latest with ubuntu-22.04 in the test.yaml file.)

yes sir!!

i saw those changes soon i will review it.

i just saw that , i fix it soon

@grg grg mentioned this pull request Jun 2, 2025
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
…nstallation - Update Ubuntu version to 22.04 - Update actions/checkout to v4 - Add submodules: recursive - Add parallel build with -j

Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
sudhanshu112233shukla and others added 3 commits June 11, 2025 07:52
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
… handling

Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
Signed-off-by: sudhanshu shukla <161225935+sudhanshu112233shukla@users.noreply.github.com>
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.

CMake support
4 participants
0