Skip to content

Commit 1ffbf86

Browse files
committed
fix(opencv): wire xim:glibc lib into install() LINK env (host-free crt/libm)
Ground truth from CI (via the temp diagnostic): xim:cmake installs fine; the real failure is cmake's compiler check cannot LINK a test exe — ld: cannot find crt1.o / crti.o / -lm All three live in <xim:glibc>/lib. xim:gcc's specs wire xim:glibc only for RUNTIME (rpath/dynamic-linker), not the link-time startfile/library search — mcpp's build supplies that via LIBRARY_PATH, which an install() subprocess doesn't inherit. On a dev host gcc silently fell back to /usr/lib crt/libc (works but NOT host-free); the minimal CI runner has no libc-dev so it hard-fails. openblas dodged it (archives a .a, never links an exe). Fix: resolve xim:glibc (+ xim:gcc) install dirs via pkginfo and export LIBRARY_PATH=<glibc>/lib:<gcc>/lib64 for the cmake configure/build/install steps — truly host-free. Declare xim:glibc@2.39 explicitly so pkginfo can resolve it.
1 parent 450acbb commit 1ffbf86

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

pkgs/c/compat.opencv.lua

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ package = {
4747

4848
xpm = {
4949
linux = {
50-
deps = { "xim:cmake@4.0.2", "xim:make@latest", "xim:gcc@16.1.0" },
50+
-- xim:glibc is declared explicitly (though transitively pulled by
51+
-- cmake/gcc) so install() can resolve its lib dir via pkginfo for the
52+
-- LINK-time LIBRARY_PATH (crt1.o/crti.o/libm) — see install() below.
53+
deps = { "xim:cmake@4.0.2", "xim:make@latest", "xim:gcc@16.1.0", "xim:glibc@2.39" },
5154
["4.13.0"] = {
5255
-- Plain-string GLOBAL url (no CN mirror table): this session lacks
5356
-- mcpp-res write access. Per the add-package skill, CN users fall
@@ -169,6 +172,28 @@ local function _install_impl()
169172
-- correct for all four.) This matches the header-comment strategy above.
170173
local cmake, make, gcc, gxx = "cmake", "make", "gcc", "g++"
171174

175+
-- xim:gcc's specs wire xim:glibc only for RUNTIME (rpath / dynamic-linker),
176+
-- NOT the LINK-time startfile + library search. mcpp's own build provides that
177+
-- via LIBRARY_PATH; an install() subprocess does NOT inherit it, so cmake's
178+
-- compiler check fails to LINK a test exe with
179+
-- ld: cannot find crt1.o / crti.o / -lm (all in <xim:glibc>/lib).
180+
-- On a dev host it silently fell back to the host's /usr/lib crt/libc (works,
181+
-- but NOT host-free); a minimal CI runner has no libc-dev, so it hard-fails.
182+
-- Point gcc at xim:glibc/lib (+ xim:gcc/lib64 for libgcc_s) via LIBRARY_PATH so
183+
-- the build resolves the ecosystem glibc and stays host-free. (openblas never
184+
-- hit this: it only compiles + archives a .a, it never LINKS an executable.)
185+
local glibc_dir = pkginfo.install_dir("xim:glibc", "2.39")
186+
or pkginfo.install_dir("glibc", "2.39")
187+
local gcc_dir = pkginfo.install_dir("xim:gcc", "16.1.0")
188+
or pkginfo.install_dir("gcc", "16.1.0")
189+
local libpaths = {}
190+
if glibc_dir then table.insert(libpaths, path.join(glibc_dir, "lib")) end
191+
if gcc_dir then table.insert(libpaths, path.join(gcc_dir, "lib64")) end
192+
if #libpaths == 0 then
193+
error("compat.opencv: cannot resolve xim:glibc / xim:gcc lib dirs for the LINK env")
194+
end
195+
local libenv = "export LIBRARY_PATH=" .. sh_quote(table.concat(libpaths, ":")) .. " && "
196+
172197
-- Move the extracted tree INTO the install dir (this CREATES prefix — xim's
173198
-- restricted Lua has no os.mkdir; os.cd is the only dir primitive, same as
174199
-- compat.openblas). Then build out-of-source into ./_bld and install
@@ -209,14 +234,14 @@ local function _install_impl()
209234
}, " ")
210235

211236
os.exec(string.format("bash -c %s", sh_quote(string.format(
212-
"cd %s && %s -S . -B _bld %s > %s 2>&1",
213-
sh_quote(prefix), sh_quote(cmake), dflags, sh_quote(logf)))))
237+
"cd %s && %s%s -S . -B _bld %s > %s 2>&1",
238+
sh_quote(prefix), libenv, sh_quote(cmake), dflags, sh_quote(logf)))))
214239
os.exec(string.format("bash -c %s", sh_quote(string.format(
215-
"cd %s && %s --build _bld -j%d >> %s 2>&1",
216-
sh_quote(prefix), sh_quote(cmake), jobs, sh_quote(logf)))))
240+
"cd %s && %s%s --build _bld -j%d >> %s 2>&1",
241+
sh_quote(prefix), libenv, sh_quote(cmake), jobs, sh_quote(logf)))))
217242
os.exec(string.format("bash -c %s", sh_quote(string.format(
218-
"cd %s && %s --install _bld >> %s 2>&1",
219-
sh_quote(prefix), sh_quote(cmake), sh_quote(logf)))))
243+
"cd %s && %s%s --install _bld >> %s 2>&1",
244+
sh_quote(prefix), libenv, sh_quote(cmake), sh_quote(logf)))))
220245

221246
-- Verify BOTH the static libs AND the installed public headers materialised
222247
-- (exit-0 != correct; and a partial install that lays libs but not headers at

0 commit comments

Comments
 (0)