Skip to content

Commit 8a168ea

Browse files
committed
feat: add protobuf dependency and improve installation process for onnxruntime
1 parent 5cffcc8 commit 8a168ea

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

‎pkgs/c/compat.onnxruntime.lua‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ package = {
4848
},
4949
sources = { "mcpp_generated/onnxruntime_anchor.c" },
5050
targets = { ["onnxruntime"] = { kind = "lib" } },
51-
deps = {},
51+
deps = { ["compat.protobuf"] = "35.1" },
5252
linux = {
5353
requires = { "mcpp:c++-abi=libc++" },
5454
ldflags = { "-Llib", "-lonnxruntime",
5555
"-Wl,-Bdynamic,-lc++,-lc++abi,-lunwind" },
5656
},
5757
macosx = {
5858
requires = { "mcpp:c++-abi=libc++" },
59-
ldflags = { "-Llib", "-lonnxruntime",
60-
"-Wl,-Bdynamic,-lc++,-lc++abi,-lunwind" },
59+
ldflags = { "-Llib", "-lonnxruntime" },
6160
},
6261
windows = {
6362
ldflags = { "-Llib", "-lonnxruntime" },
@@ -94,6 +93,16 @@ local function resolve_cmake()
9493
return nil
9594
end
9695

96+
local function resolve_source(address, version, directory)
97+
local root = pkginfo.install_dir(address, version)
98+
if not root then return nil end
99+
local direct = path.join(root, "CMakeLists.txt")
100+
if os.isfile(direct) then return root end
101+
local nested = path.join(root, directory, "CMakeLists.txt")
102+
if os.isfile(nested) then return path.join(root, directory) end
103+
return nil
104+
end
105+
97106
function install()
98107
local wrap = "onnxruntime-" .. pkginfo.version()
99108
local source = path.join(wrap, "cmake")
@@ -108,6 +117,15 @@ function install()
108117
return false
109118
end
110119

120+
local protobuf = resolve_source("compat:protobuf", "35.1",
121+
"protobuf-35.1")
122+
local abseil = resolve_source("compat:abseil", "20250512.1",
123+
"abseil-cpp-20250512.1")
124+
if not protobuf or not abseil then
125+
log.error("compat.onnxruntime: mcpp protobuf/abseil sources not found")
126+
return false
127+
end
128+
111129
local prefix = pkginfo.install_dir()
112130
local build = path.join(wrap, "mcpp-build")
113131
os.tryrm(prefix)
@@ -121,6 +139,14 @@ function install()
121139
"-DCMAKE_INSTALL_PREFIX=" .. quote(prefix),
122140
"-DCMAKE_SKIP_INSTALL_RULES=OFF",
123141
"-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER",
142+
"-DFETCHCONTENT_SOURCE_DIR_PROTOBUF=" .. quote(protobuf),
143+
"-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=" .. quote(abseil),
144+
"-DCMAKE_C_FLAGS=" .. quote("-I" ..
145+
path.join(protobuf, "third_party", "utf8_range") ..
146+
" -Wno-error=unused-variable -Wno-error=unused-result"),
147+
"-DCMAKE_CXX_FLAGS=" .. quote("-I" ..
148+
path.join(protobuf, "third_party", "utf8_range") ..
149+
" -Wno-error=unused-variable -Wno-error=unused-result"),
124150
"-Donnxruntime_BUILD_SHARED_LIB=ON",
125151
"-Donnxruntime_BUILD_UNIT_TESTS=OFF",
126152
"-Donnxruntime_ENABLE_PYTHON=OFF",
@@ -139,10 +165,10 @@ function install()
139165
"-Donnxruntime_USE_VCPKG=OFF",
140166
"-Dprotobuf_WITH_ZLIB=OFF",
141167
"-Dprotobuf_BUILD_PROTOBUF_BINARIES=ON",
168+
"-Dprotobuf_BUILD_LIBPROTOBUF=ON",
142169
"-Dprotobuf_BUILD_PROTOC_BINARIES=ON",
143170
"-Dprotobuf_BUILD_LIBPROTOC=ON",
144171
"-Dprotobuf_BUILD_TESTS=OFF",
145-
"-Dprotobuf_INSTALL=OFF",
146172
}, " ")
147173
if os.host() == "linux" then
148174
configure = configure .. " -DCMAKE_SHARED_LINKER_FLAGS="

0 commit comments

Comments
 (0)