From 9b4a763f56393111560830ece791e70d325e377f Mon Sep 17 00:00:00 2001 From: kushagharahi <3326002+kushagharahi@users.noreply.github.com> Date: Fri, 6 Mar 2026 00:21:48 -0600 Subject: [PATCH 1/5] introduce LLAMA_SERVER_NO_WEBUI --- CMakeLists.txt | 1 + tools/server/CMakeLists.txt | 35 +++++++++++++++++++++-------------- tools/server/server-http.cpp | 9 ++++++++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69da97dc1e..425d7addc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_TOOLS "llama: build tools" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE}) +option(LLAMA_SERVER_NO_WEBUI "llama: disable the embedded Web UI in server" OFF) option(LLAMA_TOOLS_INSTALL "llama: install tools" ${LLAMA_TOOLS_INSTALL_DEFAULT}) option(LLAMA_TESTS_INSTALL "llama: install tests" ON) diff --git a/tools/server/CMakeLists.txt b/tools/server/CMakeLists.txt index 5621a51b22..ceb17ddd1e 100644 --- a/tools/server/CMakeLists.txt +++ b/tools/server/CMakeLists.txt @@ -35,22 +35,29 @@ set(TARGET_SRCS server-models.cpp server-models.h ) -set(PUBLIC_ASSETS - index.html.gz - loading.html -) -foreach(asset ${PUBLIC_ASSETS}) - set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}") - set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp") - list(APPEND TARGET_SRCS ${output}) - add_custom_command( - DEPENDS "${input}" - OUTPUT "${output}" - COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake" +option(LLAMA_SERVER_NO_WEBUI "Disable the embedded Web UI" OFF) + +if (NOT LLAMA_SERVER_NO_WEBUI) + set(PUBLIC_ASSETS + index.html.gz + loading.html ) - set_source_files_properties(${output} PROPERTIES GENERATED TRUE) -endforeach() + + foreach(asset ${PUBLIC_ASSETS}) + set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}") + set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp") + list(APPEND TARGET_SRCS ${output}) + add_custom_command( + DEPENDS "${input}" + OUTPUT "${output}" + COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake" + ) + set_source_files_properties(${output} PROPERTIES GENERATED TRUE) + endforeach() +else() + add_definitions(-DLLAMA_SERVER_NO_WEBUI) +endif() add_executable(${TARGET} ${TARGET_SRCS}) install(TARGETS ${TARGET} RUNTIME) diff --git a/tools/server/server-http.cpp b/tools/server/server-http.cpp index 129022a711..a362d959a9 100644 --- a/tools/server/server-http.cpp +++ b/tools/server/server-http.cpp @@ -8,9 +8,11 @@ #include #include +#ifndef LLAMA_SERVER_NO_WEBUI // auto generated files (see README.md for details) #include "index.html.gz.hpp" #include "loading.html.hpp" +#endif // // HTTP implementation using cpp-httplib @@ -181,11 +183,14 @@ bool server_http_context::init(const common_params & params) { auto middleware_server_state = [this](const httplib::Request & req, httplib::Response & res) { bool ready = is_ready.load(); if (!ready) { +#ifndef LLAMA_SERVER_NO_WEBUI auto tmp = string_split(req.path, '.'); if (req.path == "/" || tmp.back() == "html") { res.status = 503; res.set_content(reinterpret_cast(loading_html), loading_html_len, "text/html; charset=utf-8"); - } else { + } else +#endif + { // no endpoints is allowed to be accessed when the server is not ready // this is to prevent any data races or inconsistent states res.status = 503; @@ -249,6 +254,7 @@ bool server_http_context::init(const common_params & params) { return 1; } } else { +#ifndef LLAMA_SERVER_NO_WEBUI // using embedded static index.html srv->Get(params.api_prefix + "/", [](const httplib::Request & req, httplib::Response & res) { if (req.get_header_value("Accept-Encoding").find("gzip") == std::string::npos) { @@ -262,6 +268,7 @@ bool server_http_context::init(const common_params & params) { } return false; }); +#endif } } return true; From f6f5715a861bb7eb3f8f4d147688a011bbda6adb Mon Sep 17 00:00:00 2001 From: kushagharahi <3326002+kushagharahi@users.noreply.github.com> Date: Fri, 6 Mar 2026 00:24:24 -0600 Subject: [PATCH 2/5] =?UTF-8?q?LLAMA=5FSERVER=5FNO=5FWEBUI=20=E2=86=92=20L?= =?UTF-8?q?LAMA=5FBUILD=5FWEBUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- tools/server/CMakeLists.txt | 6 +++--- tools/server/server-http.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 425d7addc1..9c6bcbead8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_TOOLS "llama: build tools" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE}) -option(LLAMA_SERVER_NO_WEBUI "llama: disable the embedded Web UI in server" OFF) +option(LLAMA_BUILD_WEBUI "llama: build the embedded Web UI for server" ${LLAMA_STANDALONE}) option(LLAMA_TOOLS_INSTALL "llama: install tools" ${LLAMA_TOOLS_INSTALL_DEFAULT}) option(LLAMA_TESTS_INSTALL "llama: install tests" ON) diff --git a/tools/server/CMakeLists.txt b/tools/server/CMakeLists.txt index ceb17ddd1e..abb6637716 100644 --- a/tools/server/CMakeLists.txt +++ b/tools/server/CMakeLists.txt @@ -36,9 +36,9 @@ set(TARGET_SRCS server-models.h ) -option(LLAMA_SERVER_NO_WEBUI "Disable the embedded Web UI" OFF) +option(LLAMA_BUILD_WEBUI "Build the embedded Web UI" ${LLAMA_STANDALONE}) -if (NOT LLAMA_SERVER_NO_WEBUI) +if (LLAMA_BUILD_WEBUI) set(PUBLIC_ASSETS index.html.gz loading.html @@ -55,8 +55,8 @@ if (NOT LLAMA_SERVER_NO_WEBUI) ) set_source_files_properties(${output} PROPERTIES GENERATED TRUE) endforeach() + add_definitions(-DLLAMA_BUILD_WEBUI) else() - add_definitions(-DLLAMA_SERVER_NO_WEBUI) endif() add_executable(${TARGET} ${TARGET_SRCS}) diff --git a/tools/server/server-http.cpp b/tools/server/server-http.cpp index a362d959a9..8cc96684f1 100644 --- a/tools/server/server-http.cpp +++ b/tools/server/server-http.cpp @@ -8,7 +8,7 @@ #include #include -#ifndef LLAMA_SERVER_NO_WEBUI +#ifdef LLAMA_BUILD_WEBUI // auto generated files (see README.md for details) #include "index.html.gz.hpp" #include "loading.html.hpp" @@ -183,7 +183,7 @@ bool server_http_context::init(const common_params & params) { auto middleware_server_state = [this](const httplib::Request & req, httplib::Response & res) { bool ready = is_ready.load(); if (!ready) { -#ifndef LLAMA_SERVER_NO_WEBUI +#ifdef LLAMA_BUILD_WEBUI auto tmp = string_split(req.path, '.'); if (req.path == "/" || tmp.back() == "html") { res.status = 503; @@ -254,7 +254,7 @@ bool server_http_context::init(const common_params & params) { return 1; } } else { -#ifndef LLAMA_SERVER_NO_WEBUI +#ifdef LLAMA_BUILD_WEBUI // using embedded static index.html srv->Get(params.api_prefix + "/", [](const httplib::Request & req, httplib::Response & res) { if (req.get_header_value("Accept-Encoding").find("gzip") == std::string::npos) { From 86ac8df9a6fc2585f8f588b42cad10587fdf17dd Mon Sep 17 00:00:00 2001 From: kushagharahi <3326002+kushagharahi@users.noreply.github.com> Date: Sun, 22 Mar 2026 08:24:09 -0500 Subject: [PATCH 3/5] LLAMA_BUILD_WEBUI ON by default not based on LLAMA_STANDALONE --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6bcbead8..caea48c506 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_TOOLS "llama: build tools" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE}) option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE}) -option(LLAMA_BUILD_WEBUI "llama: build the embedded Web UI for server" ${LLAMA_STANDALONE}) +option(LLAMA_BUILD_WEBUI "llama: build the embedded Web UI for server" ON) option(LLAMA_TOOLS_INSTALL "llama: install tools" ${LLAMA_TOOLS_INSTALL_DEFAULT}) option(LLAMA_TESTS_INSTALL "llama: install tests" ON) From 8e8f89ae51bbc5bfa64f1d354b6efaf5fdb955b4 Mon Sep 17 00:00:00 2001 From: kushagharahi <3326002+kushagharahi@users.noreply.github.com> Date: Sun, 22 Mar 2026 08:25:18 -0500 Subject: [PATCH 4/5] MIssed this --- tools/server/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/server/CMakeLists.txt b/tools/server/CMakeLists.txt index abb6637716..02432efbb9 100644 --- a/tools/server/CMakeLists.txt +++ b/tools/server/CMakeLists.txt @@ -36,7 +36,7 @@ set(TARGET_SRCS server-models.h ) -option(LLAMA_BUILD_WEBUI "Build the embedded Web UI" ${LLAMA_STANDALONE}) +option(LLAMA_BUILD_WEBUI "Build the embedded Web UI" ON) if (LLAMA_BUILD_WEBUI) set(PUBLIC_ASSETS From 4e112392fcaee3e1e7c54976c1f73c52ba1f2b43 Mon Sep 17 00:00:00 2001 From: kushagharahi <3326002+kushagharahi@users.noreply.github.com> Date: Sun, 22 Mar 2026 20:55:25 -0500 Subject: [PATCH 5/5] Add useWebUi to package.nix --- .devops/nix/package.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.devops/nix/package.nix b/.devops/nix/package.nix index 79a7270e5d..289273e72e 100644 --- a/.devops/nix/package.nix +++ b/.devops/nix/package.nix @@ -41,6 +41,7 @@ effectiveStdenv ? if useCuda then cudaPackages.backendStdenv else stdenv, enableStatic ? effectiveStdenv.hostPlatform.isStatic, precompileMetalShaders ? false, + useWebUi ? true, }: let @@ -164,6 +165,7 @@ effectiveStdenv.mkDerivation (finalAttrs: { cmakeFlags = [ (cmakeBool "LLAMA_BUILD_SERVER" true) + (cmakeBool "LLAMA_BUILD_WEBUI" useWebUi) (cmakeBool "BUILD_SHARED_LIBS" (!enableStatic)) (cmakeBool "CMAKE_SKIP_BUILD_RPATH" true) (cmakeBool "GGML_NATIVE" false)