Skip to content

Commit cd28ddc

Browse files
committed
fix(compat.opencv): off-linux dnn — drop Vulkan vkcom backend (dead w/o SDK, breaks off-linux scan) + mlas platform.cpp -include unistd.h is POSIX-only (windows has none)
1 parent 5ca1e46 commit cd28ddc

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

pkgs/c/compat.opencv.lua

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ package = {
1313
features = {
1414
dnn = {
1515
defines = { "HAVE_OPENCV_DNN" },
16-
flags = {
17-
{
18-
cxxflags = { "-include", "unistd.h" },
19-
glob = "*/3rdparty/mlas/lib/platform.cpp",
20-
},
21-
},
16+
flags = {},
2217
sources = {
2318
"*/3rdparty/mlas/lib/*.cpp",
2419
"*/3rdparty/protobuf/src/google/protobuf/*.cc",
@@ -36,9 +31,6 @@ package = {
3631
"*/modules/dnn/src/tensorflow/*.cpp",
3732
"*/modules/dnn/src/tflite/tflite_importer.cpp",
3833
"*/modules/dnn/src/tokenizer/*.cpp",
39-
"*/modules/dnn/src/vkcom/shader/*.cpp",
40-
"*/modules/dnn/src/vkcom/src/*.cpp",
41-
"*/modules/dnn/src/vkcom/vulkan/*.cpp",
4234
"mcpp_generated/mlas_hgemm_stub.cpp",
4335
},
4436
},
@@ -163,6 +155,10 @@ package = {
163155
},
164156
glob = "**/modules/dnn/**/*.avx512_skx.cpp",
165157
},
158+
{
159+
cxxflags = { "-include", "unistd.h" },
160+
glob = "*/3rdparty/mlas/lib/platform.cpp",
161+
},
166162
},
167163
sources = {
168164
"*/3rdparty/mlas/lib/x86_64/*.S",
@@ -3918,6 +3914,10 @@ mcpp_generated/modules/imgproc/{accum.avx,accum.avx2,accum.sse4_1,bilateral_filt
39183914
defines = { "CV_CPU_DISPATCH_MODE=NEON" },
39193915
glob = "mcpp_generated/modules/dnn/layers/layers_common.neon.cpp",
39203916
},
3917+
{
3918+
cxxflags = { "-include", "unistd.h" },
3919+
glob = "*/3rdparty/mlas/lib/platform.cpp",
3920+
},
39213921
},
39223922
sources = {
39233923
"*/3rdparty/mlas/lib/aarch64/*.S",
@@ -7428,17 +7428,6 @@ jpeg16 3rdparty/libjpeg-turbo/src/jutils.c
74287428
},
74297429
glob = "*/3rdparty/mlas/lib/flashattn.cpp",
74307430
},
7431-
{
7432-
defines = {
7433-
"NDEBUG",
7434-
"WIN32",
7435-
"_CRT_NONSTDC_NO_DEPRECATE",
7436-
"_CRT_SECURE_NO_DEPRECATE",
7437-
"_SCL_SECURE_NO_WARNINGS",
7438-
"_WINDOWS",
7439-
},
7440-
glob = "*/3rdparty/mlas/lib/platform.cpp",
7441-
},
74427431
{
74437432
defines = {
74447433
"NDEBUG",

tools/compat-opencv/merge_opencv.lua

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,32 @@ local function is_dnn_glob(g)
148148
end
149149
local function ser_id(v) return ser(v, "") end
150150

151+
-- dnn's Vulkan compute backend (modules/dnn/src/vkcom/**) is dead code without a
152+
-- Vulkan SDK (WITH_VULKAN is OFF in every headless profile); its sources #include
153+
-- <opencv2/dnn.hpp> from a nested dir and fail mcpp's dependency scan off-linux.
154+
-- Drop them from the feature entirely — CPU dnn inference is unaffected.
155+
local function is_vkcom(s) return type(s) == "string" and s:find("modules/dnn/src/vkcom", 1, true) ~= nil end
156+
-- the mlas platform.cpp `-include unistd.h` curated exception is POSIX-only
157+
-- (glibc/darwin have unistd.h; windows does not -> `fatal error: 'unistd.h'`).
158+
local function is_unistd_platform_flag(f)
159+
return type(f) == "table" and type(f.glob) == "string"
160+
and f.glob:find("3rdparty/mlas/lib/platform.cpp", 1, true) ~= nil
161+
end
151162
local pkgs, order = {}, {}
152163
for _, e in ipairs(INPUTS) do pkgs[e.os] = load_pkg(e.path); order[#order+1] = e.os end
153164
local dnn_src, dnn_flg, base_flg = {}, {}, {}
154165
for _, os_ in ipairs(order) do
155166
local p = pkgs[os_]
156167
local feat = (p.mcpp.features and p.mcpp.features.dnn) or {}
157168
local srcs, flgs, cleaned = {}, {}, {}
158-
for _, s in ipairs(feat.sources or {}) do srcs[#srcs+1] = s end
159-
for _, f in ipairs(feat.flags or {}) do flgs[#flgs+1] = f end
169+
local drop_unistd = (os_ == "windows")
170+
for _, s in ipairs(feat.sources or {}) do if not is_vkcom(s) then srcs[#srcs+1] = s end end
171+
for _, f in ipairs(feat.flags or {}) do
172+
if not (drop_unistd and is_unistd_platform_flag(f)) then flgs[#flgs+1] = f end
173+
end
160174
for _, f in ipairs(p.mcpp.flags or {}) do
161-
if type(f) == "table" and is_dnn_glob(f.glob) then flgs[#flgs+1] = f
175+
if type(f) == "table" and is_dnn_glob(f.glob) then
176+
if not (drop_unistd and is_unistd_platform_flag(f)) then flgs[#flgs+1] = f end
162177
else cleaned[#cleaned+1] = f end
163178
end
164179
dnn_src[os_], dnn_flg[os_], base_flg[os_] = srcs, flgs, cleaned

0 commit comments

Comments
 (0)