Skip to content
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

Fix P4C extension boilerplate CI build & test issue #32

Closed
wants to merge 6 commits into from

Conversation

qobilidop
Copy link
Member

No description provided.


# FIXME: This is a temporary hack. With our current CMake configs, somehow
# p4mlir-opt ended up in this directory.
tool_dirs += [os.path.join(config.p4c_binary_dir, "bin")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is fixed by https://github.com/p4lang/p4mlir-incubator/pull/7/files#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR12 or some additional changes in third-party/llvm/CMakeLists.txt in the same PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Let me take a look.

Copy link
Member Author

@qobilidop qobilidop Jan 28, 2025

Choose a reason for hiding this comment

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

I'm still not able to resolve this. If you are also okay with it, I suggest we leave this as a TODO. So we can re-enable CI test on other PRs sooner.

@qobilidop
Copy link
Member Author

Somehow the build-and-test check is not automatically triggered after pushing more commits. I've manually triggered it in https://github.com/p4lang/p4mlir-incubator/actions/runs/12983849029/job/36236520316.

@qobilidop
Copy link
Member Author

Somehow the build-and-test check is not automatically triggered after pushing more commits. I've manually triggered it in https://github.com/p4lang/p4mlir-incubator/actions/runs/12983849029/job/36236520316.

Well, that doesn't seem to be testing the latest commit. Let me try using #33.

@qobilidop
Copy link
Member Author

https://github.com/p4lang/p4mlir-incubator/actions/runs/12994911907/job/36240417411#step:9:12345

+ ninja check-p4mlir
[0/1] Running the P4MLIR regression tests
-- Testing: 2 tests, 2 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Testing Time: 0.04s

Total Discovered Tests: 2
  Passed: 2 (100.00%)

Now the CI test can pass!

I'll take another look at the CMake hack issue after work today.

@qobilidop qobilidop requested a review from fruffy January 27, 2025 19:26
@asl
Copy link
Collaborator

asl commented Jan 27, 2025

Now the CI test can pass!

I'll take another look at the CMake hack issue after work today.

Still, it seems you returned to the old way of building LLVM separately rather than doing it as a sub-project. I found the former approach quite error-prone during development:

  • It could peek "wrong" LLVM build that might happen to be on developer's machine (and I do have lots of different LLVM trees locally, for now we stick to LLVM 19 release)
  • We need to build LLVM in non-default mode (need to have both RTTI and EH enabled as P4C relies on them and this is an ABI-breaking change, you cannot mix and match things).

Note that after https://github.com/p4lang/p4mlir-incubator/pull/7/files everything is supposed to work if the code is just dropped into extensions subdir of P4C, it would just build LLVM as a necessary dependency with all required options and propagate stuff further. We'd also just stash whole P4C with all dependencies into the cache there.

CMakeLists.txt Outdated Show resolved Hide resolved
@qobilidop
Copy link
Member Author

@asl Thanks for your comments!

The main reason I switched back to the old CMake config was to start from a known working state to better isolate CI issues. Now that things are working in CI, I'm taking another look at CMake changes in #3 and #7.

I have to admit that my knowledge on CMake is quite limited. So I still don't fully understand some of your comments. Let me explain my current understanding below, and maybe you can help me clarify my misunderstandings.

Overall, I was following the out-of-tree component build approach from the MLIR standalone example. I noticed that this approach is used in some popular MLIR-based projects, like CIRCT. So I was assuming it is a solid approach and just went with it.

Still, it seems you returned to the old way of building LLVM separately rather than doing it as a sub-project. I found the former approach quite error-prone during development:

  • It could peek "wrong" LLVM build that might happen to be on developer's machine (and I do have lots of different LLVM trees locally, for now we stick to LLVM 19 release)

I thought we could specify local LLVM locations when building an out-of-tree MLIR project, by passing in some CMake options, like the following:

cmake -G Ninja "$P4MLIR_REPO_DIR" \
-DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_DIR" \
-DMLIR_DIR="$LLVM_INSTALL_DIR"/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT="$LLVM_BUILD_DIR"/bin/llvm-lit

Or maybe that's not enough?

  • We need to build LLVM in non-default mode (need to have both RTTI and EH enabled as P4C relies on them and this is an ABI-breaking change, you cannot mix and match things).

Is that achievable with the out-of-tree approach as well? We currently have the following script for building LLVM/MLIR:

cmake -G Ninja "$LLVM_REPO_DIR"/llvm \
-DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_DIR" \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_TARGETS_TO_BUILD="Native" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON \
-DLLVM_CCACHE_BUILD=ON \
-DLLVM_INSTALL_UTILS=ON

I imagine we could tweak CMake options here to enable RTTI and EH, right?

Note that after https://github.com/p4lang/p4mlir-incubator/pull/7/files everything is supposed to work if the code is just dropped into extensions subdir of P4C, it would just build LLVM as a necessary dependency with all required options and propagate stuff further. We'd also just stash whole P4C with all dependencies into the cache there.

Then it seems to make more sense to rebase this PR to #7. I'll try it.

@qobilidop qobilidop changed the base branch from boilerplate to mlir-basic January 28, 2025 08:08
@@ -1,15 +1,45 @@
cmake_minimum_required(VERSION 3.20.0)
project(p4mlir LANGUAGES CXX)

add_subdirectory(third_party)
# TODO: Consider unify the build process and remove this option.
option(BUILD_P4MLIR_OUT_OF_TREE "Whether to build P4MLIR out-of-tree" OFF)
Copy link
Member Author

Choose a reason for hiding this comment

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

@asl How about making out-of-tree build optional for now? This way your local development workflow won't be disrupted. And our current CI build scripts also work.

@qobilidop
Copy link
Member Author

This is superseded by #46.

@qobilidop qobilidop closed this Jan 31, 2025
@qobilidop qobilidop deleted the boilerplate-ci-fix branch February 1, 2025 18:35
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.

2 participants