diff --git a/misc/ollama/Makefile b/misc/ollama/Makefile index 1a3552c87d85..c8778fe3d2da 100644 --- a/misc/ollama/Makefile +++ b/misc/ollama/Makefile @@ -1,150 +1,150 @@ PORTNAME= ollama DISTVERSIONPREFIX= v -DISTVERSION= 0.18.2 -PORTREVISION= 1 +DISTVERSION= 0.18.3 CATEGORIES= misc # machine-learning MAINTAINER= yuri@FreeBSD.org COMMENT= Run Llama 2, Mistral, and other large language models WWW= https://ollama.com \ https://github.com/ollama/ollama LICENSE= MIT LICENSE_FILE= ${WRKSRC}/LICENSE BROKEN_i386= fails to compile: x/mlxrunner/mlx/memory.go:40:11: 1 << (4 * 10) (untyped int constant 1099511627776) overflows int BUILD_DEPENDS= bash:shells/bash \ ${LOCALBASE}/include/miniaudio/miniaudio.h:audio/miniaudio \ ${LOCALBASE}/include/nlohmann/json_fwd.hpp:devel/nlohmann-json \ ${LOCALBASE}/include/stb/stb_image.h:devel/stb USES= cmake:indirect go:1.24+,modules localbase pkgconfig GO_MODULE= github.com/yurivict/${PORTNAME} # fork with FreeBSD patches GO_TARGET= . GO_ENV+= CGO_CXXFLAGS="${CXXFLAGS}" MLX_CORE_VERSION= 0.30.6 MLX_C_VERSION= 0.5.0 JSON_VERSION= 3.11.3 PLIST_FILES= bin/${PORTNAME} \ bin/ollama-limit-gpu-layers OPTIONS_GROUP= BACKENDS OPTIONS_GROUP_BACKENDS= CPU VULKAN MLX -OPTIONS_DEFAULT= CPU VULKAN MLX +OPTIONS_DEFAULT= CPU VULKAN #MLX CPU_DESC= Build CPU backend shared libraries for various SIMD instruction sets CPU_PLIST_FILES= lib/ollama/libggml-base.so \ lib/ollama/libggml-cpu-alderlake.so \ lib/ollama/libggml-cpu-haswell.so \ lib/ollama/libggml-cpu-icelake.so \ lib/ollama/libggml-cpu-sandybridge.so \ lib/ollama/libggml-cpu-skylakex.so \ lib/ollama/libggml-cpu-sse42.so \ lib/ollama/libggml-cpu-x64.so VULKAN_DESC= Build Vulkan GPU backend shared library VULKAN_BUILD_DEPENDS= glslc:graphics/shaderc \ ${LOCALBASE}/include/vulkan/vulkan.h:graphics/vulkan-headers VULKAN_LIB_DEPENDS= libvulkan.so:graphics/vulkan-loader VULKAN_PLIST_FILES= lib/ollama/libggml-vulkan.so MLX_DESC= Build MLX backend for image generation (CPU) MLX_BUILD_DEPENDS= ${LOCALBASE}/lib/cmake/fmt/fmt-config.cmake:devel/libfmt MLX_LIB_DEPENDS= libopenblas.so:math/openblas MLX_PLIST_FILES= lib/ollama/libmlx.so \ lib/ollama/libmlxc.so +MLX_BROKEN= build fails in 1.18.3 _CMAKE_FLAGS= -DCMAKE_BUILD_TYPE=Release -DGGML_BACKEND_DL=ON -DGGML_BACKEND_DIR=${PREFIX}/lib/ollama .include .if ${PORT_OPTIONS:MMLX} GO_BUILDFLAGS+= -tags mlx DISTFILES+= v${MLX_CORE_VERSION}.tar.gz:mlxsrc \ v${MLX_C_VERSION}.tar.gz:mlxcsrc \ json.tar.xz:jsonsrc MASTER_SITES+= https://github.com/ml-explore/mlx/archive/refs/tags/:mlxsrc \ https://github.com/ml-explore/mlx-c/archive/refs/tags/:mlxcsrc \ https://github.com/nlohmann/json/releases/download/v${JSON_VERSION}/:jsonsrc .endif post-patch: # change import path to the fork @cd ${WRKSRC} && \ (${GREP} -rl ollama/ollama | ${XARGS} ${REINPLACE_CMD} -i '' -e 's|ollama/ollama|yurivict/ollama|g') # update version in go.mod and version.go @${REINPLACE_CMD} -e 's|var Version string = "0.0.0"|var Version string = "${PORTVERSION}"|g' \ ${WRKSRC}/go.mod ${WRKSRC}/version/version.go pre-build-CPU-on: @${MKDIR} ${WRKSRC}/build && \ cd ${WRKSRC}/build && \ ${CMAKE_BIN} ${_CMAKE_FLAGS} .. && \ ${MAKE_CMD} ggml-base && \ ${MAKE_CMD} ggml-cpu pre-build-VULKAN-on: .if !${PORT_OPTIONS:MCPU} && !${PORT_OPTIONS:MMLX} @${MKDIR} ${WRKSRC}/build && \ cd ${WRKSRC}/build && \ ${CMAKE_BIN} ${_CMAKE_FLAGS} .. .endif @cd ${WRKSRC}/build && \ ${MAKE_CMD} ggml-vulkan post-patch-MLX-on: # FreeBSD compatibility fix: add missing netinet/in.h include @${AWK} '/^#include /{print;print "#include ";next}1' \ ${WRKDIR}/mlx-${MLX_CORE_VERSION}/mlx/distributed/ring/ring.cpp > \ ${WRKDIR}/mlx-${MLX_CORE_VERSION}/mlx/distributed/ring/ring.cpp.new && \ ${MV} ${WRKDIR}/mlx-${MLX_CORE_VERSION}/mlx/distributed/ring/ring.cpp.new \ ${WRKDIR}/mlx-${MLX_CORE_VERSION}/mlx/distributed/ring/ring.cpp pre-build-MLX-on: @${MKDIR} ${WRKSRC}/build && \ cd ${WRKSRC}/build && \ OLLAMA_MLX_SOURCE=${WRKDIR}/mlx-${MLX_CORE_VERSION} \ OLLAMA_MLX_C_SOURCE=${WRKDIR}/mlx-c-${MLX_C_VERSION} \ ${CMAKE_BIN} ${_CMAKE_FLAGS} \ -DMLX_ENGINE:BOOL=ON \ -DFETCHCONTENT_FULLY_DISCONNECTED:BOOL=ON \ -DFETCHCONTENT_SOURCE_DIR_JSON:PATH=${WRKDIR}/json \ -DUSE_SYSTEM_FMT:BOOL=ON \ -DMLX_BUILD_TESTS:BOOL=OFF \ -DMLX_BUILD_EXAMPLES:BOOL=OFF \ .. @cd ${WRKSRC}/build && \ ${MAKE_CMD} mlx mlxc post-install: # pending https://github.com/ollama/ollama/issues/6407 ${INSTALL_SCRIPT} ${FILESDIR}/ollama-limit-gpu-layers ${STAGEDIR}${PREFIX}/bin post-install-CPU-on: @${MKDIR} ${STAGEDIR}${PREFIX}/lib/ollama ${INSTALL_LIB} ${WRKSRC}/build/lib/ollama/libggml-base.so \ ${STAGEDIR}${PREFIX}/lib/ollama/ @for f in ${WRKSRC}/build/lib/ollama/libggml-cpu*.so; do \ ${INSTALL_LIB} $$f ${STAGEDIR}${PREFIX}/lib/ollama/; \ done post-install-VULKAN-on: @${MKDIR} ${STAGEDIR}${PREFIX}/lib/ollama ${INSTALL_LIB} ${WRKSRC}/build/lib/ollama/libggml-vulkan.so \ ${STAGEDIR}${PREFIX}/lib/ollama/ post-install-MLX-on: @${MKDIR} ${STAGEDIR}${PREFIX}/lib/ollama ${INSTALL_LIB} ${WRKSRC}/build/lib/ollama/libmlx.so \ ${STAGEDIR}${PREFIX}/lib/ollama/ ${INSTALL_LIB} ${WRKSRC}/build/lib/ollama/libmlxc.so \ ${STAGEDIR}${PREFIX}/lib/ollama/ do-test: @cd ${WRKSRC} && \ ${SETENVI} ${WRK_ENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} test ./... .include diff --git a/misc/ollama/distinfo b/misc/ollama/distinfo index e709a9fc964b..089f57d96267 100644 --- a/misc/ollama/distinfo +++ b/misc/ollama/distinfo @@ -1,11 +1,11 @@ -TIMESTAMP = 1774149327 -SHA256 (go/misc_ollama/ollama-v0.18.2/v0.18.2.mod) = e660ffa37ad33611a4c1248967204e578f07ada9941e63ffe6a6fe3e95ac5039 -SIZE (go/misc_ollama/ollama-v0.18.2/v0.18.2.mod) = 4757 -SHA256 (go/misc_ollama/ollama-v0.18.2/v0.18.2.zip) = 2ad77971884d45d35ba80db3d610cdfb93e7a2f390ea68fe1745085ebf73da4a -SIZE (go/misc_ollama/ollama-v0.18.2/v0.18.2.zip) = 23468279 -SHA256 (go/misc_ollama/ollama-v0.18.2/v0.30.6.tar.gz) = 04d8e3c5d3c3ae748145ffe51d3ad8b72493e1e8597fc0f9dc631ed620b12618 -SIZE (go/misc_ollama/ollama-v0.18.2/v0.30.6.tar.gz) = 4138686 -SHA256 (go/misc_ollama/ollama-v0.18.2/v0.5.0.tar.gz) = dcfc404d7004e6da70170c669dbc920913cb25a59c9f7dac781caf92e524cc86 -SIZE (go/misc_ollama/ollama-v0.18.2/v0.5.0.tar.gz) = 169957 -SHA256 (go/misc_ollama/ollama-v0.18.2/json.tar.xz) = d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d -SIZE (go/misc_ollama/ollama-v0.18.2/json.tar.xz) = 110988 +TIMESTAMP = 1774561377 +SHA256 (go/misc_ollama/ollama-v0.18.3/v0.30.6.tar.gz) = 04d8e3c5d3c3ae748145ffe51d3ad8b72493e1e8597fc0f9dc631ed620b12618 +SIZE (go/misc_ollama/ollama-v0.18.3/v0.30.6.tar.gz) = 4138686 +SHA256 (go/misc_ollama/ollama-v0.18.3/v0.5.0.tar.gz) = dcfc404d7004e6da70170c669dbc920913cb25a59c9f7dac781caf92e524cc86 +SIZE (go/misc_ollama/ollama-v0.18.3/v0.5.0.tar.gz) = 169957 +SHA256 (go/misc_ollama/ollama-v0.18.3/json.tar.xz) = d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d +SIZE (go/misc_ollama/ollama-v0.18.3/json.tar.xz) = 110988 +SHA256 (go/misc_ollama/ollama-v0.18.3/v0.18.3.mod) = e660ffa37ad33611a4c1248967204e578f07ada9941e63ffe6a6fe3e95ac5039 +SIZE (go/misc_ollama/ollama-v0.18.3/v0.18.3.mod) = 4757 +SHA256 (go/misc_ollama/ollama-v0.18.3/v0.18.3.zip) = ef81db55a2230537be59fdcc5b358738bc410c9fb8270bfbd3131e4d654556d5 +SIZE (go/misc_ollama/ollama-v0.18.3/v0.18.3.zip) = 23566929 diff --git a/misc/ollama/files/patch-ml_backend_ggml_ggml_src_ggml-backend-reg.cpp b/misc/ollama/files/patch-ml_backend_ggml_ggml_src_ggml-backend-reg.cpp index 17d3116f0faa..c18b4d4f4090 100644 --- a/misc/ollama/files/patch-ml_backend_ggml_ggml_src_ggml-backend-reg.cpp +++ b/misc/ollama/files/patch-ml_backend_ggml_ggml_src_ggml-backend-reg.cpp @@ -1,18 +1,18 @@ ---- ml/backend/ggml/ggml/src/ggml-backend-reg.cpp.orig 2025-11-29 00:42:10.354754000 -0800 -+++ ml/backend/ggml/ggml/src/ggml-backend-reg.cpp 2025-11-29 00:42:20.531699000 -0800 -@@ -538,11 +538,13 @@ +--- ml/backend/ggml/ggml/src/ggml-backend-reg.cpp.orig 1979-11-30 08:00:00 UTC ++++ ml/backend/ggml/ggml/src/ggml-backend-reg.cpp +@@ -545,11 +545,13 @@ static ggml_backend_reg_t ggml_backend_load_best(const std::vector search_paths; if (user_search_path == nullptr) { #ifdef GGML_BACKEND_DIR + // On FreeBSD, GGML_BACKEND_DIR is set to the correct library directory search_paths.push_back(fs::u8path(GGML_BACKEND_DIR)); -#endif - // default search paths: executable directory, current directory +#else + // Fallback: search executable directory and current directory search_paths.push_back(get_executable_path()); search_paths.push_back(fs::current_path()); +#endif } else { search_paths.push_back(fs::u8path(user_search_path)); } diff --git a/misc/ollama/files/patch-ml_path.go b/misc/ollama/files/patch-ml_path.go index c9a0ef4dfb8f..a35427626861 100644 --- a/misc/ollama/files/patch-ml_path.go +++ b/misc/ollama/files/patch-ml_path.go @@ -1,11 +1,11 @@ ---- ml/path.go.orig 2025-11-29 01:38:34.298472000 -0800 -+++ ml/path.go 2025-11-29 01:39:10.084873000 -0800 -@@ -27,7 +27,7 @@ +--- ml/path.go.orig 1979-11-30 08:00:00 UTC ++++ ml/path.go +@@ -27,7 +27,7 @@ var LibOllamaPath string = func() string { switch runtime.GOOS { case "windows": libPath = filepath.Join(filepath.Dir(exe), "lib", "ollama") - case "linux": + case "linux", "freebsd": libPath = filepath.Join(filepath.Dir(exe), "..", "lib", "ollama") case "darwin": libPath = filepath.Dir(exe) diff --git a/misc/ollama/files/patch-x_imagegen_mlx_CMakeLists.txt b/misc/ollama/files/patch-x_imagegen_mlx_CMakeLists.txt new file mode 100644 index 000000000000..2ebbf324d1a1 --- /dev/null +++ b/misc/ollama/files/patch-x_imagegen_mlx_CMakeLists.txt @@ -0,0 +1,31 @@ +--- x/imagegen/mlx/CMakeLists.txt.orig 2026-03-27 00:01:53 UTC ++++ x/imagegen/mlx/CMakeLists.txt +@@ -98,28 +98,6 @@ file(COPY ${_mlx_c_hdrs} DESTINATION "${CMAKE_SOURCE_D + file(GLOB _mlx_c_hdrs "${mlx-c_SOURCE_DIR}/mlx/c/*.h") + file(COPY ${_mlx_c_hdrs} DESTINATION "${CMAKE_SOURCE_DIR}/x/mlxrunner/mlx/include/mlx/c/") + +-# Regenerate Go/C shim wrappers from the (possibly updated) headers. +-find_program(GO_EXECUTABLE go REQUIRED) +-message(STATUS "Regenerating MLX Go wrappers") +- +-# Go's cgo splits CC on whitespace, so a CC like "C:/Program Files/…/cl.exe" +-# (set by cmake on Windows) breaks with "C:/Program" not found. Clear CC +-# when it contains spaces so cgo falls back to its default (gcc). +-if(WIN32 AND "$ENV{CC}" MATCHES " ") +- set(_SAVE_CC "$ENV{CC}") +- set(ENV{CC} "") +-endif() +- +-execute_process( +- COMMAND ${GO_EXECUTABLE} generate ./x/... +- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +- COMMAND_ERROR_IS_FATAL ANY +-) +- +-if(DEFINED _SAVE_CC) +- set(ENV{CC} "${_SAVE_CC}") +-endif() +- + # For local dev builds, override MLX_VERSION with git describe output + if(TARGET mlx_version AND DEFINED FETCHCONTENT_SOURCE_DIR_MLX) + execute_process(