Skip to content

Commit 86a64bd

Browse files
committed
fix(pkg): compat.opencl builds its POSIX loader on macOS; the probe member is unix-only
The macOS block built no sources and a consumer failed at link on khrIcd_free_getenv. Upstream builds the same dlopen-based sources on Apple platforms; a runner there reports zero platforms, the loader's own answer. There is no windows entry, so the member declares its dependency under cfg(unix) and compiles to a skip elsewhere.
1 parent ceba8f4 commit 86a64bd

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎pkgs/c/compat.opencl.lua‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,20 @@ package = {
133133
},
134134

135135
macosx = {
136-
-- Apple ships its own libOpenCL as a framework and there is no ICD
137-
-- mechanism, so the loader is built without the linux sources and a
138-
-- consumer links the framework instead of dispatching.
139-
sources = {},
136+
-- The same POSIX sources upstream builds on Apple platforms: the
137+
-- loader enumerates `/etc/OpenCL/vendors` and `OCL_ICD_FILENAMES`
138+
-- through dlopen there exactly as on Linux. A macOS runner has no
139+
-- vendors directory and reports zero platforms, which is the
140+
-- loader's own answer and what tests/examples/opencl asserts.
141+
-- Apple's OpenCL framework is not involved: a program that links
142+
-- this package dispatches through this loader, not the framework.
143+
targets = { ["opencl"] = { kind = "shared", soname = "libOpenCL.1.dylib" } },
144+
sources = {
145+
"*/loader/linux/icd_linux.c",
146+
"*/loader/linux/icd_linux_envvars.c",
147+
"*/loader/linux/icd_linux_library.c",
148+
},
149+
ldflags = { "-ldl" },
140150
runtime = { capabilities = { "opencl.icd.driver" } },
141151
},
142152
},

‎tests/examples/opencl/mcpp.toml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
name = "opencl-tests"
33
version = "0.1.0"
44

5-
# The loader and the runtime adapter. The adapter is what lets the loader's
6-
# dlopen of a host ICD resolve from inside mcpp's own C library; on a runner
7-
# with no driver it is empty, and the loader then reports zero platforms.
8-
[dependencies.compat]
5+
# The loader and, on Linux, the runtime adapter it depends on. The adapter is
6+
# what lets the loader's dlopen of a host ICD resolve from inside mcpp's own
7+
# C library; on a runner with no driver it is empty and the loader reports
8+
# zero platforms. compat.opencl has no windows entry: Windows drivers are
9+
# enumerated through the registry, which this index does not model yet, so
10+
# the test compiles to a skip there.
11+
[target.'cfg(unix)'.dependencies.compat]
912
opencl = "2026.05.29"
13+
14+
[target.'cfg(unix)'.build]
15+
cxxflags = ["-DHAVE_OPENCL_LOADER=1"]

‎tests/examples/opencl/tests/platforms.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
// `<xmmintrin.h>`, which pulls `<stdlib.h>` into the global module before the
1313
// std module is imported, and GCC then reports conflicting language linkage
1414
// for the declarations both provide.
15+
#include <cstdio>
16+
#if !defined(HAVE_OPENCL_LOADER)
17+
int main() {
18+
std::printf("compat.opencl: skipped (no windows entry; drivers are enumerated through the registry there)\n");
19+
return 0;
20+
}
21+
#else
1522
#define CL_TARGET_OPENCL_VERSION 300
1623
#include <CL/cl.h>
1724
#include <CL/cl_ext.h>
18-
#include <cstdio>
1925
#include <vector>
2026

2127
int main() {
@@ -51,3 +57,4 @@ int main() {
5157
}
5258
return 0;
5359
}
60+
#endif

0 commit comments

Comments
 (0)