Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpiutil] Use C++23 stacktrace library on Windows #6839

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apriltag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ add_library(apriltag ${apriltag_native_src} ${apriltag_resources_src} ${apriltag
set_target_properties(apriltag PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET apriltag PROPERTY FOLDER "libraries")
target_compile_features(apriltag PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(apriltag PUBLIC cxx_std_23)
else()
target_compile_features(apriltag PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(apriltag)

target_link_libraries(apriltag wpimath)
Expand Down
4 changes: 3 additions & 1 deletion fieldImages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ add_library(fieldImages ${field_images_resources_src} src/main/native/cpp/fields
set_target_properties(fieldImages PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET fieldImages PROPERTY FOLDER "libraries")
target_compile_features(fieldImages PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(fieldImages PUBLIC /bigobj)
target_compile_features(fieldImages PUBLIC cxx_std_23)
else()
target_compile_features(fieldImages PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(fieldImages)

Expand Down
6 changes: 5 additions & 1 deletion ntcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ target_include_directories(
$<INSTALL_INTERFACE:${include_dest}/ntcore>
)
wpilib_target_warnings(ntcore)
target_compile_features(ntcore PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(ntcore PUBLIC cxx_std_23)
else()
target_compile_features(ntcore PUBLIC cxx_std_20)
endif()
target_link_libraries(ntcore PUBLIC wpinet wpiutil)

set_property(TARGET ntcore PROPERTY FOLDER "libraries")
Expand Down
6 changes: 5 additions & 1 deletion romiVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ add_library(romiVendordep ${romiVendordep_native_src})
set_target_properties(romiVendordep PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET romiVendordep PROPERTY FOLDER "libraries")

target_compile_features(romiVendordep PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(romiVendordep PUBLIC cxx_std_23)
else()
target_compile_features(romiVendordep PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(romiVendordep)
target_link_libraries(romiVendordep wpilibc)

Expand Down
7 changes: 7 additions & 0 deletions shared/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ nativeUtils.platformConfigs.each {
}
}

// Use C++23 on Windows
nativeUtils.platformConfigs.each {
if (it.name.contains('windows')) {
it.cppCompiler.args.add("/std:c++23preview")
}
}

nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")

if (project.hasProperty('ntcoreffibuild')) {
Expand Down
6 changes: 5 additions & 1 deletion wpilibNewCommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ add_library(wpilibNewCommands ${wpilibNewCommands_native_src})
set_target_properties(wpilibNewCommands PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpilibNewCommands PROPERTY FOLDER "libraries")

target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(wpilibNewCommands PUBLIC cxx_std_23)
else()
target_compile_features(wpilibNewCommands PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(wpilibNewCommands)
target_link_libraries(wpilibNewCommands wpilibc)

Expand Down
2 changes: 1 addition & 1 deletion wpimath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ set_target_properties(wpimath PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpimath PROPERTY FOLDER "libraries")
target_compile_definitions(wpimath PRIVATE WPILIB_EXPORTS SLEIPNIR_EXPORTS)

target_compile_features(wpimath PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(wpimath PUBLIC cxx_std_23)
target_compile_options(wpimath PUBLIC /utf-8 /bigobj)
endif()
wpilib_target_warnings(wpimath)
Expand Down
6 changes: 5 additions & 1 deletion wpinet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ set_target_properties(wpinet PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET wpinet PROPERTY FOLDER "libraries")

target_compile_features(wpinet PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(wpinet PUBLIC cxx_std_23)
else()
target_compile_features(wpinet PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(wpinet)
target_link_libraries(wpinet PUBLIC wpiutil)

Expand Down
4 changes: 3 additions & 1 deletion wpiutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET wpiutil PROPERTY FOLDER "libraries")

target_compile_features(wpiutil PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(
wpiutil
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
)
target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS)
target_compile_features(wpiutil PUBLIC cxx_std_23)
else()
target_compile_features(wpiutil PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(wpiutil)
if(WITH_PROTOBUF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

#include "wpi/StackTrace.h"

#ifdef __cpp_lib_stacktrace
#include <stacktrace>
#elif !defined(_WIN32)
#include <execinfo.h>
#endif

#include <string>

Expand All @@ -16,33 +20,41 @@
namespace wpi {

std::string GetStackTraceDefault(int offset) {
#ifndef __ANDROID__
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream trace(buf);

#ifdef __cpp_lib_stacktrace
auto stackTrace = std::stacktrace::current();

for (size_t i = offset; i < stackTrace.size(); ++i) {
// Only print recursive functions once in a row
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
trace << "\tat " << std::to_string(stackTrace[i]) << '\n';
}
}
#elif !defined(_WIN32) && !defined(__ANDROID__)
void* stackTrace[128];
int stackSize = backtrace(stackTrace, 128);
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream trace(buf);

for (int i = offset; i < stackSize; i++) {
// Only print recursive functions once in a row.
for (int i = offset; i < stackSize; ++i) {
// Only print recursive functions once in a row
if (i == 0 || stackTrace[i] != stackTrace[i - 1]) {
// extract just function name from "pathToExe(functionName+offset)"
// Extract just function name from "pathToExe(functionName+offset)"
std::string_view sym = split(mangledSymbols[i], '(').second;
std::string_view offset;
std::tie(sym, offset) = split(sym, '+');
std::string_view addr;
std::tie(offset, addr) = split(offset, ')');
trace << "\tat " << Demangle(sym) << " + " << offset << addr << "\n";

trace << "\tat " << Demangle(sym) << " + " << offset << addr << '\n';
}
}

std::free(mangledSymbols);
#endif

return std::string{trace.str()};
#else
// backtrace_symbols not supported on android
return "";
#endif
}

} // namespace wpi
20 changes: 0 additions & 20 deletions wpiutil/src/main/native/windows/StackTrace.cpp

This file was deleted.

6 changes: 5 additions & 1 deletion xrpVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ add_library(xrpVendordep ${xrpVendordep_native_src})
set_target_properties(xrpVendordep PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET xrpVendordep PROPERTY FOLDER "libraries")

target_compile_features(xrpVendordep PUBLIC cxx_std_20)
if(MSVC)
target_compile_features(xrpVendordep PUBLIC cxx_std_23)
else()
target_compile_features(xrpVendordep PUBLIC cxx_std_20)
endif()
wpilib_target_warnings(xrpVendordep)
target_link_libraries(xrpVendordep wpilibc)

Expand Down
Loading