Skip to content

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

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

Open
wants to merge 1 commit into
base: 2027
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
2 changes: 1 addition & 1 deletion apriltag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ 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)
target_compile_features(apriltag PUBLIC cxx_std_23)
wpilib_target_warnings(apriltag)

target_link_libraries(apriltag wpimath)
Expand Down
2 changes: 1 addition & 1 deletion fieldImages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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)
target_compile_features(fieldImages PUBLIC cxx_std_23)
if(MSVC)
target_compile_options(fieldImages PUBLIC /bigobj)
endif()
Expand Down
2 changes: 1 addition & 1 deletion ntcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${include_dest}/ntcore>
)
wpilib_target_warnings(ntcore)
target_compile_features(ntcore PUBLIC cxx_std_20)
target_compile_features(ntcore PUBLIC cxx_std_23)
target_link_libraries(ntcore PUBLIC wpinet wpiutil datalog)

set_property(TARGET ntcore PROPERTY FOLDER "libraries")
Expand Down
2 changes: 1 addition & 1 deletion ntcore/src/dev/native/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
#include <cstdlib>
Expand All @@ -22,7 +23,6 @@

#include "networktables/DoubleArrayTopic.h"
#include "networktables/NetworkTableInstance.h"
#include "ntcore.h"
#include "ntcore_c.h"
#include "ntcore_cpp.h"

Expand Down
2 changes: 1 addition & 1 deletion romiVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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)
target_compile_features(romiVendordep PUBLIC cxx_std_23)
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 @@ -45,6 +45,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
2 changes: 1 addition & 1 deletion wpilibNewCommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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)
target_compile_features(wpilibNewCommands PUBLIC cxx_std_23)
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 @@ -152,7 +152,7 @@ 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)
target_compile_features(wpimath PUBLIC cxx_std_23)
if(MSVC)
target_compile_options(wpimath PUBLIC /utf-8 /bigobj)
endif()
Expand Down
2 changes: 1 addition & 1 deletion wpinet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ set_target_properties(wpinet PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET wpinet PROPERTY FOLDER "libraries")

target_compile_features(wpinet PUBLIC cxx_std_20)
target_compile_features(wpinet PUBLIC cxx_std_23)
wpilib_target_warnings(wpinet)
target_link_libraries(wpinet PUBLIC wpiutil)

Expand Down
9 changes: 1 addition & 8 deletions wpiutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ if(NOT WITH_PROTOBUF)
list(APPEND wpiutil_native_src src/main/native/cpp/protobuf/Protobuf.cpp)
endif()
file(GLOB_RECURSE wpiutil_unix_src src/main/native/unix/*.cpp)
file(GLOB_RECURSE wpiutil_linux_src src/main/native/linux/*.cpp)
file(GLOB_RECURSE wpiutil_macos_src src/main/native/macOS/*.cpp)
file(GLOB_RECURSE wpiutil_windows_src src/main/native/windows/*.cpp)

file(GLOB fmtlib_native_src src/main/native/thirdparty/fmtlib/src/*.cpp)
Expand All @@ -136,7 +134,7 @@ set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d")

set_property(TARGET wpiutil PROPERTY FOLDER "libraries")

target_compile_features(wpiutil PUBLIC cxx_std_20)
target_compile_features(wpiutil PUBLIC cxx_std_23)
if(MSVC)
target_compile_options(
wpiutil
Expand Down Expand Up @@ -183,11 +181,6 @@ if(MSVC)
target_sources(wpiutil PRIVATE ${wpiutil_windows_src})
else()
target_sources(wpiutil PRIVATE ${wpiutil_unix_src})
if(APPLE)
target_sources(wpiutil PRIVATE ${wpiutil_macos_src})
else()
target_sources(wpiutil PRIVATE ${wpiutil_linux_src})
endif()
endif()

install(
Expand Down
26 changes: 0 additions & 26 deletions wpiutil/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,6 @@ ext {
}
}
}
} else if (it.targetPlatform.operatingSystem.isMacOsX()) {
it.sources {
wpiutilmacOSCpp(CppSourceSet) {
source {
srcDirs 'src/main/native/macOS'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/cpp', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include'
include '**/*.h'
}
}
}
} else {
it.sources {
wpiutilLinuxCpp(CppSourceSet) {
source {
srcDirs 'src/main/native/linux'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/main/native/include', 'src/main/native/cpp', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include'
include '**/*.h'
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "wpi/StackTrace.h"

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

Expand All @@ -18,23 +20,36 @@
namespace wpi {

std::string GetStackTraceDefault(int offset) {
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
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';
}
}

return std::string{trace.str()};
#elif !defined(_WIN32) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
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';
}
}

Expand Down
20 changes: 0 additions & 20 deletions wpiutil/src/main/native/windows/StackTrace.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion xrpVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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)
target_compile_features(xrpVendordep PUBLIC cxx_std_23)
wpilib_target_warnings(xrpVendordep)
target_link_libraries(xrpVendordep wpilibc)

Expand Down
Loading