Enable compiler errors for implicit switch case fallthroughs.

Also unify warning options across Clang and GCC and fix minor issues that was surfaced by this.

PiperOrigin-RevId: 508619655
Change-Id: I59b777bf2dfea4422485670e2427c7d3f5cf6405
This commit is contained in:
Saran Tunyasuvunakool
2023-02-10 03:48:12 -08:00
committed by Copybara-Service
parent 8a53a33fd1
commit 5e989d18c3
24 changed files with 150 additions and 76 deletions
+26 -14
View File
@@ -67,7 +67,12 @@ include(FindOrFetch)
# ==================== MUJOCO LIBRARY ==========================================
if(NOT TARGET mujoco)
add_library(mujoco SHARED IMPORTED GLOBAL)
add_library(
mujoco
SHARED
IMPORTED
GLOBAL
)
if(APPLE)
# On macOS, check if we are using mujoco.framework first.
# Framework headers are searched differently from normal headers.
@@ -75,13 +80,17 @@ if(NOT TARGET mujoco)
find_path(MUJOCO_FRAMEWORK mujoco.Framework HINTS ${MUJOCO_FRAMEWORK_DIR})
if(MUJOCO_FRAMEWORK)
message("MuJoCo framework is at ${MUJOCO_FRAMEWORK}/mujoco.framework")
set(MUJOCO_LIBRARY ${MUJOCO_FRAMEWORK}/mujoco.framework/Versions/A/libmujoco.2.3.2.dylib)
set(MUJOCO_LIBRARY
${MUJOCO_FRAMEWORK}/mujoco.framework/Versions/A/libmujoco.2.3.2.dylib
)
target_compile_options(mujoco INTERFACE -F${MUJOCO_FRAMEWORK})
endif()
endif()
if(NOT MUJOCO_FRAMEWORK)
find_library(MUJOCO_LIBRARY mujoco mujoco.2.3.2 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED)
find_library(
MUJOCO_LIBRARY mujoco mujoco.2.3.2 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED
)
find_path(MUJOCO_INCLUDE mujoco/mujoco.h HINTS ${MUJOCO_INCLUDE_DIR} REQUIRED)
message("MuJoCo is at ${MUJOCO_LIBRARY}")
message("MuJoCo headers are at ${MUJOCO_INCLUDE}")
@@ -276,16 +285,18 @@ macro(mujoco_pybind11_module name)
pybind11_add_module(${name} ${ARGN})
target_compile_options(${name} PRIVATE ${AVX_COMPILE_OPTIONS})
if(NOT MSVC)
target_compile_options(${name} PRIVATE -Wall -Werror)
if(CMAKE_C_COMPILER_ID STREQUAL GNU)
target_compile_options(
${name}
PRIVATE -Wno-int-in-bool-context
-Wno-maybe-uninitialized
-Wno-sign-compare
-Wno-stringop-overflow
-Wno-stringop-truncation
)
target_compile_options(
${name}
PRIVATE -Werror
-Wall
-Wimplicit-fallthrough
-Wunused
-Wno-int-in-bool-context
-Wno-sign-compare
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Only allow fallthrough annotation via __attribute__.
target_compile_options(${name} PRIVATE -Wimplicit-fallthrough=5)
endif()
endif()
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
@@ -380,7 +391,8 @@ target_link_libraries(
PRIVATE mujoco
mujoco::libsimulate
raw
structs_header)
structs_header
)
set(LIBRARIES_FOR_WHEEL
"$<TARGET_FILE:_callbacks>"
+2 -1
View File
@@ -110,7 +110,8 @@ static thread_local std::jmp_buf mju_error_jmp_buf;
static thread_local std::array<char, 1024> mju_error_msg{0};
static inline void MjErrorHandler(const char* msg) {
std::strncpy(mju_error_msg.data(), msg, mju_error_msg.size());
std::strncpy(mju_error_msg.data(), msg, mju_error_msg.size() - 1);
mju_error_msg.data()[mju_error_msg.size() - 1] = '\0';
std::longjmp(mju_error_jmp_buf, 1);
}
+8 -2
View File
@@ -25,6 +25,11 @@
namespace mujoco::python {
namespace {
template <typename T, int N>
constexpr inline std::size_t sizeof_arr(const T(&arr)[N]) {
return sizeof(arr);
}
PYBIND11_MODULE(_simulate, pymodule) {
namespace py = ::pybind11;
using SimulateMutex = decltype(mujoco::Simulate::mtx);
@@ -138,8 +143,9 @@ PYBIND11_MODULE(_simulate, pymodule) {
return simulate.loadError;
},
[](mujoco::Simulate& simulate, const std::string& error) {
std::strncpy(simulate.loadError, error.c_str(),
simulate.kMaxFilenameLength);
const auto max_length = sizeof_arr(simulate.loadError);
std::strncpy(simulate.loadError, error.c_str(), max_length - 1);
simulate.loadError[max_length - 1] = '\0';
});
pymodule.def("setglfwdlhandle", [](std::uintptr_t dlhandle) {