From cec7b6bd2cab4a9ce5b75e65451916b527e218d1 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Sat, 20 Jun 2026 17:05:33 +0800 Subject: [PATCH 1/2] Add coverage for freestanding --- .bazelrc | 4 + .github/workflows/bvt-appleclang.yml | 31 ++++--- .github/workflows/bvt-clang.yml | 36 ++++++--- .github/workflows/bvt-compatibility.yml | 12 ++- .github/workflows/bvt-gcc.yml | 36 ++++++--- .github/workflows/bvt-msvc.yml | 20 ++--- .github/workflows/bvt-nvhpc.yml | 20 ++--- .github/workflows/bvt-oneapi.yml | 36 ++++++--- CMakeLists.txt | 58 +++++++++----- CMakePresets.json | 55 +++++++++++++ README.md | 6 +- include/proxy/v4/proxy.ixx | 10 ++- meson.build | 80 ++++++++++++------- meson.options | 6 ++ tests/BUILD.bazel | 10 +-- tests/CMakeLists.txt | 24 ------ tests/freestanding/CMakeLists.txt | 26 ++++++ tests/freestanding/meson.build | 13 +++ .../proxy_freestanding_module_tests.cpp | 52 ++++++++++++ tests/meson.build | 34 -------- 20 files changed, 379 insertions(+), 190 deletions(-) create mode 100644 CMakePresets.json create mode 100644 tests/freestanding/CMakeLists.txt create mode 100644 tests/freestanding/meson.build create mode 100644 tests/freestanding/proxy_freestanding_module_tests.cpp diff --git a/.bazelrc b/.bazelrc index 0850c0e..469834a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -5,6 +5,10 @@ common --enable_platform_specific_config # Default Build Options build --features=external_include_paths +# Freestanding Configuration +build:freestanding --cxxopt=-ffreestanding --cxxopt=-fno-exceptions --cxxopt=-fno-rtti +build:freestanding --linkopt=-nodefaultlibs --linkopt=-lc + # Platform-Specific Toolchain Overrides build:linux --repo_env=BAZEL_CXXOPTS=-std=c++20 build:macos --repo_env=BAZEL_CXXOPTS=-std=c++20 diff --git a/.github/workflows/bvt-appleclang.yml b/.github/workflows/bvt-appleclang.yml index 94952c8..5134313 100644 --- a/.github/workflows/bvt-appleclang.yml +++ b/.github/workflows/bvt-appleclang.yml @@ -22,26 +22,37 @@ jobs: - name: Build and run test with AppleClang on cmake run: | - cmake -B build-cmake -GNinja -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release -DPROXY_BUILD_MODULES=FALSE - cmake --build build-cmake -j - ctest --test-dir build-cmake -j - mkdir build-cmake/drop - bash ./tools/dump_build_env.sh c++ build-cmake/drop/env-info.json + cmake --preset default -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=FALSE + cmake --build --preset default -j + ctest --preset default -j + mkdir build/cmake/drop + bash ./tools/dump_build_env.sh c++ build/cmake/drop/env-info.json + + - name: Build and run freestanding test with AppleClang on cmake + run: | + cmake --preset freestanding -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=FALSE + cmake --build --preset freestanding -j + ctest --preset freestanding -j - name: Build and run test with AppleClang on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true + + - name: Build and run freestanding test with AppleClang on meson + run: | + meson setup build/meson-freestanding --buildtype=release -Dfreestanding=true + meson test -C build/meson-freestanding - name: Build and Run test with AppleClang on bazel run: bazel test --lockfile_mode=error //tests:proxy_tests //benchmarks:proxy_benchmarks //docs/... - name: Run benchmarks - run: build-cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake/drop/benchmarking-results.json + run: build/cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-appleclang - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/.github/workflows/bvt-clang.yml b/.github/workflows/bvt-clang.yml index c015a07..ab728dc 100644 --- a/.github/workflows/bvt-clang.yml +++ b/.github/workflows/bvt-clang.yml @@ -34,26 +34,40 @@ jobs: - name: Build and run test with clang ${{ env.CLANG_VERSION }} on cmake run: | - cmake -B build-cmake -GNinja -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release -DPROXY_BUILD_MODULES=TRUE - cmake --build build-cmake -j - ctest --test-dir build-cmake -j - mkdir build-cmake/drop - bash ./tools/dump_build_env.sh "$CXX" build-cmake/drop/env-info.json + cmake --preset default -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE + cmake --build --preset default -j + ctest --preset default -j + mkdir build/cmake/drop + bash ./tools/dump_build_env.sh "$CXX" build/cmake/drop/env-info.json + + - name: Build and run freestanding test with clang ${{ env.CLANG_VERSION }} on cmake + run: | + cmake --preset freestanding -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE + cmake --build --preset freestanding -j + ctest --preset freestanding -j - name: Build and run test with clang ${{ env.CLANG_VERSION }} on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true + + - name: Build and run freestanding test with clang ${{ env.CLANG_VERSION }} on meson + run: | + meson setup build/meson-freestanding --buildtype=release -Dfreestanding=true + meson test -C build/meson-freestanding - name: Build and Run test with clang ${{ env.CLANG_VERSION }} on bazel - run: bazel test --lockfile_mode=error //tests:proxy_tests //tests:proxy_freestanding_tests //benchmarks:proxy_benchmarks //docs/... + run: bazel test --lockfile_mode=error //tests:proxy_tests //benchmarks:proxy_benchmarks //docs/... + + - name: Build and run freestanding test with clang ${{ env.CLANG_VERSION }} on bazel + run: bazel test --config=freestanding --lockfile_mode=error //tests:proxy_freestanding_tests - name: Run benchmarks - run: build-cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake/drop/benchmarking-results.json + run: build/cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-clang - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/.github/workflows/bvt-compatibility.yml b/.github/workflows/bvt-compatibility.yml index 0dca8d6..5f3c424 100644 --- a/.github/workflows/bvt-compatibility.yml +++ b/.github/workflows/bvt-compatibility.yml @@ -53,6 +53,12 @@ jobs: - name: Build and run test with cmake run: | - cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Release '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' - cmake --build build -j - ctest --test-dir build -j + cmake --preset default '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' + cmake --build --preset default -j + ctest --preset default -j + + - name: Build and run freestanding test with cmake + run: | + cmake --preset freestanding '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' + cmake --build --preset freestanding -j + ctest --preset freestanding -j diff --git a/.github/workflows/bvt-gcc.yml b/.github/workflows/bvt-gcc.yml index b217468..7a733ac 100644 --- a/.github/workflows/bvt-gcc.yml +++ b/.github/workflows/bvt-gcc.yml @@ -27,27 +27,41 @@ jobs: - name: Build and run test with gcc 15 on cmake run: | - cmake -B build-cmake -GNinja -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release -DPROXY_BUILD_MODULES=TRUE - cmake --build build-cmake -j - ctest --test-dir build-cmake -j - mkdir build-cmake/drop + cmake --preset default -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE + cmake --build --preset default -j + ctest --preset default -j + mkdir build/cmake/drop chmod +x tools/dump_build_env.sh - ./tools/dump_build_env.sh g++ build-cmake/drop/env-info.json + ./tools/dump_build_env.sh g++ build/cmake/drop/env-info.json + + - name: Build and run freestanding test with gcc 15 on cmake + run: | + cmake --preset freestanding -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE + cmake --build --preset freestanding -j + ctest --preset freestanding -j - name: Build and run test with gcc 15 on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true + + - name: Build and run freestanding test with gcc 15 on meson + run: | + meson setup build/meson-freestanding --buildtype=release -Dfreestanding=true + meson test -C build/meson-freestanding - name: Build and Run test with gcc 15 on bazel - run: bazel test --lockfile_mode=error //tests:proxy_tests //tests:proxy_freestanding_tests //benchmarks:proxy_benchmarks //docs/... + run: bazel test --lockfile_mode=error //tests:proxy_tests //benchmarks:proxy_benchmarks //docs/... + + - name: Build and run freestanding test with gcc 15 on bazel + run: bazel test --config=freestanding --lockfile_mode=error //tests:proxy_freestanding_tests - name: Run benchmarks - run: build-cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake/drop/benchmarking-results.json + run: build/cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-gcc - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/.github/workflows/bvt-msvc.yml b/.github/workflows/bvt-msvc.yml index 3e36074..c741d8c 100644 --- a/.github/workflows/bvt-msvc.yml +++ b/.github/workflows/bvt-msvc.yml @@ -22,26 +22,26 @@ jobs: - name: Build and run test with MSVC on cmake run: | - cmake -B build-cmake -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE ` - && cmake --build build-cmake --config Release -j ` - && ctest --test-dir build-cmake -C Release -j ` - && mkdir build-cmake\drop > $null ` - && .\tools\dump_build_env_msvc.ps1 -OutputPath build-cmake\drop\env-info.json + cmake -B build/cmake -DCMAKE_CXX_STANDARD=23 -DPROXY_BUILD_MODULES=TRUE ` + && cmake --build build/cmake --config Release -j ` + && ctest --test-dir build/cmake -C Release -j ` + && mkdir build/cmake/drop > $null ` + && .\tools\dump_build_env_msvc.ps1 -OutputPath build/cmake/drop/env-info.json - name: Build and run test with MSVC on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled --vsenv - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled --vsenv + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true - name: Build and Run test with MSVC on bazel run: bazel test --lockfile_mode=error //tests:proxy_tests //benchmarks:proxy_benchmarks //docs/... - name: Run benchmarks - run: build-cmake\benchmarks\Release\msft_proxy_benchmarks.exe --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake\drop\benchmarking-results.json + run: build/cmake/benchmarks/Release/msft_proxy_benchmarks.exe --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-msvc - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/.github/workflows/bvt-nvhpc.yml b/.github/workflows/bvt-nvhpc.yml index 823218d..51d0350 100644 --- a/.github/workflows/bvt-nvhpc.yml +++ b/.github/workflows/bvt-nvhpc.yml @@ -37,24 +37,24 @@ jobs: - name: Build and run test with NVHPC ${{ env.NVHPC_VERSION }} on cmake run: | - cmake -B build-cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DPROXY_BUILD_MODULES=FALSE - cmake --build build-cmake -j - ctest --test-dir build-cmake -j - mkdir build-cmake/drop + cmake --preset default -DPROXY_BUILD_MODULES=FALSE + cmake --build --preset default -j + ctest --preset default -j + mkdir build/cmake/drop chmod +x tools/dump_build_env.sh - ./tools/dump_build_env.sh "$CXX" build-cmake/drop/env-info.json + ./tools/dump_build_env.sh "$CXX" build/cmake/drop/env-info.json - name: Build and run test with NVHPC ${{ env.NVHPC_VERSION }} on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true - name: Run benchmarks - run: build-cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake/drop/benchmarking-results.json + run: build/cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-nvhpc - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/.github/workflows/bvt-oneapi.yml b/.github/workflows/bvt-oneapi.yml index 80b44aa..dc822fa 100644 --- a/.github/workflows/bvt-oneapi.yml +++ b/.github/workflows/bvt-oneapi.yml @@ -42,26 +42,40 @@ jobs: - name: Build and run test with oneapi on cmake run: | - cmake -B build-cmake -GNinja -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release - cmake --build build-cmake -j - ctest --test-dir build-cmake -j - mkdir build-cmake/drop - bash ./tools/dump_build_env.sh "$CXX" build-cmake/drop/env-info.json + cmake --preset default -DCMAKE_CXX_STANDARD=23 + cmake --build --preset default -j + ctest --preset default -j + mkdir build/cmake/drop + bash ./tools/dump_build_env.sh "$CXX" build/cmake/drop/env-info.json + + - name: Build and run freestanding test with oneapi on cmake + run: | + cmake --preset freestanding -DCMAKE_CXX_STANDARD=23 + cmake --build --preset freestanding -j + ctest --preset freestanding -j - name: Build and run test with oneapi on meson run: | - meson setup build-meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled - meson test -C build-meson - meson test -C build-meson --benchmark --test-args=--benchmark_list_tests=true + meson setup build/meson --buildtype=release -Dtests=enabled -Dbenchmarks=enabled + meson test -C build/meson + meson test -C build/meson --benchmark --test-args=--benchmark_list_tests=true + + - name: Build and run freestanding test with oneapi on meson + run: | + meson setup build/meson-freestanding --buildtype=release -Dfreestanding=true + meson test -C build/meson-freestanding - name: Build and Run test with oneapi on bazel - run: bazel test --lockfile_mode=error --cxxopt=-Wno-c++23-extensions --test_env=LD_LIBRARY_PATH //tests:proxy_tests //tests:proxy_freestanding_tests //benchmarks:proxy_benchmarks //docs/... + run: bazel test --lockfile_mode=error --cxxopt=-Wno-c++23-extensions --test_env=LD_LIBRARY_PATH //tests:proxy_tests //benchmarks:proxy_benchmarks //docs/... + + - name: Build and run freestanding test with oneapi on bazel + run: bazel test --config=freestanding --lockfile_mode=error --cxxopt=-Wno-c++23-extensions --test_env=LD_LIBRARY_PATH //tests:proxy_freestanding_tests - name: Run benchmarks - run: build-cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build-cmake/drop/benchmarking-results.json + run: build/cmake/benchmarks/msft_proxy_benchmarks --benchmark_min_warmup_time=0.1 --benchmark_min_time=0.1s --benchmark_repetitions=30 --benchmark_enable_random_interleaving=true --benchmark_report_aggregates_only=true --benchmark_format=json > build/cmake/drop/benchmarking-results.json - name: Archive benchmarking results uses: actions/upload-artifact@v7 with: name: drop-oneapi - path: build-cmake/drop/ + path: build/cmake/drop/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f01a29b..38b2fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,16 @@ if(PROJECT_IS_TOP_LEVEL) "When this project is top level, build the docs and tests with C++ module support." OFF ) + option( + PROXY_FREESTANDING + "When this project is top level, configure proxy and its tests for a freestanding environment. GCC/Clang only." + OFF + ) +endif() + +if(PROXY_FREESTANDING) + add_compile_options(-ffreestanding -fno-exceptions -fno-rtti) + add_link_options(-nodefaultlibs -lc) endif() file(GLOB_RECURSE proxy_public_headers CONFIGURE_DEPENDS @@ -101,24 +111,6 @@ install( if(BUILD_TESTING) include(CTest) - include(cmake/read_dependencies.cmake) - proxy_read_dependencies("${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies.json") - - include(FetchContent) - # The policy uses the download time for timestamp, instead of the timestamp in the archive. This - # allows for proper rebuilds when a projects URL changes. - if(POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) - endif() - - FetchContent_Declare( - fmt - URL ${PROXY_FMT_URL} - URL_HASH SHA256=${PROXY_FMT_SHA256} - SYSTEM - ) - FetchContent_MakeAvailable(fmt) - if(MSVC) set(PROXY_BUILD_FLAGS /utf-8 /W4) set(PROXY_STRICT_WARNING_FLAGS ${PROXY_BUILD_FLAGS} /WX) @@ -133,10 +125,32 @@ if(BUILD_TESTING) set(PROXY_STRICT_WARNING_FLAGS ${PROXY_BUILD_FLAGS} -Werror) endif() - add_subdirectory(tests) - add_subdirectory(benchmarks) + if(PROXY_FREESTANDING) + add_subdirectory(tests/freestanding) + else() + include(cmake/read_dependencies.cmake) + proxy_read_dependencies("${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies.json") + + include(FetchContent) + # The policy uses the download time for timestamp, instead of the timestamp in the archive. This + # allows for proper rebuilds when a projects URL changes. + if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) + endif() + + FetchContent_Declare( + fmt + URL ${PROXY_FMT_URL} + URL_HASH SHA256=${PROXY_FMT_SHA256} + SYSTEM + ) + FetchContent_MakeAvailable(fmt) + + add_subdirectory(tests) + add_subdirectory(benchmarks) - if(BUILD_DOC_TESTING) - add_subdirectory(docs) + if(BUILD_DOC_TESTING) + add_subdirectory(docs) + endif() endif() endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..e5c7ddc --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,55 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 28, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default hosted build", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_CXX_STANDARD": "20" + } + }, + { + "name": "freestanding", + "displayName": "Freestanding build", + "inherits": "default", + "binaryDir": "${sourceDir}/build/cmake-freestanding", + "cacheVariables": { + "PROXY_FREESTANDING": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + }, + { + "name": "freestanding", + "configurePreset": "freestanding" + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + } + }, + { + "name": "freestanding", + "configurePreset": "freestanding", + "output": { + "outputOnFailure": true + } + } + ] +} diff --git a/README.md b/README.md index 336795c..ab72435 100644 --- a/README.md +++ b/README.md @@ -316,9 +316,9 @@ Then drive the tests through any of the supported build systems: ### CMake ``` -cmake -B build -cmake --build build -j -ctest --test-dir build -j +cmake --preset default +cmake --build --preset default -j +ctest --preset default -j ``` ### Meson diff --git a/include/proxy/v4/proxy.ixx b/include/proxy/v4/proxy.ixx index 37fb981..cdf4cce 100644 --- a/include/proxy/v4/proxy.ixx +++ b/include/proxy/v4/proxy.ixx @@ -6,9 +6,17 @@ export module proxy.v4; export namespace pro::inline v4 { +#if __STDC_HOSTED__ using v4::allocate_proxy; using v4::allocate_proxy_shared; +using v4::make_proxy; +using v4::make_proxy_shared; +#endif // __STDC_HOSTED__ + +#if __cpp_rtti >= 199711L using v4::bad_proxy_cast; +#endif // __cpp_rtti >= 199711L + using v4::basic_facade_builder; using v4::constraint_level; using v4::conversion_dispatch; @@ -20,9 +28,7 @@ using v4::implicit_conversion_dispatch; using v4::inplace_proxiable_target; using v4::is_bitwise_trivially_relocatable; using v4::is_bitwise_trivially_relocatable_v; -using v4::make_proxy; using v4::make_proxy_inplace; -using v4::make_proxy_shared; using v4::make_proxy_view; using v4::not_implemented; using v4::observer_facade; diff --git a/meson.build b/meson.build index 26acf94..ef0eed9 100644 --- a/meson.build +++ b/meson.build @@ -32,6 +32,21 @@ elif cxx.get_id() == 'nvidia_hpc' ) endif +freestanding = get_option('freestanding') +if freestanding + add_project_arguments( + '-ffreestanding', + '-fno-exceptions', + '-fno-rtti', + language: 'cpp', + ) + add_project_link_arguments( + '-nodefaultlibs', + '-lc', + language: 'cpp', + ) +endif + inc = include_directories('include') msft_proxy4_dep = declare_dependency( @@ -57,36 +72,41 @@ endif meson.override_dependency(meson.project_name(), msft_proxy4_dep) tests = get_option('tests').disable_auto_if(meson.is_subproject()) -gtest_dep = dependency( - 'gtest_main', - main: true, - required: tests, - default_options: ['warning_level=0'], -) -fmt_dep = dependency( - 'fmt', - version: '>=6.1.0', - required: tests, - disabler: true, - default_options: ['warning_level=0'], - include_type: 'system', -) -subdir( - 'tests', - if_found: gtest_dep, -) -benchmarks = get_option('benchmarks').disable_auto_if(meson.is_subproject()) -benchmark_dep = dependency( - 'benchmark_main', - required: benchmarks, - default_options: ['warning_level=0'], -) -subdir( - 'benchmarks', - if_found: benchmark_dep, -) +if freestanding + subdir('tests/freestanding') +else + gtest_dep = dependency( + 'gtest_main', + main: true, + required: tests, + default_options: ['warning_level=0'], + ) + fmt_dep = dependency( + 'fmt', + version: '>=6.1.0', + required: tests, + disabler: true, + default_options: ['warning_level=0'], + include_type: 'system', + ) + subdir( + 'tests', + if_found: gtest_dep, + ) + + benchmarks = get_option('benchmarks').disable_auto_if(meson.is_subproject()) + benchmark_dep = dependency( + 'benchmark_main', + required: benchmarks, + default_options: ['warning_level=0'], + ) + subdir( + 'benchmarks', + if_found: benchmark_dep, + ) -if tests.allowed() and get_option('doc_tests') - subdir('docs') + if tests.allowed() and get_option('doc_tests') + subdir('docs') + endif endif diff --git a/meson.options b/meson.options index 321cc7d..9793ad6 100644 --- a/meson.options +++ b/meson.options @@ -16,3 +16,9 @@ option( value: true, description: 'Build and run tests extracted from docs (requires tests)', ) +option( + 'freestanding', + type: 'boolean', + value: false, + description: 'Configure proxy and its tests for a freestanding environment.', +) diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index c3c49eb..9ecbd9a 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -41,15 +41,7 @@ cc_test( cc_test( name = "proxy_freestanding_tests", srcs = ["freestanding/proxy_freestanding_tests.cpp"], - copts = PROXY_STRICT_BUILD_COPTS + [ - "-ffreestanding", - "-fno-exceptions", - "-fno-rtti", - ], - linkopts = [ - "-nodefaultlibs", - "-lc", - ], + copts = PROXY_STRICT_BUILD_COPTS, target_compatible_with = ["@platforms//os:linux"], deps = ["//:proxy"], ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8d0f756..49eafc2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,28 +35,4 @@ target_link_libraries( target_compile_options(msft_proxy_tests PRIVATE ${PROXY_STRICT_WARNING_FLAGS}) gtest_discover_tests(msft_proxy_tests) -if( - CMAKE_CXX_COMPILER_ID STREQUAL "GNU" - OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" -) - add_executable( - msft_proxy_freestanding_tests - freestanding/proxy_freestanding_tests.cpp - ) - target_compile_options( - msft_proxy_freestanding_tests - PRIVATE - -ffreestanding - -fno-exceptions - -fno-rtti - ${PROXY_STRICT_WARNING_FLAGS} - ) - target_link_options(msft_proxy_freestanding_tests PRIVATE -nodefaultlibs -lc) - target_link_libraries( - msft_proxy_freestanding_tests - PRIVATE msft_proxy4::proxy - ) - add_test(NAME ProxyFreestandingTests COMMAND msft_proxy_freestanding_tests) -endif() - add_subdirectory(modules) diff --git a/tests/freestanding/CMakeLists.txt b/tests/freestanding/CMakeLists.txt new file mode 100644 index 0000000..2c1f592 --- /dev/null +++ b/tests/freestanding/CMakeLists.txt @@ -0,0 +1,26 @@ +add_executable(msft_proxy_freestanding_tests proxy_freestanding_tests.cpp) +target_compile_options( + msft_proxy_freestanding_tests + PRIVATE ${PROXY_STRICT_WARNING_FLAGS} +) +target_link_libraries(msft_proxy_freestanding_tests PRIVATE msft_proxy4::proxy) +add_test(NAME ProxyFreestandingTests COMMAND msft_proxy_freestanding_tests) + +if(PROXY_BUILD_MODULES) + add_executable( + msft_proxy_freestanding_module_tests + proxy_freestanding_module_tests.cpp + ) + target_compile_options( + msft_proxy_freestanding_module_tests + PRIVATE ${PROXY_STRICT_WARNING_FLAGS} + ) + target_link_libraries( + msft_proxy_freestanding_module_tests + PRIVATE msft_proxy4::proxy_module + ) + add_test( + NAME ProxyFreestandingModuleSupportTests + COMMAND msft_proxy_freestanding_module_tests + ) +endif() diff --git a/tests/freestanding/meson.build b/tests/freestanding/meson.build new file mode 100644 index 0000000..7dcfffb --- /dev/null +++ b/tests/freestanding/meson.build @@ -0,0 +1,13 @@ +test( + 'ProxyFreestandingTests', + executable( + 'msft_proxy_freestanding_tests', + files('proxy_freestanding_tests.cpp'), + implicit_include_directories: false, + dependencies: msft_proxy4_dep, + override_options: { + 'werror': true, + }, + build_by_default: false, + ), +) diff --git a/tests/freestanding/proxy_freestanding_module_tests.cpp b/tests/freestanding/proxy_freestanding_module_tests.cpp new file mode 100644 index 0000000..fcebb0e --- /dev/null +++ b/tests/freestanding/proxy_freestanding_module_tests.cpp @@ -0,0 +1,52 @@ +// Copyright (c) 2022-2026 Microsoft Corporation. +// Copyright (c) 2026-Present Next Gen C++ Foundation. +// Licensed under the MIT License. + +#if __STDC_HOSTED__ +#error "This file shall be compiled targeting a freestanding environment." +#endif // __STDC_HOSTED__ + +#include + +#include +#include +#include + +import proxy.v4; + +constexpr unsigned DefaultHash = -1; +unsigned GetHashImpl(int v) { return static_cast(v + 3) * 31; } +unsigned GetHashImpl(double v) { return static_cast(v * v + 5) * 87; } +unsigned GetHashImpl(const char* v) { + unsigned result = 91u; + for (int i = 0; v[i]; ++i) { + result = result * 47u + v[i]; + } + return result; +} +unsigned GetHashImpl(auto&&) { return DefaultHash; } +PRO_DEF_FREE_DISPATCH(FreeGetHash, GetHashImpl, GetHash); + +struct Hashable : pro::facade_builder // + ::add_convention // + ::build {}; + +extern "C" int main() { + int i = 123; + double d = 3.14159; + const char* s = "lalala"; + pro::proxy p; + p = &i; + if (GetHash(*p) != GetHashImpl(i)) { + return 1; + } + p = &d; + if (GetHash(*p) != GetHashImpl(d)) { + return 1; + } + p = pro::make_proxy_inplace(s); + if (GetHash(*p) != GetHashImpl(s)) { + return 1; + } + return 0; +} diff --git a/tests/meson.build b/tests/meson.build index 9e6d847..df7f405 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -37,37 +37,3 @@ test( ), protocol: 'gtest', ) - -freestanding_cflags = ['-ffreestanding'] -freestanding_ldflags = ['-nodefaultlibs'] - -if cxx.has_multi_arguments( - freestanding_cflags, - freestanding_ldflags, - required: false, -) - libc_dep = cxx.find_library( - 'c', - required: false, - ) - - if libc_dep.found() - test( - 'ProxyFreestandingSupportTests', - executable( - 'msft_proxy_freestanding_tests', - files('freestanding/proxy_freestanding_tests.cpp'), - implicit_include_directories: false, - dependencies: [msft_proxy4_dep, libc_dep], - cpp_args: freestanding_cflags, - link_args: get_option('b_sanitize') == 'none' ? freestanding_ldflags : [], - override_options: { - 'cpp_eh': 'none', - 'cpp_rtti': false, - 'werror': true, - }, - build_by_default: false, - ), - ) - endif -endif From aea76b19dfb9dc496137420d85ea096d9632bf7a Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Sat, 20 Jun 2026 17:34:32 +0800 Subject: [PATCH 2/2] Disable module tests for gcc-14 --- .github/workflows/bvt-compatibility.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bvt-compatibility.yml b/.github/workflows/bvt-compatibility.yml index 5f3c424..9f7792e 100644 --- a/.github/workflows/bvt-compatibility.yml +++ b/.github/workflows/bvt-compatibility.yml @@ -11,7 +11,7 @@ jobs: matrix: compiler: - {family: gcc, version: 13, modules: false, doc_tests: true} - - {family: gcc, version: 14, modules: true, doc_tests: true} + - {family: gcc, version: 14, modules: false, doc_tests: true} - {family: clang, version: 16, modules: false, doc_tests: false} - {family: clang, version: 17, modules: false, doc_tests: true} - {family: clang, version: 18, modules: false, doc_tests: true}