Skip to content

Commit 3925e0d

Browse files
committed
patch onetbb's assembler probe for native windows builds
oneTBB probes the GNU assembler version by compiling /dev/null, which does not exist when a native Windows cmake drives mingw gcc. The compiler fails with 'no input files', the version regex doesn't match, and math() then chokes on the error text -- taking the whole configure down: CMake Error at cmake/compilers/GNU.cmake:65 (math): math cannot parse the expression: "g++.exe: error: /dev/null: No such file or directory ... * 1000 + ..." MXE doesn't hit this because it cross-builds oneTBB from a POSIX host. Use NUL on Windows, and treat an unparseable probe as an assembler too old for waitpkg rather than a fatal error -- it only guards an optimization, and Rtools42's GCC 10.4 is below the GCC 11 floor for -mwaitpkg regardless.
1 parent b8fd7b1 commit 3925e0d

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

patches/mingw_devnull.diff

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/src/tbb/cmake/compilers/GNU.cmake b/src/tbb/cmake/compilers/GNU.cmake
2+
index cf6d8bdb..4c5e43a9 100644
3+
--- a/src/tbb/cmake/compilers/GNU.cmake
4+
+++ b/src/tbb/cmake/compilers/GNU.cmake
5+
@@ -47,19 +47,42 @@ endif()
6+
# >=2.31.1). Capturing the output in CMake can be done like below. The version
7+
# information is written to either stdout or stderr. To not make any
8+
# assumptions, both are captured.
9+
+
10+
+# The null device is spelled differently on Windows. A mingw build driven by
11+
+# a native Windows CMake (rather than cross-compiled from a POSIX host) has no
12+
+# '/dev/null', and the compiler would fail with "no input files".
13+
+if (WIN32)
14+
+ set(_tbb_null_device "NUL")
15+
+else()
16+
+ set(_tbb_null_device "/dev/null")
17+
+endif()
18+
+
19+
execute_process(
20+
- COMMAND ${CMAKE_COMMAND} -E env "LANG=C" ${CMAKE_CXX_COMPILER} -xc -c /dev/null -Wa,-v -o/dev/null
21+
+ COMMAND ${CMAKE_COMMAND} -E env "LANG=C" ${CMAKE_CXX_COMPILER} -xc -c ${_tbb_null_device} -Wa,-v -o${_tbb_null_device}
22+
OUTPUT_VARIABLE ASSEMBLER_VERSION_LINE_OUT
23+
ERROR_VARIABLE ASSEMBLER_VERSION_LINE_ERR
24+
OUTPUT_STRIP_TRAILING_WHITESPACE
25+
ERROR_STRIP_TRAILING_WHITESPACE
26+
)
27+
+unset(_tbb_null_device)
28+
set(ASSEMBLER_VERSION_LINE ${ASSEMBLER_VERSION_LINE_OUT}${ASSEMBLER_VERSION_LINE_ERR})
29+
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\1" _tbb_gnu_asm_major_version "${ASSEMBLER_VERSION_LINE}")
30+
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\2" _tbb_gnu_asm_minor_version "${ASSEMBLER_VERSION_LINE}")
31+
unset(ASSEMBLER_VERSION_LINE_OUT)
32+
unset(ASSEMBLER_VERSION_LINE_ERR)
33+
unset(ASSEMBLER_VERSION_LINE)
34+
+
35+
+# When the version can't be parsed, the REGEX REPLACE calls above leave the
36+
+# whole (unmatched) probe output behind, which math() below cannot evaluate.
37+
+# Treat that as an assembler too old for waitpkg rather than failing the
38+
+# configure outright -- the probe is only an optimization guard.
39+
+if (NOT _tbb_gnu_asm_major_version MATCHES "^[0-9]+$" OR
40+
+ NOT _tbb_gnu_asm_minor_version MATCHES "^[0-9]+$")
41+
+ message(STATUS "Could not determine the GNU assembler version; assuming it predates waitpkg support")
42+
+ set(_tbb_gnu_asm_major_version 0)
43+
+ set(_tbb_gnu_asm_minor_version 0)
44+
+endif()
45+
+
46+
message(TRACE "Extracted GNU assembler version: major=${_tbb_gnu_asm_major_version} minor=${_tbb_gnu_asm_minor_version}")
47+
48+
math(EXPR _tbb_gnu_asm_version_number "${_tbb_gnu_asm_major_version} * 1000 + ${_tbb_gnu_asm_minor_version}")

src/tbb/cmake/compilers/GNU.cmake

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,42 @@ endif()
4747
# >=2.31.1). Capturing the output in CMake can be done like below. The version
4848
# information is written to either stdout or stderr. To not make any
4949
# assumptions, both are captured.
50+
51+
# The null device is spelled differently on Windows. A mingw build driven by
52+
# a native Windows CMake (rather than cross-compiled from a POSIX host) has no
53+
# '/dev/null', and the compiler would fail with "no input files".
54+
if (WIN32)
55+
set(_tbb_null_device "NUL")
56+
else()
57+
set(_tbb_null_device "/dev/null")
58+
endif()
59+
5060
execute_process(
51-
COMMAND ${CMAKE_COMMAND} -E env "LANG=C" ${CMAKE_CXX_COMPILER} -xc -c /dev/null -Wa,-v -o/dev/null
61+
COMMAND ${CMAKE_COMMAND} -E env "LANG=C" ${CMAKE_CXX_COMPILER} -xc -c ${_tbb_null_device} -Wa,-v -o${_tbb_null_device}
5262
OUTPUT_VARIABLE ASSEMBLER_VERSION_LINE_OUT
5363
ERROR_VARIABLE ASSEMBLER_VERSION_LINE_ERR
5464
OUTPUT_STRIP_TRAILING_WHITESPACE
5565
ERROR_STRIP_TRAILING_WHITESPACE
5666
)
67+
unset(_tbb_null_device)
5768
set(ASSEMBLER_VERSION_LINE ${ASSEMBLER_VERSION_LINE_OUT}${ASSEMBLER_VERSION_LINE_ERR})
5869
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\1" _tbb_gnu_asm_major_version "${ASSEMBLER_VERSION_LINE}")
5970
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\2" _tbb_gnu_asm_minor_version "${ASSEMBLER_VERSION_LINE}")
6071
unset(ASSEMBLER_VERSION_LINE_OUT)
6172
unset(ASSEMBLER_VERSION_LINE_ERR)
6273
unset(ASSEMBLER_VERSION_LINE)
74+
75+
# When the version can't be parsed, the REGEX REPLACE calls above leave the
76+
# whole (unmatched) probe output behind, which math() below cannot evaluate.
77+
# Treat that as an assembler too old for waitpkg rather than failing the
78+
# configure outright -- the probe is only an optimization guard.
79+
if (NOT _tbb_gnu_asm_major_version MATCHES "^[0-9]+$" OR
80+
NOT _tbb_gnu_asm_minor_version MATCHES "^[0-9]+$")
81+
message(STATUS "Could not determine the GNU assembler version; assuming it predates waitpkg support")
82+
set(_tbb_gnu_asm_major_version 0)
83+
set(_tbb_gnu_asm_minor_version 0)
84+
endif()
85+
6386
message(TRACE "Extracted GNU assembler version: major=${_tbb_gnu_asm_major_version} minor=${_tbb_gnu_asm_minor_version}")
6487

6588
math(EXPR _tbb_gnu_asm_version_number "${_tbb_gnu_asm_major_version} * 1000 + ${_tbb_gnu_asm_minor_version}")

0 commit comments

Comments
 (0)