Skip to content

Commit 3114651

Browse files
Copilottianleiwu
andauthored
Update microsoft_gsl from v4.0.0 to v4.2.1 (fixes C4875 deprecation) (#28527)
### Description Upgrades `microsoft_gsl` to v4.2.1 and patches `GSL_SUPPRESS` to stringify its argument for MSVC, fixing the C4875 deprecation warning in VC++ 18.6.0. - **`cmake/deps.txt`** — Bump to v4.2.1 - **`cmake/patches/gsl/1064.patch`** — Removed; the NVCC guard (`!defined(__NVCC__)`) is already upstream in v4.2.1 - **`cmake/patches/gsl/1213.patch`** — New patch: `[[gsl::suppress(x)]]` → `[[gsl::suppress(#x)]]` for MSVC, matching upstream microsoft/GSL@543d0dd (PR microsoft/GSL#1213) - **`cmake/external/onnxruntime_external_deps.cmake`** — Removed the `if(onnxruntime_USE_CUDA)` conditional around the patch; the stringify fix applies to all MSVC builds, not just CUDA - **`cmake/vcpkg.json`** — Added `"version>=": "4.2.1"` constraint for `ms-gsl` to ensure vcpkg builds also pick up a version that includes the NVCC guard fix ### Motivation and Context GSL v4.0.0's `GSL_SUPPRESS` macro passes a non-string-literal to `[[gsl::suppress()]]`. VC++ 18.6.0 deprecates this form (C4875), and a future MSVC release will remove it entirely, breaking the build. The warning fires on essentially every translation unit via `capture.h` / `narrow.h`. The upstream fix (stringify via `#x`) hasn't shipped in a GSL release yet, so a local patch is still needed until a future GSL release includes it. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
1 parent df44eab commit 3114651

5 files changed

Lines changed: 28 additions & 46 deletions

File tree

cmake/deps.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ googletest;https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip;f6
3030
#xnnpack 2025.06.22
3131
googlexnnpack;https://github.com/google/XNNPACK/archive/3cf85e705098622d59056dcb8f5f963ea7bb0a00.zip;6f6bbba627241f89463ca845febaf063982b34fe
3232
json;https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.zip;5e88795165cc8590138d1f47ce94ee567b85b4d6
33-
microsoft_gsl;https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.zip;cf368104cd22a87b4dd0c80228919bb2df3e2a14
33+
microsoft_gsl;https://github.com/microsoft/GSL/archive/refs/tags/v4.2.1.zip;1094e3bb7a8af763dcb136ccd676e6e75e614eec
3434
microsoft_wil;https://github.com/microsoft/wil/archive/refs/tags/v1.0.250325.1.zip;826c8bd47c2258ec61b8b218e031e5b33d27f761
3535
mimalloc;https://github.com/microsoft/mimalloc/archive/refs/tags/v2.1.1.zip;d5ee7d34223d0567892db5179849939c8769dc41
3636
mp11;https://github.com/boostorg/mp11/archive/refs/tags/boost-1.82.0.zip;9bc9e01dffb64d9e0773b2e44d2f22c51aace063

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -405,24 +405,16 @@ if (CPUINFO_SUPPORTED)
405405
endif()
406406
endif()
407407

408-
if(onnxruntime_USE_CUDA)
409-
onnxruntime_fetchcontent_declare(
410-
GSL
411-
URL ${DEP_URL_microsoft_gsl}
412-
URL_HASH SHA1=${DEP_SHA1_microsoft_gsl}
413-
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch
414-
EXCLUDE_FROM_ALL
415-
FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL
416-
)
417-
else()
418-
onnxruntime_fetchcontent_declare(
419-
GSL
420-
URL ${DEP_URL_microsoft_gsl}
421-
URL_HASH SHA1=${DEP_SHA1_microsoft_gsl}
422-
EXCLUDE_FROM_ALL
423-
FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL
424-
)
425-
endif()
408+
onnxruntime_fetchcontent_declare(
409+
GSL
410+
URL ${DEP_URL_microsoft_gsl}
411+
URL_HASH SHA1=${DEP_SHA1_microsoft_gsl}
412+
# Stringify fix for GSL_SUPPRESS on MSVC (C4875). Remove when GSL ships a release
413+
# containing microsoft/GSL#1213 (commit 543d0dd).
414+
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1213.patch
415+
EXCLUDE_FROM_ALL
416+
FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL
417+
)
426418
set(GSL_TARGET "Microsoft.GSL::GSL")
427419
set(GSL_INCLUDE_DIR "$<TARGET_PROPERTY:${GSL_TARGET},INTERFACE_INCLUDE_DIRECTORIES>")
428420
onnxruntime_fetchcontent_makeavailable(GSL)

cmake/patches/gsl/1064.patch

Lines changed: 0 additions & 26 deletions
This file was deleted.

cmake/patches/gsl/1213.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/include/gsl/assert b/include/gsl/assert
2+
index 58e0426..b3f7c8a 100644
3+
--- a/include/gsl/assert
4+
+++ b/include/gsl/assert
5+
@@ -50,7 +50,7 @@
6+
#define GSL_SUPPRESS(x) [[gsl::suppress(#x)]]
7+
#else
8+
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__NVCC__)
9+
-#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
10+
+#define GSL_SUPPRESS(x) [[gsl::suppress(#x)]]
11+
#else
12+
#define GSL_SUPPRESS(x)
13+
#endif // _MSC_VER

cmake/vcpkg.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
"name": "mimalloc",
4141
"platform": "windows"
4242
},
43-
"ms-gsl",
43+
{
44+
"name": "ms-gsl",
45+
"version>=": "4.2.1"
46+
},
4447
"nlohmann-json",
4548
"onnx",
4649
{

0 commit comments

Comments
 (0)