Skip to content

Commit cac597f

Browse files
committed
build: Test C++20 and gcc14 + fixes needed (#2010)
We weren't testing against gcc-14 nor against C++20 in our test matrix. Add them. The fixes required were: * Had to suppress some warnings gcc-14 complains about in LLVM's headers. * There were some tricky interactions between C++20 and fmtlib, which is because when being compiled with C++ >= 20, fmt switches to a bunch of tricky runtime checking that has different needs for constexpr and consteval. I had to rearrange some things a bit to make it happy simultaneously with both old and new. Signed-off-by: Larry Gritz <[email protected]>
1 parent 87aab13 commit cac597f

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

.github/workflows/build-steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
restore-keys: ${{inputs.nametag}}
135135
- name: Install LLVM and Clang
136136
if: inputs.llvm_action_ver != ''
137-
uses: KyleMayes/install-llvm-action@6ba6e2cd3813def9879be378609d87cb3ef3bac3 # v2.0.6
137+
uses: KyleMayes/install-llvm-action@a7a1a882e2d06ebe05d5bb97c3e1f8c984ae96fc # v2.0.7
138138
with:
139139
version: ${{ inputs.llvm_action_ver }}
140140
- name: Dependencies

.github/workflows/ci.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,20 +426,19 @@ jobs:
426426
openimageio_ver: release
427427
pybind11_ver: v3.0.0
428428
python_ver: "3.12"
429+
llvm_action_ver: "18.1.7"
429430
simd: avx2,f16c
430431
batched: b8_AVX2,b8_AVX512,b16_AVX512
431-
setenvs: export LLVM_VERSION=17.0.6
432-
LLVM_DISTRO_NAME=ubuntu-22.04
433-
LIBTIFF_VERSION=v4.7.0
432+
setenvs: export LIBTIFF_VERSION=v4.7.0
434433
PTEX_VERSION=v2.4.3
435434
PUGIXML_VERSION=v1.15
436435
FREETYPE_VERSION=VER-2-13-3
437-
- desc: bleeding edge gcc13/C++17 llvm17 oiio/ocio/exr/pybind-main py3.12 avx2 batch-b16avx512
436+
- desc: bleeding edge gcc14/C++17 llvm17 oiio/ocio/exr/pybind-main py3.12 avx2 batch-b16avx512
438437
nametag: linux-bleeding-edge
439438
runner: ubuntu-24.04
440-
cc_compiler: gcc-13
441-
cxx_compiler: g++-13
442-
cxx_std: 17
439+
cc_compiler: gcc-14
440+
cxx_compiler: g++-14
441+
cxx_std: 20
443442
fmt_ver: master
444443
opencolorio_ver: main
445444
openexr_ver: main

src/include/OSL/oslconfig.h.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ template<typename Str, typename... Args>
123123
OSL_NODISCARD inline std::string
124124
fmtformat(const Str& fmt, Args&&... args)
125125
{
126+
#if OSL_CPLUSPLUS_VERSION >= 20 || FMT_VERSION >= 100000
127+
return ::fmt::vformat(fmt, ::fmt::make_format_args(args...));
128+
#else
126129
return OIIO::Strutil::fmt::format(fmt, std::forward<Args>(args)...);
130+
#endif
127131
}
128132

129133
// TODO: notice the fmt argument is not templatised, this is because
@@ -132,13 +136,18 @@ fmtformat(const Str& fmt, Args&&... args)
132136
// OIIO should fix this if possible.
133137
template<typename OutIt, typename... Args>
134138
OSL_NODISCARD inline auto
135-
fmtformat_to_n(OutIt &out, size_t n, const string_view& fmt, Args&&... args)
139+
fmtformat_to_n(OutIt& out, size_t n, string_view fmt, Args&&... args)
136140
{
137141
// DOES NOT EXIST AS PUBLIC API
138142
//return OIIO::Strutil::fmt::format_to_n(out, n, fmt, std::forward<Args>(args)...);
139143
// So call directly into underlying fmt library OIIO is using
140144
// TODO: Add format_to_n as a public API in OIIO
145+
#if OSL_CPLUSPLUS_VERSION >= 20 || FMT_VERSION >= 100000
146+
std::string str = fmtformat(fmt, std::forward<Args>(args)...);
147+
return ::fmt::format_to_n(out, n, "{}", str);
148+
#else
141149
return ::fmt::format_to_n(out, n, ::fmt::string_view{fmt.begin(), fmt.length()}, std::forward<Args>(args)...);
150+
#endif
142151
}
143152

144153

src/liboslcomp/oslcomp_pvt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ class OSLCompilerImpl {
365365
template<typename... Args>
366366
inline void osofmt(const char* fmt, Args&&... args) const
367367
{
368-
fmt::print(*m_osofile, fmt, std::forward<Args>(args)...);
368+
*m_osofile << OIIO::Strutil::fmt::format(fmt,
369+
std::forward<Args>(args)...);
369370
}
370371

371372
void track_variable_lifetimes()

src/liboslexec/llvm_util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
# error "LLVM minimum version required for OSL is 11.0"
1818
#endif
1919

20+
OSL_PRAGMA_WARNING_PUSH
21+
#if OSL_GNUC_VERSION >= 140000
22+
OSL_GCC_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
23+
#endif
24+
2025
#include "llvm_passes.h"
2126

2227
#include <llvm/InitializePasses.h>
@@ -128,6 +133,8 @@
128133
#include <llvm/Transforms/Utils/Cloning.h>
129134
#include <llvm/Transforms/Utils/SymbolRewriter.h>
130135

136+
OSL_PRAGMA_WARNING_POP
137+
131138
OSL_NAMESPACE_BEGIN
132139

133140

0 commit comments

Comments
 (0)