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

Change MSVC std::mutex workaround #923

Merged
merged 6 commits into from
Jun 30, 2024
Merged
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
8 changes: 0 additions & 8 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,6 @@ jobs:
if: matrix.check_mkvk == 'ONLY'
run: scripts/check_mkvk.ps1

# Works around issues with 2024.06.03.1.0 runner image. See
# https://github.com/actions/runner-images/issues/10004 and
# https://github.com/actions/runner-images/issues/10055
- name: Remove conflicting msvcp140.dll as workaround for runner image bugs.
shell: bash -l {0}
run: |
find "C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk" -name "msvcp140.dll" -exec rm {} \;

- name: Test Windows build
# Tests built for arm64 can't be run as the CI runners are all x64.
if: matrix.arch == 'x64' && matrix.options.tests == 'ON'
Expand Down
34 changes: 30 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
endif()

#cmake_print_variables(
# CMAKE_CXX_COMPILER_ID
# CMAKE_CXX_COMPILER_VERSION
# CMAKE_CXX_COMPILER_FRONTEND_VARIANT
#)

# Compiler accepts MSVC-style command line options
set(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
# Compiler accepts GNU-style command line options
Expand Down Expand Up @@ -609,6 +615,21 @@ macro(common_libktx_settings target enable_write library_type)
PRIVATE
# Only set dllexport when building a shared library.
$<$<STREQUAL:${library_type},SHARED>:KTX_API=__declspec\(dllexport\)>
# Code compiled with the versions shown defaults to a constexpr
# std::mutex constructor and requires a mscvp140.dll of at least
# version 14.40.33810.00 otherwise code creating a mutex
# crashes mysteriously. Since many JVM installations bundle
# their own version of the VC++ redistributables chances are
# high they will not have a modern enough version so JNI modules
# linked with libktx will crash when multiple threads are used,
# as they are in the BasisU and ASTC encoders.
#
# To avoid this set a define to prevent the compiler using
# constexpr mutex constructors. Remove this eventually after
# in-use JVM installations have at least this VC runtime. Remove
# also from ASTCENC_LIB_TARGET settings around line 1169.
$<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.40.33811>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
$<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,17.0.3>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
PUBLIC # only for basisu_c_binding.
BASISU_NO_ITERATOR_DEBUG_LEVEL
)
Expand Down Expand Up @@ -805,10 +826,6 @@ PRIVATE
# Turn off these warnings until Rich fixes the occurences.
# It it not clear to me if generator expressions can be used here
# hence the long-winded way.
#message(STATUS
# "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID} "
# "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}"
#)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Currently no need to disable any warnings in basisu code. Rich fixed them.
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down Expand Up @@ -1150,6 +1167,15 @@ endif()
set(ASTCENC_CLI OFF) # Only build as library not the CLI astcencoder
add_subdirectory(external/astc-encoder)
set_property(TARGET ${ASTCENC_LIB_TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(
${ASTCENC_LIB_TARGET}
PRIVATE
# ASTC encoder uses std::mutex. For more info. see comment about
# same setting in libktx starting about line 618. To be eventually
# removed as noted in that comment.
$<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.40.33811>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
$<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,17.0.3>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
)

if(KTX_FEATURE_STATIC_LIBRARY AND APPLE)
# Make a single static library to simplify linking.
Expand Down
12 changes: 6 additions & 6 deletions tests/loadtests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright 2017-2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

if(WIN32)
cmake_print_variables(
CMAKE_SYSTEM_VERSION
CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
)
endif()
#if(WIN32)
# cmake_print_variables(
# CMAKE_SYSTEM_VERSION
# CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
# )
#endif()

if(NOT APPLE_LOCKED_OS)
set( fp_pref ${CMAKE_FIND_PACKAGE_PREFER_CONFIG} )
Expand Down
Loading