diff --git a/CMakeLists.txt b/CMakeLists.txt index a3cb79520..98b4a629b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,8 @@ findorfetch( https://github.com/abseil/abseil-cpp.git GIT_TAG ${MUJOCO_DEP_VERSION_abseil} + PATCH_COMMAND + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/PatchAbseil.cmake" TARGETS absl::core_headers EXCLUDE_FROM_ALL diff --git a/cmake/PatchAbseil.cmake b/cmake/PatchAbseil.cmake new file mode 100644 index 000000000..66d61b115 --- /dev/null +++ b/cmake/PatchAbseil.cmake @@ -0,0 +1,31 @@ +# Copyright 2026 DeepMind Technologies Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Backport the architecture flag grouping from Abseil's newer revisions. +# CMake deduplicates compile options, so separate -Xarch and flag options +# can leave an x86-only flag unguarded in an arm64 compile command. +set(copts "${CMAKE_CURRENT_BINARY_DIR}/absl/copts/AbseilConfigureCopts.cmake") +file(READ "${copts}" contents) +set(old [=[list(APPEND ABSL_RANDOM_RANDEN_COPTS "-Xarch_${_arch}" "${_flag}")]=]) +set(new [=[list(APPEND ABSL_RANDOM_RANDEN_COPTS "SHELL:-Xarch_${_arch} ${_flag}")]=]) +string(FIND "${contents}" "${old}" old_position) +if(NOT old_position EQUAL -1) + string(REPLACE "${old}" "${new}" contents "${contents}") + file(WRITE "${copts}" "${contents}") +else() + string(FIND "${contents}" "${new}" new_position) + if(new_position EQUAL -1) + message(FATAL_ERROR "Abseil architecture flag patch no longer applies") + endif() +endif()