C/C++ Backend #15499
Replies: 5 comments 11 replies
-
For third-party package management....maybe we use a distinct backend per ecosystem that you explicitly opt into? I've never done third-party stuff w/ C/C++, would you ever mix package managers in a project? If not, can you envision having multiple projects in a repo, each w/ a different package manager? -- For test runners, I at first was going to suggest a similar idea. Have a Buf oof that's a lot of targets, especially when you add target generators. I suspect the metadata is similar with all the test runners, like a I'm not sure how each test runner knows whether to run on a -- For compiler/toolchains, would something like JVM and Python's resolves make sense? https://www.pantsbuild.org/v2.11/docs/python-third-party-dependencies#multiple-lockfiles |
Beta Was this translation helpful? Give feedback.
-
I recently came along a post on hackernews about Uber using Zig's compiler tools to build their C/C++. Reasons are Zig's cross compilation story, having a linker on their own. Zig is known to improve cross compilation with Go and Rust FFI as well. Added the adoption and support from Uber (support contract with Zig foundation) along with another big tech does secure long term support. Maybe this is a compelling reason to favor Zig over Clang/GCC. Any opinions on that? |
Beta Was this translation helpful? Give feedback.
-
Throwing an idea into the void... For "CMake-support" - instead of calling into cmake, maybe this plugin would enhance the Tailor command to auto-generate a reasonable equivalent? Maybe even both, anyways... It's hard (to the point of not trying) to parse any/every CMakeLists file into a BUILD, but the 80/20 approach feels like a layup. Get the sources all in, create libraries/executables, a bunch of compiler options - and stop there. |
Beta Was this translation helpful? Give feedback.
-
I am also very interested in a possible C/C++ backend, hence my thoughts below. I suggest it would make sense to integrate CMake/CTest/CPack (priority in this order) without any package managers first. Package Managers in the C/C++ are mostly inexistent (no common understanding or standards) and probably Pants should (partially) take the role of a PM, at least for dependency resolution. CMake Build supportPants should provide a way to configure CMake and it's possible Options (-Dxxx) or maybe more flexible via the new CMake preset mechanism: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html Dependency resolutionFor a CMake project to find it's dependencies there are sadly too many mechanisms as there is a long legacy. The most often used are however the CMake native Config Mode: https://cmake.org/cmake/help/latest/command/find_package.html using *Config.cmake files and also pkg-config *.pc files: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html?highlight=pkg%20config#module:FindPkgConfig. They are created by the CMake build in the "install" target. The install place however has to be managed and injected by Pants, best handled by the DESTDIR environment variable: DESTDIR Toolchain/SDKOn the toolchain side the most generic way I could think of is along the way Yocto and also e.g. GNU does it, is by defining a build environment by setting ENV variables: CC/CXX/CPP/..., and everything else needed for a specific toolchain. Often SDKs have environment setup scripts which can be sourced prior to building. I am not sure how to handle these, but somehow I think Pants should just require the correct build environment to be set prior to execute Pants and thus respect it. This however only works if the complete build is for a single target w/o building native tools. Otherwise Pants has to set the correct environment and needs a mechanism for this. Probably also best using these environment setup scripts provided by the SDK. Future integration/introspectionThe described CMake integration above is by creating the respective "goals" on the commandline. Edit: just found out CMake server mode is removed from new versions, new API ist the file API: https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#manual:cmake-file-api(7) Edit 2: reading the CMake File API docs it seems to me that using the File API would be a natural addition to the commandline integration described above, to get more insight into the CMake Project. That means it wouldn't take another approach, but can be added and thus build on the work already done. |
Beta Was this translation helpful? Give feedback.
-
Closing this as "resolved" for the most part, I think the rest of the discussion will happen with PRs and during the experimental CC phase. |
Beta Was this translation helpful? Give feedback.
-
C/C++ Backend
Preamble
There is no explicit proposal below.
This is intended to be a bit of a brain dump and request for ideas/opinions/thoughts on creating a compilation and packaging workflow for the C and C++ backend(s). At the moment, there exists the recently added
cc_sources
target and ClangFormat plugin.My hope is that we can come up with some ideas on each of the following topics, to provide a path forward on each high-level subject and incrementally build out the backend(s).
While the CC backend is in experimental, I think two reasonable user/project-types to cater towards are:
Conveniently, I happen to be in both of these camps... What are the odds? :)
There exists another category of projects, with users actively looking for a new build solution to replace theirs - but these tend to be rare, and usually live in the edge-cases with what they require (eclectic compilers, super-massive repos, less common CPU architectures, etc...). I wouldn't recommend spending much time targeting these workflows, even though, I again happen to be in this category for one isolated project.
Compilers/Toolchains:
How are they installed/called?
Should they be specified per target or globally?
Package Management
Package management is a hot sloppy mess in C/C++ land.
single file headers
git subrepos/subtrees
conan
vcpkg
pmm
buckaroo
...
What is the recommend approach for projects that use 3rd party PM tools?
Linters/Formatters:
gcc
,clang
/llvm
may need to be downloaded regardlessUnit Testing
While not as bad as package management, there are several oft-used testing tools (excluding mocking tools):
Catch
Google Test
Boost.Test
CppUnit
CUnit
Do we need to support selecting a test runner as a plugin?
Compilation/Linking flags and options
There should be an option to set these types of flags globally, and then override them per target.
Build Generators
Is it worth considering exporting to Makefiles or .ninja files (ala CMake)?
Potential next step?
Create a CMake plugin to help with the "existing project" workflow as described above. Aiming for a "just works" solution for the user, with minimal BUILD intervention.
CMake plugin would essentially call down into cmake/ctest/cpack/etc, pass along some configuration items, and define the destination directory for the
install
command. Not very Pants-y internal to the C/C++ code, however, it would allow monorepo integration (like an outside-in approach to development).Target Types (WIP)
How are transitive dependencies handled? Do the settings flow through, or do we need target-limited equivalents
How do private/public headers fit in?
How are public headers published (in the digest?)?
How do single-file headers or pre-compiled sources fit in?
Option de-duplication?
cc_library
? compile options, linker options, static/shared link, source files, libraries, headers
dependencies
compile_options
- string list of compile options, added to the existing toolchain optionslink_options
- string list of linker options, added to the existing toolchain optionsdefines
- string list of defines to add to compilation, prepended with (-D) unless it is already therecc_binary
? compile options, linker options, source files, libraries, headers
dependencies
compile_options
- string list of compile options, added to the existing toolchain optionslink_options
- string list of linker options, added to the existing toolchain optionsdefines
- string list of defines to add to compilation, prepended with (-D) unless it is already therecc_test
References
Adding a New Language to Pants
Beta Was this translation helpful? Give feedback.
All reactions