Skip to content

Commit b196da0

Browse files
committed
[wpiutil] Use C++23 stacktrace library on Windows
1 parent 155b3d4 commit b196da0

File tree

12 files changed

+67
-40
lines changed

12 files changed

+67
-40
lines changed

apriltag/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ add_library(apriltag ${apriltag_native_src} ${apriltag_resources_src} ${apriltag
120120
set_target_properties(apriltag PROPERTIES DEBUG_POSTFIX "d")
121121

122122
set_property(TARGET apriltag PROPERTY FOLDER "libraries")
123-
target_compile_features(apriltag PUBLIC cxx_std_20)
123+
if(MSVC)
124+
target_compile_features(apriltag PUBLIC cxx_std_23)
125+
else()
126+
target_compile_features(apriltag PUBLIC cxx_std_20)
127+
endif()
124128
wpilib_target_warnings(apriltag)
125129

126130
target_link_libraries(apriltag wpimath)

fieldImages/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ add_library(fieldImages ${field_images_resources_src} src/main/native/cpp/fields
4646
set_target_properties(fieldImages PROPERTIES DEBUG_POSTFIX "d")
4747

4848
set_property(TARGET fieldImages PROPERTY FOLDER "libraries")
49-
target_compile_features(fieldImages PUBLIC cxx_std_20)
5049
if(MSVC)
5150
target_compile_options(fieldImages PUBLIC /bigobj)
51+
target_compile_features(fieldImages PUBLIC cxx_std_23)
52+
else()
53+
target_compile_features(fieldImages PUBLIC cxx_std_20)
5254
endif()
5355
wpilib_target_warnings(fieldImages)
5456

ntcore/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ target_include_directories(
2525
$<INSTALL_INTERFACE:${include_dest}/ntcore>
2626
)
2727
wpilib_target_warnings(ntcore)
28-
target_compile_features(ntcore PUBLIC cxx_std_20)
28+
if(MSVC)
29+
target_compile_features(ntcore PUBLIC cxx_std_23)
30+
else()
31+
target_compile_features(ntcore PUBLIC cxx_std_20)
32+
endif()
2933
target_link_libraries(ntcore PUBLIC wpinet wpiutil)
3034

3135
set_property(TARGET ntcore PROPERTY FOLDER "libraries")

romiVendordep/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ add_library(romiVendordep ${romiVendordep_native_src})
5252
set_target_properties(romiVendordep PROPERTIES DEBUG_POSTFIX "d")
5353
set_property(TARGET romiVendordep PROPERTY FOLDER "libraries")
5454

55-
target_compile_features(romiVendordep PUBLIC cxx_std_20)
55+
if(MSVC)
56+
target_compile_features(romiVendordep PUBLIC cxx_std_23)
57+
else()
58+
target_compile_features(romiVendordep PUBLIC cxx_std_20)
59+
endif()
5660
wpilib_target_warnings(romiVendordep)
5761
target_link_libraries(romiVendordep wpilibc)
5862

shared/config.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ nativeUtils.platformConfigs.each {
3939
}
4040
}
4141

42+
// Use C++23 on Windows
43+
nativeUtils.platformConfigs.each {
44+
if (it.name.contains('windows')) {
45+
it.cppCompiler.args.add("/std:c++23preview")
46+
}
47+
}
48+
4249
nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")
4350

4451
if (project.hasProperty('ntcoreffibuild')) {

wpilibNewCommands/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ add_library(wpilibNewCommands ${wpilibNewCommands_native_src})
6060
set_target_properties(wpilibNewCommands PROPERTIES DEBUG_POSTFIX "d")
6161
set_property(TARGET wpilibNewCommands PROPERTY FOLDER "libraries")
6262

63-
target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
63+
if(MSVC)
64+
target_compile_features(wpilibNewCommands PUBLIC cxx_std_23)
65+
else()
66+
target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
67+
endif()
6468
wpilib_target_warnings(wpilibNewCommands)
6569
target_link_libraries(wpilibNewCommands wpilibc)
6670

wpimath/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ set_target_properties(wpimath PROPERTIES DEBUG_POSTFIX "d")
153153
set_property(TARGET wpimath PROPERTY FOLDER "libraries")
154154
target_compile_definitions(wpimath PRIVATE WPILIB_EXPORTS SLEIPNIR_EXPORTS)
155155

156-
target_compile_features(wpimath PUBLIC cxx_std_20)
157156
if(MSVC)
157+
target_compile_features(wpimath PUBLIC cxx_std_23)
158158
target_compile_options(wpimath PUBLIC /utf-8 /bigobj)
159159
endif()
160160
wpilib_target_warnings(wpimath)

wpinet/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ set_target_properties(wpinet PROPERTIES DEBUG_POSTFIX "d")
126126

127127
set_property(TARGET wpinet PROPERTY FOLDER "libraries")
128128

129-
target_compile_features(wpinet PUBLIC cxx_std_20)
129+
if(MSVC)
130+
target_compile_features(wpinet PUBLIC cxx_std_23)
131+
else()
132+
target_compile_features(wpinet PUBLIC cxx_std_20)
133+
endif()
130134
wpilib_target_warnings(wpinet)
131135
target_link_libraries(wpinet PUBLIC wpiutil)
132136

wpiutil/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")
141141

142142
set_property(TARGET wpiutil PROPERTY FOLDER "libraries")
143143

144-
target_compile_features(wpiutil PUBLIC cxx_std_20)
145144
if(MSVC)
146145
target_compile_options(
147146
wpiutil
148147
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
149148
)
150149
target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS)
150+
target_compile_features(wpiutil PUBLIC cxx_std_23)
151+
else()
152+
target_compile_features(wpiutil PUBLIC cxx_std_20)
151153
endif()
152154
wpilib_target_warnings(wpiutil)
153155
if(WITH_PROTOBUF)

wpiutil/src/main/native/unix/StackTrace.cpp wpiutil/src/main/native/cpp/StackTrace.cpp

+23-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
#include "wpi/StackTrace.h"
66

7+
#ifdef __cpp_lib_stacktrace
8+
#include <stacktrace>
9+
#elif !defined(_WIN32)
710
#include <execinfo.h>
11+
#endif
812

913
#include <string>
1014

@@ -16,33 +20,41 @@
1620
namespace wpi {
1721

1822
std::string GetStackTraceDefault(int offset) {
19-
#ifndef __ANDROID__
23+
wpi::SmallString<1024> buf;
24+
wpi::raw_svector_ostream trace(buf);
25+
26+
#ifdef __cpp_lib_stacktrace
27+
auto stackTrace = std::stacktrace::current();
28+
29+
for (size_t i = offset; i < stackTrace.size(); ++i) {
30+
// Only print recursive functions once in a row
31+
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
32+
trace << "\tat " << std::to_string(stackTrace[i]) << '\n';
33+
}
34+
}
35+
#elif !defined(_WIN32) && !defined(__ANDROID__)
2036
void* stackTrace[128];
2137
int stackSize = backtrace(stackTrace, 128);
2238
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);
23-
wpi::SmallString<1024> buf;
24-
wpi::raw_svector_ostream trace(buf);
2539

26-
for (int i = offset; i < stackSize; i++) {
27-
// Only print recursive functions once in a row.
40+
for (int i = offset; i < stackSize; ++i) {
41+
// Only print recursive functions once in a row
2842
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
29-
// extract just function name from "pathToExe(functionName+offset)"
43+
// Extract just function name from "pathToExe(functionName+offset)"
3044
std::string_view sym = split(mangledSymbols[i], '(').second;
3145
std::string_view offset;
3246
std::tie(sym, offset) = split(sym, '+');
3347
std::string_view addr;
3448
std::tie(offset, addr) = split(offset, ')');
35-
trace << "\tat " << Demangle(sym) << " + " << offset << addr << "\n";
49+
50+
trace << "\tat " << Demangle(sym) << " + " << offset << addr << '\n';
3651
}
3752
}
3853

3954
std::free(mangledSymbols);
55+
#endif
4056

4157
return std::string{trace.str()};
42-
#else
43-
// backtrace_symbols not supported on android
44-
return "";
45-
#endif
4658
}
4759

4860
} // namespace wpi

wpiutil/src/main/native/windows/StackTrace.cpp

-20
This file was deleted.

xrpVendordep/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ add_library(xrpVendordep ${xrpVendordep_native_src})
5252
set_target_properties(xrpVendordep PROPERTIES DEBUG_POSTFIX "d")
5353
set_property(TARGET xrpVendordep PROPERTY FOLDER "libraries")
5454

55-
target_compile_features(xrpVendordep PUBLIC cxx_std_20)
55+
if(MSVC)
56+
target_compile_features(xrpVendordep PUBLIC cxx_std_23)
57+
else()
58+
target_compile_features(xrpVendordep PUBLIC cxx_std_20)
59+
endif()
5660
wpilib_target_warnings(xrpVendordep)
5761
target_link_libraries(xrpVendordep wpilibc)
5862

0 commit comments

Comments
 (0)