diff --git a/misc/py-onnxruntime/Makefile b/misc/py-onnxruntime/Makefile index 4d3a5c167bd4..a3ec059102f8 100644 --- a/misc/py-onnxruntime/Makefile +++ b/misc/py-onnxruntime/Makefile @@ -1,83 +1,76 @@ PORTNAME= onnxruntime DISTVERSIONPREFIX= v DISTVERSION= 1.27.0 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= misc # machine-learning PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} DIST_SUBDIR= ${PORTNAME} MAINTAINER= yuri@FreeBSD.org COMMENT= Cross-platform, high performance ML inferencing & training accelerator WWW= https://onnxruntime.ai/ \ https://github.com/microsoft/onnxruntime LICENSE= MIT LICENSE_FILE= ${WRKSRC}/LICENSE BUILD_DEPENDS= cmake:devel/cmake-core \ ${PYTHON_PKGNAMEPREFIX}packaging>=0:devel/py-packaging@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}setuptools>=0:devel/py-setuptools@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}wheel>=0:devel/py-wheel@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}numpy>=1.21.6:math/py-numpy@${PY_FLAVOR} RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}numpy>=1.21.6:math/py-numpy@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}packaging>=0:devel/py-packaging@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}protobuf>=4.25.8:devel/py-protobuf@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}flatbuffers>=0:devel/py-flatbuffers@${PY_FLAVOR} USES= compiler:c++17-lang python USE_PYTHON= pep517 autoplist concurrent -# Build using the official build.py script; wheel is left in ${WRKDIR}/build/Release/dist. +# Build using the official build.py script PEP517_BUILD_DEPEND= -PEP517_INSTALL_CMD= ${PYTHON_CMD} -m installer --destdir ${STAGEDIR} --prefix ${PREFIX} ${WRKDIR}/build/Release/dist/onnxruntime-${DISTVERSION}*.whl + +MAKE_ENV+= ORT_DIST_DIR=${WRKSRC}/dist do-build: cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \ ${PYTHON_CMD} tools/ci_build/build.py \ --build_dir ${WRKDIR}/build \ --config Release \ --parallel \ --skip_tests \ --skip_submodule_sync \ --allow_running_as_root \ --enable_pybind \ --build_wheel \ --cmake_extra_defines CMAKE_INSTALL_PREFIX=${PREFIX} \ --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF \ --cmake_extra_defines ONNXRUNTIME_NUMPY_INCLUDE_DIR=${PYTHONPREFIX_SITELIBDIR}/numpy/_core/include -# The upstream wheel build does not include the native pybind extension, so -# install it alongside the pure-Python files and add it to the autoplist. -post-install: - ${INSTALL_DATA} ${WRKDIR}/build/Release/onnxruntime/capi/onnxruntime_pybind11_state.so \ - ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/onnxruntime/capi/ - @${ECHO_CMD} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/onnxruntime/capi/onnxruntime_pybind11_state.so \ - >> ${_PYTHONPKGLIST} - USE_GITHUB= yes GH_ACCOUNT= microsoft GH_TUPLE= emscripten-core:emsdk:0742117:emsdk/cmake/external/emsdk \ google:libprotobuf-mutator:7a2ed51a6b682a83e345ff49fc4cfd7ca47550db:libprotobuf_mutator/cmake/external/libprotobuf-mutator \ onnx:onnx:b8baa8446686496da4cc8fda09f2b6fe65c2a02c:onnx/cmake/external/onnx CXXFLAGS+= -Wno-array-bounds # workaround for https://github.com/microsoft/onnxruntime/issues/23410 CXXFLAGS+= -I${WRKSRC}/include/onnxruntime/core/common/logging # otherwise logging.h isn't found CXXFLAGS_powerpc64le= -Wno-error=deprecated-declarations DEPS_FILE= ${WRKSRC}/cmake/deps.txt CONFLICTS_BUILD= abseil benchmark nsync googletest dlpack flatbuffers gsl mimalloc \ nlohmann-json onnx protobuf psimd pthreadpool pybind11 re2 dev-update-deps-in-makefiles: extract # this should be run when the port is updated @${FILESDIR}/convert-deps.sh ${DEPS_FILE} post-patch: @${FIND} ${WRKSRC}/cmake/external -name "*.cmake" -exec ${REINPLACE_CMD} -e 's|--binary ||g' {} + pre-configure: @${REINPLACE_CMD} -E 's|;(https://.*)/([^/]+\.zip);|;file://${DISTDIR}/${DIST_SUBDIR}/\2;|' ${DEPS_FILE} .include .include .include diff --git a/misc/py-onnxruntime/files/patch-setup.py b/misc/py-onnxruntime/files/patch-setup.py new file mode 100644 index 000000000000..69bc35ddb8ef --- /dev/null +++ b/misc/py-onnxruntime/files/patch-setup.py @@ -0,0 +1,15 @@ +--- setup.py.orig 2026-08-15 00:00:00 UTC ++++ setup.py +@@ -434,6 +434,12 @@ elif platform.system() == "Darwin": + libs.extend(["libonnxruntime_providers_vitisai.dylib"]) + if nightly_build: + libs.extend(["libonnxruntime_pywrapper.dylib"]) ++elif platform.system() == "FreeBSD": ++ libs = [ ++ "onnxruntime_pybind11_state.so", ++ "libonnxruntime_providers_shared.so", ++ "libonnxruntime.so*", ++ ] + else: + libs = [ + "onnxruntime_pybind11_state.pyd", diff --git a/misc/py-onnxruntime/files/patch-tools_ci__build_build.py b/misc/py-onnxruntime/files/patch-tools_ci__build_build.py new file mode 100644 index 000000000000..f4807c853eee --- /dev/null +++ b/misc/py-onnxruntime/files/patch-tools_ci__build_build.py @@ -0,0 +1,11 @@ +--- tools/ci_build/build.py.orig 2026-08-15 00:00:00 UTC ++++ tools/ci_build/build.py +@@ -1953,6 +1953,8 @@ def build_python_wheel( + cwd = os.path.join(cwd, config) + + args = [sys.executable, os.path.join(source_dir, "setup.py"), "bdist_wheel"] ++ if os.environ.get("ORT_DIST_DIR"): ++ args.extend(["--dist-dir", os.environ["ORT_DIST_DIR"]]) + + # Any combination of the following arguments can be applied + if nightly_build: