build: add Meson build support and export a C++20 module interface - #240
build: add Meson build support and export a C++20 module interface#240lozkoev wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughThe pull request adds a C++20 ChangesC++20 module and build integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CMake
participant miniocpp_target
participant Install
CMake->>miniocpp_target: Register modules/miniocpp.cc for C++20
miniocpp_target->>Install: Install the CXX_MODULES file set
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@meson.build`:
- Line 1: Update the project configuration in meson.build to require C++20 for
the miniocpp module build, and make the cpp_args setting conditional so
/interface is supplied only when meson.get_compiler('cpp').get_id() is msvc; use
no MSVC-specific flag for GCC or native Clang builds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 229fd75c-ae3d-4238-a93b-13861489acae
📒 Files selected for processing (4)
CMakeLists.txtmeson.buildminiocpp.pc.inmodules/miniocpp.cc
| @@ -0,0 +1,56 @@ | |||
| project('miniocpp', 'cpp', version : '0.4.0') | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check that the module target requires C++20 and scopes MSVC-only flags.
rg -n -C 3 "project\\(|cpp_std|miniocpp_module|cpp_args|/interface|cxx\\.get_id" meson.build
# Expected:
# - C++20 is selected for the module build.
# - `/interface` appears only in an MSVC compiler-ID condition.Repository: minio/minio-cpp
Length of output: 757
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== meson.build =="
cat -n meson.build
echo
echo "== module source excerpt =="
if [ -f modules/miniocpp.cc ]; then
sed -n '1,120p' modules/miniocpp.cc
fi
echo
echo "== Meson compatibility docs in repo =="
fd -a 'meson|README|BUILD' . | sed 's#^\./##' | head -20Repository: minio/minio-cpp
Length of output: 3054
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== README build sections =="
sed -n '1,240p' README.md | rg -n -C 4 -i "meson|build|install|module|cpp standard|c++20|clang|gcc|msvc|visual studio|interface" || true
echo
echo "== docs README =="
if [ -f docs/README.md ]; then sed -n '1,240p' docs/README.md; fiRepository: minio/minio-cpp
Length of output: 6766
🌐 Web query:
Meson cpp_std c++20 project cpp
💡 Result:
To specify the C++20 standard in a Meson project, you should set the cpp_std option within the project() function call in your meson.build file [1][2]. The standard approach is to use the default_options argument [2]: project('my_project', 'cpp', default_options: ['cpp_std=c++20']) Advanced Configuration with Fallbacks Since Meson 1.3.0, cpp_std supports a list of values to handle cross-compiler compatibility [3]. If you want to use C++20 but allow fallbacks if the compiler does not support it, you can provide a prioritized list [4][3]: project('my_project', 'cpp', default_options: ['cpp_std=c++20,c++17']) Meson will select the first standard in the list that the current compiler supports [4][5][3]. Alternative Methods Per-Target Override: You can override the C++ standard for a specific target by using override_options [2]: executable('my_target', 'main.cpp', override_options: ['cpp_std=c++20']) Command Line: You can also change the standard during the configuration phase using the command line [6]: meson setup builddir -Dcpp_std=c++20 Note that while c++20 is the standard ISO designation, some compiler-specific values (like vc++20 for MSVC or gnu++20 for GNU-extended C++20) are available if specific compiler features or extensions are required [1][7]. However, c++20 is the recommended portable choice for modern projects [3].
Citations:
- 1: https://mesonbuild.com/Builtin-options.html
- 2: https://mesonbuild.com/howtox.html
- 3: https://github.com/mesonbuild/meson/blob/a6c976da/docs/markdown/Builtin-options.md
- 4: https://www.scivision.dev/meson-cpp-standard/
- 5: c_std, cpp_std: Change to a list of desired versions in preference order mesonbuild/meson#10332
- 6: https://stackoverflow.com/questions/43299413/setting-compiler-right-for-meson
- 7: https://github.com/mesonbuild/meson/blob/a6c976da/mesonbuild/compilers/cpp.py
Set C++20 and limit /interface to MSVC.
modules/miniocpp.cc uses a C++20 named module, but meson.build does not select cpp20. Line 49 also passes the MSVC-only /interface option for every compiler, so GCC/native Clang Meson builds fail with an invalid compiler flag. Add cpp_std=c++20 for this module build and set cpp_args to /interface only when meson.get_compiler('cpp').get_id() == 'msvc'.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@meson.build` at line 1, Update the project configuration in meson.build to
require C++20 for the miniocpp module build, and make the cpp_args setting
conditional so /interface is supplied only when
meson.get_compiler('cpp').get_id() is msvc; use no MSVC-specific flag for GCC or
native Clang builds.
What
meson.build(and a Meson-native.wrap-friendly layout) so thislibrary can be consumed directly by Meson-based projects, without going
through CMake at all.
modules/miniocpp.cc- a C++20 module interface (export module miniocpp;) that re-exports the public API (minio::s3::Client,BaseUrl,BucketExistsArgs/BucketExistsResponse,minio::creds:: StaticProvider,minio::Result), so consumers canimport miniocpp;instead of
#include <miniocpp/client.h>.miniocppCMake target viaFILE_SET CXX_MODULES(CMake 3.28+), gated behindMINIO_CPP_STD=20andthe CMake version check, so CMake/MSBuild consumers get
import miniocpp;too, not only Meson ones.
miniocpp.pc.in: the generated.pchad an emptyRequires:field,so pkg-config consumers never picked up curlpp/OpenSSL/pugixml/zlib
transitively and failed to link. Added the missing
Requires:.Why
Building this project with Meson previously required either wrapping it
in a manual
dependency(method: 'pkg-config')/method: 'cmake'call withhand-written link flags (fragile, breaks whenever a dependency version
changes), or going through
cmake.subproject(), which currently dropsinclude paths that live outside the subproject's own directory tree - a
known Meson limitation (see mesonbuild/meson#12451, #6079, #12351) that
makes it unusable for a library with external (e.g. vcpkg) dependencies.
A real
meson.buildavoids both problems.The module interface is a small addition on top since C++20 modules are
increasingly the expected way to consume a library that already supports
C++20 (
MINIO_CPP_STD=20, added in #237).Example usage
Testing
MINIO_CPP_STD=20):FILE_SET CXX_MODULESpath)subproject('minio-cpp'), full source build, not the vcpkgbinary package)
check-style.shclean (clang-format --style=Google)check-version.pypasses (no version bump in this change)MINIO_CPP_ENABLE_RDMAstill defaultsOFF; module/Meson additions don't touch it)
Summary by CodeRabbit
New Features
Bug Fixes
Build & Installation