diff --git a/.github/workflows/linux-windows-release.yml b/.github/workflows/linux-windows-release.yml index fb83b32b..7a300224 100644 --- a/.github/workflows/linux-windows-release.yml +++ b/.github/workflows/linux-windows-release.yml @@ -104,7 +104,8 @@ jobs: run: NFPM="$RUNNER_TEMP/nfpm" scripts/package-linux-distros.sh # Each package installs in a clean container with its declared - # dependencies, and every library the app links or loads resolves. + # dependencies, and every library the app links or loads resolves, as + # does libgomp, which the llama.cpp runtime it downloads links. - name: Check the packages install working-directory: LinuxWindows/dist run: | @@ -112,7 +113,7 @@ jobs: test -x /usr/bin/lokalbot test -f /usr/share/applications/com.lokalbot.LokalBot.desktop if ldd /usr/bin/lokalbot | grep "not found"; then exit 1; fi - for lib in libvulkan.so.1 libwayland-client.so.0; do ldconfig -p | grep -q "$lib" || { echo "missing $lib"; exit 1; }; done + for lib in libvulkan.so.1 libwayland-client.so.0 libgomp.so.1; do ldconfig -p | grep -q "$lib" || { echo "missing $lib"; exit 1; }; done /usr/bin/lokalbot-cli --help > /dev/null' docker run --rm -v "$PWD:/d" ubuntu:24.04 bash -c \ "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends /d/LokalBot-*-linux-amd64.deb > /dev/null && $check" diff --git a/LinuxWindows/README.md b/LinuxWindows/README.md index 5e8ba8c5..6220df26 100644 --- a/LinuxWindows/README.md +++ b/LinuxWindows/README.md @@ -145,7 +145,8 @@ release has none yet, use a CI run's artifacts (`lokalbot-linux-x86_64`, `lokalb - **Linux** (x86_64): extract `LokalBot--linux-x86_64.tar.gz` and run `./install.sh`. It installs `lokalbot` and `lokalbot-cli` into `~/.local/bin` and adds LokalBot to your applications menu. - Runtime needs: a Vulkan or OpenGL driver (Mesa is fine), PulseAudio or PipeWire for system audio. + Runtime needs: a Vulkan or OpenGL driver (Mesa is fine), PulseAudio or PipeWire for system audio, and + for the built-in models the GCC OpenMP runtime (`libgomp1` on Debian and Ubuntu, `libgomp` on Fedora and Arch). The same release has packages that install into `/usr/bin` with their dependencies: `LokalBot--linux-amd64.deb` (Debian, Ubuntu: `sudo apt install ./LokalBot-…deb`), `LokalBot--linux-x86_64.rpm` (Fedora, openSUSE: `sudo dnf install ./LokalBot-…rpm`) and diff --git a/LinuxWindows/crates/lokalbot-ai/src/runtime.rs b/LinuxWindows/crates/lokalbot-ai/src/runtime.rs index 20e10e08..e65b11ed 100644 --- a/LinuxWindows/crates/lokalbot-ai/src/runtime.rs +++ b/LinuxWindows/crates/lokalbot-ai/src/runtime.rs @@ -163,6 +163,18 @@ const SERVER_BINARY: &str = if cfg!(windows) { "llama-server" }; +/// The folder beside `lokalbot.exe` that holds [`VC_RUNTIME_DLLS`] +/// (scripts/package.sh). lokalbot-update's `install.rs` names it too. +pub const VC_RUNTIME_DIR: &str = "vc-runtime"; +/// The Microsoft Visual C++ runtime DLLs upstream's Windows builds import. +/// Windows without the Visual C++ Redistributable has none of them, so each +/// runtime gets the bundled copies beside its `llama-server.exe`. +const VC_RUNTIME_DLLS: [&str; 3] = ["msvcp140.dll", "vcruntime140.dll", "vcruntime140_1.dll"]; +const VC_REDIST_URL: &str = "https://aka.ms/vc14/vc_redist.x64.exe"; +/// STATUS_DLL_NOT_FOUND: Windows found no file for a DLL the program +/// imports. The process exits with it before printing anything. +const STATUS_DLL_NOT_FOUND: i32 = 0xC000_0135_u32 as i32; + // ------------------------------------------------------------------- roles #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -502,6 +514,8 @@ impl Installer { perms.set_mode(perms.mode() | 0o755); std::fs::set_permissions(&server, perms)?; } + // Before any GPU check: a missing system library fails every one. + check_loads(&server)?; let (cuda_libraries, cuda_unverified) = if let Some(build) = cuda_build { let (libraries, checked) = self.prepare_cuda(&server, build, cancel, progress)?; // A GPU filled by another app fails only the final check. Keep @@ -802,6 +816,10 @@ fn find_file(dir: &Path, name: &str, depth: usize) -> Option { fn server_command(binary: &Path) -> Command { let mut command = Command::new(binary); if let Some(dir) = binary.parent() { + #[cfg(windows)] + if let Some(bundled) = bundled_vc_runtime() { + deploy_vc_runtime(&bundled, dir); + } command.current_dir(dir); let extra = if cuda::is_runtime_dir(dir) { cuda::library_dirs() @@ -828,6 +846,108 @@ fn configure_library_path(command: &mut Command, server_dir: &Path, extra: Vec

Option { + let dir = std::env::current_exe().ok()?.parent()?.join(VC_RUNTIME_DIR); + dir.is_dir().then_some(dir) +} + +/// Copies the bundled Visual C++ runtime beside the server in `server_dir`, +/// Microsoft's app-local deployment: Windows loads it before any copy in +/// System32, so the server needs no Visual C++ Redistributable and never runs +/// against an older one. A copy that differs from the bundled one (after an +/// update) is replaced; one a running server holds is replaced at a later start. +#[cfg(any(windows, test))] +fn deploy_vc_runtime(bundled: &Path, server_dir: &Path) { + for name in VC_RUNTIME_DLLS { + let Ok(bytes) = std::fs::read(bundled.join(name)) else { + continue; + }; + let target = server_dir.join(name); + if std::fs::read(&target).is_ok_and(|current| current == bytes) { + continue; + } + let staged = server_dir.join(format!("{name}.new")); + let placed = + std::fs::write(&staged, &bytes).and_then(|()| std::fs::rename(&staged, &target)); + if let Err(err) = placed { + let _ = std::fs::remove_file(&staged); + log::info!("llama.cpp: kept the current {name} beside llama-server: {err}"); + } + } +} + +/// `%SystemRoot%\System32`. +fn system32() -> PathBuf { + std::env::var_os("SystemRoot") + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from(r"C:\Windows")) + .join("System32") +} + +/// Whether Windows finds every Visual C++ runtime DLL for a server in +/// `server_dir`, beside it or installed in System32. Other systems need none. +fn vc_runtime_found(server_dir: &Path) -> bool { + cfg!(not(windows)) + || VC_RUNTIME_DLLS + .iter() + .all(|name| server_dir.join(name).is_file() || system32().join(name).is_file()) +} + +/// What to install when the system could not load llama-server at all. The +/// Linux loader names the library on stderr; Windows only exits with +/// [`STATUS_DLL_NOT_FOUND`], and `vc_runtime_found` tells whether the Visual +/// C++ runtime, the one DLL set outside the runtime folder it needs, is there. +fn missing_library(code: Option, output: &str, vc_runtime_found: bool) -> Option { + if code == Some(STATUS_DLL_NOT_FOUND) { + return Some(if vc_runtime_found { + "Windows could not find a DLL that llama-server needs (error 0xC0000135). Delete the llama.cpp runtime under Settings → Models and download it again.".into() + } else { + format!( + "llama-server needs the Microsoft Visual C++ Redistributable (x64), which isn't installed. Install it from {VC_REDIST_URL}, then try again." + ) + }); + } + // "…/llama-server: error while loading shared libraries: libgomp.so.1: + // cannot open shared object file: No such file or directory" + let library = output + .lines() + .find_map(|line| { + let (_, rest) = line.split_once("error while loading shared libraries: ")?; + Some(rest.split_once(':').map_or(rest, |(name, _)| name).trim()) + }) + .filter(|name| !name.is_empty())?; + let packages = match library { + "libgomp.so.1" => " (libgomp1 on Debian, Ubuntu and openSUSE; libgomp on Fedora and Arch)", + "libvulkan.so.1" => { + " (libvulkan1 on Debian and Ubuntu, vulkan-loader on Fedora, vulkan-icd-loader on Arch)" + } + _ => "", + }; + Some(format!( + "llama-server needs {library}, which isn't installed. Install the package that provides it{packages}, then try again." + )) +} + +/// [`missing_library`] for the server at `binary`. +fn missing_library_for(binary: &Path, code: Option, output: &str) -> Option { + missing_library(code, output, binary.parent().is_some_and(vc_runtime_found)) +} + +/// Fails with what to install when the system cannot load `binary`, so setup +/// never records a runtime that cannot start. +fn check_loads(binary: &Path) -> Result<()> { + let mut command = server_command(binary); + command.arg("--version"); + let out = process::run_capture(command, Duration::from_secs(20))?; + let output = format!("{}\n{}", out.stdout, out.stderr); + match missing_library_for(binary, out.status.and_then(|s| s.code()), &output) { + Some(message) => Err(AiError::ServerStart(message).into()), + None => Ok(()), + } +} + /// `--version` and the conditional flags `--help` lists. fn probe_capabilities(binary: &Path) -> (String, Vec) { let version = process::run_capture( @@ -878,10 +998,7 @@ fn supported_flags(help: &str) -> Vec { fn vulkan_loader_present() -> bool { #[cfg(windows)] { - let root = std::env::var_os("SystemRoot") - .map(PathBuf::from) - .unwrap_or_else(|| PathBuf::from(r"C:\Windows")); - root.join("System32").join("vulkan-1.dll").is_file() + system32().join("vulkan-1.dll").is_file() } #[cfg(not(windows))] { @@ -909,6 +1026,12 @@ fn probe_gpu(binary: &Path, backend: LlamaBackend) -> Result { command.arg("--list-devices"); let out = process::run_capture(command, Duration::from_secs(30))?; if !out.status.is_some_and(|s| s.success()) { + let output = format!("{}\n{}", out.stdout, out.stderr); + if let Some(message) = + missing_library_for(binary, out.status.and_then(|s| s.code()), &output) + { + return Err(anyhow!(message)); + } return Err(anyhow!( "{} device detection failed or timed out: {}", backend.label(), @@ -1552,7 +1675,8 @@ impl ServerInner { backend.label() ); - let failure = |summary: &str, tail: &Mutex| -> anyhow::Error { + // `code`: the exit code of a server that exited during startup. + let failure = |summary: &str, code: Option, tail: &Mutex| { // Let the reader catch the last lines of an exited process. for _ in 0..10 { if tail.lock().finished { @@ -1568,11 +1692,14 @@ impl ServerInner { tail.lines.join(" | ") ); } - let message = match tail.reason() { - Some(reason) => format!("{summary}: {reason}"), - None => summary.to_string(), + let message = match missing_library_for(binary, code, &tail.lines.join("\n")) { + Some(missing) => missing, + None => match tail.reason() { + Some(reason) => format!("{summary}: {reason}"), + None => summary.to_string(), + }, }; - AiError::ServerStart(message).into() + anyhow::Error::from(AiError::ServerStart(message)) }; // Loading a large model can take a while. On GPUs without prebuilt // CUDA kernels the driver first compiles PTX, ~50 s on a Titan Xp; @@ -1584,9 +1711,13 @@ impl ServerInner { }; for _ in 0..attempts { std::thread::sleep(Duration::from_millis(500)); - if !matches!(child.try_wait(), Ok(None)) { - remove_marker_if(paths, self.port, pid); - return Err(failure("llama-server exited during startup", &tail)); + match child.try_wait() { + Ok(None) => {} + exited => { + remove_marker_if(paths, self.port, pid); + let code = exited.ok().flatten().and_then(|status| status.code()); + return Err(failure("llama-server exited during startup", code, &tail)); + } } if health(self.port, &token) { if backend == LlamaBackend::Cuda { @@ -1602,6 +1733,7 @@ impl ServerInner { remove_marker_if(paths, self.port, pid); return Err(failure( "CUDA server did not confirm any model layers on the GPU", + None, &tail, )); } @@ -1632,7 +1764,11 @@ impl ServerInner { } process::stop_child(&mut child, Duration::from_secs(2)); remove_marker_if(paths, self.port, pid); - Err(failure("server did not become healthy in time", &tail)) + Err(failure( + "server did not become healthy in time", + None, + &tail, + )) } /// Deals with a helper recorded on this port. A healthy one with the same @@ -2522,6 +2658,168 @@ mod tests { assert!(probe_gpu(&binary, LlamaBackend::Cuda).is_err()); } + const MISSING_GOMP: &str = "llama-server needs libgomp.so.1, which isn't installed. Install the package that provides it (libgomp1 on Debian, Ubuntu and openSUSE; libgomp on Fedora and Arch), then try again."; + + /// What the dynamic loader prints for llama-server without libgomp1. + #[cfg(unix)] + const MISSING_GOMP_SERVER: &str = "#!/bin/sh\necho \"$0: error while loading shared libraries: libgomp.so.1: cannot open shared object file: No such file or directory\" >&2\nexit 127\n"; + + #[test] + fn missing_system_libraries_say_what_to_install() { + assert_eq!(STATUS_DLL_NOT_FOUND, -1_073_741_515); + let redist = missing_library(Some(STATUS_DLL_NOT_FOUND), "", false).unwrap(); + assert_eq!( + redist, + "llama-server needs the Microsoft Visual C++ Redistributable (x64), which isn't installed. Install it from https://aka.ms/vc14/vc_redist.x64.exe, then try again." + ); + // With the Visual C++ runtime in place, a DLL of the runtime folder is gone. + let other = missing_library(Some(STATUS_DLL_NOT_FOUND), "", true).unwrap(); + assert!( + other.contains("0xC0000135") && other.contains("download it again"), + "{other}" + ); + + // From b11669 in an ubuntu:24.04 container without libgomp1. + let loader = "/root/.local/share/LokalBot/runtimes/llama-cpp/b11669-ubuntu-x64/llama-b11669/llama-server: error while loading shared libraries: libgomp.so.1: cannot open shared object file: No such file or directory"; + assert_eq!( + missing_library(Some(127), loader, true).as_deref(), + Some(MISSING_GOMP) + ); + assert_eq!( + missing_library( + Some(127), + "x: error while loading shared libraries: libfoo.so.3: cannot open shared object file", + true + ) + .as_deref(), + Some( + "llama-server needs libfoo.so.3, which isn't installed. Install the package that provides it, then try again." + ) + ); + assert!( + missing_library( + None, + "a: error while loading shared libraries: libvulkan.so.1: x", + true + ) + .unwrap() + .contains("vulkan-icd-loader on Arch") + ); + + // Other failures keep llama-server's own reason. + assert_eq!( + missing_library(Some(1), "error: failed to load model 'x.gguf'", false), + None + ); + assert_eq!(missing_library(None, "", false), None); + } + + #[test] + fn bundled_vc_runtime_is_placed_and_refreshed_beside_the_server() { + let dir = tempfile::tempdir().unwrap(); + let bundled = dir.path().join(VC_RUNTIME_DIR); + let server = dir.path().join("runtime"); + std::fs::create_dir_all(&bundled).unwrap(); + std::fs::create_dir_all(&server).unwrap(); + for name in VC_RUNTIME_DLLS { + std::fs::write(bundled.join(name), format!("{name} 14.44")).unwrap(); + } + let read = |name: &str| std::fs::read_to_string(server.join(name)).unwrap(); + + deploy_vc_runtime(&bundled, &server); + for name in VC_RUNTIME_DLLS { + assert_eq!(read(name), format!("{name} 14.44")); + } + // An update brings a newer runtime. + std::fs::write(bundled.join("msvcp140.dll"), "msvcp140.dll 14.51").unwrap(); + deploy_vc_runtime(&bundled, &server); + assert_eq!(read("msvcp140.dll"), "msvcp140.dll 14.51"); + assert_eq!(read("vcruntime140.dll"), "vcruntime140.dll 14.44"); + let mut names: Vec = std::fs::read_dir(&server) + .unwrap() + .map(|entry| entry.unwrap().file_name().to_string_lossy().into_owned()) + .collect(); + names.sort(); + assert_eq!(names, VC_RUNTIME_DLLS); + } + + #[test] + #[cfg(unix)] + fn setup_names_a_missing_system_library_and_installs_nothing() { + let dir = tempfile::tempdir().unwrap(); + let manager = RuntimeManager::new(LibraryPaths::new(dir.path()), &Settings::default()); + let installer = &manager.shared.installer; + let asset = asset(LlamaBackend::Cpu).unwrap(); + seed_archive( + &installer.root().join(".downloads"), + asset, + &[(SERVER_BINARY, MISSING_GOMP_SERVER.as_bytes())], + ); + let error = installer + .download_and_unpack(asset, &AtomicBool::new(false), &mut |_, _| {}) + .unwrap_err(); + assert_eq!( + error.to_string(), + format!("Local LLM server failed to start: {MISSING_GOMP}") + ); + assert!(installer.record(LlamaBackend::Cpu).is_none()); + assert!(!installer.folder(asset).exists()); + } + + #[test] + #[cfg(unix)] + fn startup_failure_names_a_missing_system_library() { + use std::os::unix::fs::PermissionsExt as _; + let dir = tempfile::tempdir().unwrap(); + let manager = RuntimeManager::new(LibraryPaths::new(dir.path()), &Settings::default()); + // A free port, so this test never binds a release port. + let port = std::net::TcpListener::bind("127.0.0.1:0") + .unwrap() + .local_addr() + .unwrap() + .port(); + let server = ServerInner { + role: Role::Main, + port, + installer: manager.shared.installer.clone(), + state: Mutex::new(ServerState { + phase: Phase::Stopped, + leases: 0, + idle_since: None, + desired: None, + }), + changed: Condvar::new(), + }; + let binary = dir.path().join(SERVER_BINARY); + std::fs::write(&binary, MISSING_GOMP_SERVER).unwrap(); + std::fs::set_permissions(&binary, std::fs::Permissions::from_mode(0o755)).unwrap(); + let record = InstallRecord { + build: LLAMA_BUILD.into(), + asset: "test".into(), + sha256: String::new(), + backend: LlamaBackend::Cpu, + server: SERVER_BINARY.into(), + version: String::new(), + flags: Vec::new(), + probe: PROBE_VERSION, + cuda_libraries: None, + cuda_unverified: false, + }; + let Err(error) = server.launch( + "test", + Path::new("test.gguf"), + LlamaBackend::Cpu, + &record, + &binary, + ) else { + panic!("a server without libgomp started"); + }; + assert_eq!( + error.to_string(), + format!("Local LLM server failed to start: {MISSING_GOMP}") + ); + } + #[test] fn cancelled_cuda_setup_does_not_probe_or_download() { let dir = tempfile::tempdir().unwrap(); diff --git a/LinuxWindows/crates/lokalbot-update/src/install.rs b/LinuxWindows/crates/lokalbot-update/src/install.rs index fa12a0cb..5f4468c6 100644 --- a/LinuxWindows/crates/lokalbot-update/src/install.rs +++ b/LinuxWindows/crates/lokalbot-update/src/install.rs @@ -21,6 +21,9 @@ pub const APP_ID: &str = "com.lokalbot.LokalBot"; const ICON_SIZES: [u32; 8] = [16, 24, 32, 48, 64, 128, 256, 512]; /// The archive's folder of license texts. const LICENSES_DIR: &str = "LICENSES"; +/// The Windows archive's Visual C++ runtime, which lokalbot-ai's runtime.rs +/// (`VC_RUNTIME_DIR`) copies beside llama-server.exe. +const VC_RUNTIME_DIR: &str = "vc-runtime"; pub const APP_BINARY: &str = if cfg!(windows) { "lokalbot.exe" @@ -257,9 +260,9 @@ struct Replacement { /// archive's `LokalBot--` folder): both binaries, the /// Windows CLI copy, files the archive folder also holds (licenses, notices, /// when LokalBot runs from an extracted archive or the installer's folder), -/// license texts the update adds to that folder's `LICENSES`, then -/// install.sh's desktop entry and icons. Nothing is replaced unless every -/// file could be staged. +/// license texts the update adds to that folder's `LICENSES`, the Visual C++ +/// runtime, then install.sh's desktop entry and icons. Nothing is replaced +/// unless every file could be staged. pub fn install( staged: &Path, targets: &Targets, @@ -336,7 +339,10 @@ fn plan(staged: &Path, targets: &Targets) -> Result, InstallErr let new_license = !present && relative.parent() == Some(Path::new(LICENSES_DIR)) && fs::symlink_metadata(targets.dir.join(LICENSES_DIR)).is_ok_and(|m| m.is_dir()); - if present || new_license { + // Installations from before the Windows archive carried the Visual + // C++ runtime get it too; their llama.cpp runtimes need it. + let vc_runtime = relative.parent() == Some(Path::new(VC_RUNTIME_DIR)); + if present || new_license || vc_runtime { pairs.push((staged.join(&relative), target)); } } @@ -381,6 +387,10 @@ fn sibling(target: &Path, suffix: &str) -> PathBuf { fn stage(replacement: &Replacement) -> io::Result<()> { let _ = fs::remove_file(&replacement.staged); + // The Visual C++ runtime can be new to an installation, folder and all. + if let Some(folder) = replacement.staged.parent() { + fs::create_dir_all(folder)?; + } fs::copy(&replacement.source, &replacement.staged)?; #[cfg(unix)] { @@ -726,6 +736,32 @@ mod tests { } } + #[test] + fn adds_the_visual_cpp_runtime_to_older_installations() { + for style in BOTH { + let temp = tempfile::tempdir().unwrap(); + let staged = update(temp.path()); + write(&staged.join("vc-runtime/msvcp140.dll"), "new runtime"); + write(&staged.join("vc-runtime/vcruntime140.dll"), "new runtime"); + let older = temp.path().join("older"); + write(&older.join(APP_BINARY), "old app"); + write(&older.join(CLI_BINARY), "old cli"); + let current = temp.path().join("current"); + write(¤t.join(APP_BINARY), "old app"); + write(¤t.join(CLI_BINARY), "old cli"); + write(¤t.join("vc-runtime/msvcp140.dll"), "old runtime"); + for folder in [&older, ¤t] { + install(&staged, &targets(folder), style).unwrap(); + assert_eq!( + names(&folder.join("vc-runtime")), + sorted(&["msvcp140.dll", "vcruntime140.dll"]), + "{style:?}" + ); + assert_eq!(read(&folder.join("vc-runtime/msvcp140.dll")), "new runtime"); + } + } + } + #[test] fn a_missing_binary_in_the_update_changes_nothing() { let temp = tempfile::tempdir().unwrap(); diff --git a/LinuxWindows/docs/cuda-validation.md b/LinuxWindows/docs/cuda-validation.md index e0f3a0a2..0ce4ae2b 100644 --- a/LinuxWindows/docs/cuda-validation.md +++ b/LinuxWindows/docs/cuda-validation.md @@ -52,7 +52,9 @@ Environment problems found along the way, outside the CUDA code: upstream `llama-server` needs `libgomp.so.1` (OpenMP) on Linux and the Microsoft Visual C++ 2015–2022 runtime on Windows. A minimal container and a fresh Windows Server image had neither, so every backend, CPU included, failed to start until -they were installed. +they were installed. The Linux packages now depend on libgomp, the Windows +archive and installer carry the Visual C++ runtime for each `llama-server.exe`, +and a start that still fails names what to install. ## RTX 5090: review fixes, older driver and matched timings — 2026-10-22 diff --git a/LinuxWindows/packaging/aur/README.md b/LinuxWindows/packaging/aur/README.md index 4231f6da..e4051cfe 100644 --- a/LinuxWindows/packaging/aur/README.md +++ b/LinuxWindows/packaging/aur/README.md @@ -35,6 +35,7 @@ these files. namcap's remaining warnings on the built package are expected: | --- | --- | | `Unused shared library '/usr/lib64/ld-linux-x86-64.so.2'` | Both binaries import `__tls_get_addr` from the loader; namcap misses it. | | `Dependency included, but may not be needed ('vulkan-icd-loader')`, `('wayland')` | The app loads `libvulkan.so.1` and `libwayland-client.so.0` with `dlopen`, so they are not in its `NEEDED` list. | +| `Dependency included, but may not be needed ('libgomp')` | The llama.cpp runtime the app downloads links `libgomp.so.1`; the app itself doesn't. | ## Updating diff --git a/LinuxWindows/packaging/aur/lokalbot-bin/.SRCINFO b/LinuxWindows/packaging/aur/lokalbot-bin/.SRCINFO index a8b29367..93c34bbb 100644 --- a/LinuxWindows/packaging/aur/lokalbot-bin/.SRCINFO +++ b/LinuxWindows/packaging/aur/lokalbot-bin/.SRCINFO @@ -9,6 +9,7 @@ pkgbase = lokalbot-bin depends = glibc>=2.39 depends = libgcc depends = libstdc++ + depends = libgomp depends = alsa-lib depends = libxcb depends = libxkbcommon diff --git a/LinuxWindows/packaging/aur/lokalbot-bin/PKGBUILD b/LinuxWindows/packaging/aur/lokalbot-bin/PKGBUILD index 8eab6a01..372fa0c2 100644 --- a/LinuxWindows/packaging/aur/lokalbot-bin/PKGBUILD +++ b/LinuxWindows/packaging/aur/lokalbot-bin/PKGBUILD @@ -14,11 +14,13 @@ arch=('x86_64') url='https://www.lokalbot.com' license=('GPL-3.0-only' 'AGPL-3.0-only') # The binaries need glibc 2.39. They link ALSA, xcb and xkbcommon, and load -# Vulkan and the Wayland client at run time. +# Vulkan and the Wayland client at run time. The llama.cpp runtime the app +# downloads links libgomp (OpenMP). depends=( 'glibc>=2.39' 'libgcc' 'libstdc++' + 'libgomp' 'alsa-lib' 'libxcb' 'libxkbcommon' diff --git a/LinuxWindows/packaging/windows/lokalbot.iss b/LinuxWindows/packaging/windows/lokalbot.iss index b7fd840e..52b6e47c 100644 --- a/LinuxWindows/packaging/windows/lokalbot.iss +++ b/LinuxWindows/packaging/windows/lokalbot.iss @@ -61,6 +61,8 @@ Source: "{#SourceDir}\lokalbot-cli.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourceDir}\LICENSE.txt"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourceDir}\THIRD_PARTY_NOTICES.md"; DestDir: "{app}"; Flags: ignoreversion Source: "{#SourceDir}\LICENSES\*"; DestDir: "{app}\LICENSES"; Flags: ignoreversion recursesubdirs +; The Visual C++ runtime LokalBot copies beside llama-server.exe, which needs it. +Source: "{#SourceDir}\vc-runtime\*"; DestDir: "{app}\vc-runtime"; Flags: ignoreversion [Icons] ; LokalBot looks for this exact shortcut to show notifications under its own name. @@ -83,5 +85,6 @@ Root: HKCU; Subkey: "Software\Classes\AppUserModelId\{#AppId}"; Flags: dontcreat [UninstallDelete] ; Old executables an in-place update renamed aside. Type: files; Name: "{app}\*.old" -; License texts an in-place update added. +; License texts and the Visual C++ runtime an in-place update added. Type: filesandordirs; Name: "{app}\LICENSES" +Type: filesandordirs; Name: "{app}\vc-runtime" diff --git a/LinuxWindows/scripts/ci/check-windows-installer.ps1 b/LinuxWindows/scripts/ci/check-windows-installer.ps1 index 8824c491..619b01e1 100644 --- a/LinuxWindows/scripts/ci/check-windows-installer.ps1 +++ b/LinuxWindows/scripts/ci/check-windows-installer.ps1 @@ -12,7 +12,7 @@ $log = Join-Path $tmp 'lokalbot-setup.log' $p = Start-Process (Resolve-Path $Setup).Path -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/LOG=$log" -Wait -PassThru if ($p.ExitCode -ne 0) { Get-Content $log -ErrorAction SilentlyContinue; throw "setup exited with $($p.ExitCode)" } -foreach ($file in 'lokalbot.exe', 'lokalbot-cli.exe', 'LICENSE.txt', 'THIRD_PARTY_NOTICES.md', 'LICENSES\rust-crates.md', 'LICENSES\Apache-2.0.txt') { +foreach ($file in 'lokalbot.exe', 'lokalbot-cli.exe', 'LICENSE.txt', 'THIRD_PARTY_NOTICES.md', 'LICENSES\rust-crates.md', 'LICENSES\Apache-2.0.txt', 'vc-runtime\msvcp140.dll', 'vc-runtime\vcruntime140.dll', 'vc-runtime\vcruntime140_1.dll') { if (-not (Test-Path (Join-Path $app $file))) { throw "the installer did not install $file" } } if (-not (Test-Path $shortcut)) { throw 'no Start menu shortcut' } @@ -31,14 +31,16 @@ if ($LASTEXITCODE -ne 0) { throw "lokalbot-cli --help exited with $LASTEXITCODE" # An in-place update can add license texts the installer didn't install. Set-Content -Path (Join-Path $app 'LICENSES\added-by-update.txt') -Value 'added' +Set-Content -Path (Join-Path $app 'vc-runtime\added-by-update.dll') -Value 'added' $uninstaller = $entry.UninstallString.Trim('"') Start-Process $uninstaller -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART' -Wait | Out-Null # The uninstaller finishes from a copy of itself in TEMP; wait for it. $deadline = (Get-Date).AddSeconds(60) -$left = { (Test-Path (Join-Path $app 'lokalbot.exe')) -or (Test-Path (Join-Path $app 'LICENSES')) } +$left = { (Test-Path (Join-Path $app 'lokalbot.exe')) -or (Test-Path (Join-Path $app 'LICENSES')) -or (Test-Path (Join-Path $app 'vc-runtime')) } while ((& $left) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 1 } if (Test-Path (Join-Path $app 'lokalbot.exe')) { throw 'uninstalling left lokalbot.exe behind' } if (Test-Path $shortcut) { throw 'uninstalling left the Start menu shortcut behind' } if (Test-Path (Join-Path $app 'LICENSES')) { throw 'uninstalling left the LICENSES folder behind' } +if (Test-Path (Join-Path $app 'vc-runtime')) { throw 'uninstalling left the vc-runtime folder behind' } Write-Output 'Install and uninstall checks passed' diff --git a/LinuxWindows/scripts/package-linux-distros.sh b/LinuxWindows/scripts/package-linux-distros.sh index a890a3f8..0b38d7dd 100755 --- a/LinuxWindows/scripts/package-linux-distros.sh +++ b/LinuxWindows/scripts/package-linux-distros.sh @@ -123,6 +123,8 @@ EOF fi # The binaries need glibc 2.39 (built on Ubuntu 24.04). The app links ALSA, # xcb and xkbcommon and loads Vulkan and the Wayland client at run time. + # The llama.cpp runtime it downloads (llama-server) links the GCC OpenMP + # runtime, libgomp.so.1, which minimal installs lack. # Arch's gcc-libs is a meta package of every GCC runtime; namcap asks for # libgcc and libstdc++, and for hicolor-icon-theme, which owns the icon folders. # System audio uses PulseAudio or PipeWire's PulseAudio server; the @@ -134,6 +136,7 @@ overrides: - libc6 (>= 2.39) - libstdc++6 - libgcc-s1 + - libgomp1 - libasound2t64 | libasound2 - libxcb1 - libxkbcommon0 @@ -156,6 +159,7 @@ overrides: depends: - libc.so.6(GLIBC_2.39)(64bit) - libstdc++.so.6()(64bit) + - libgomp.so.1()(64bit) - libasound.so.2()(64bit) - libxcb.so.1()(64bit) - libxkbcommon.so.0()(64bit) @@ -172,6 +176,7 @@ overrides: - glibc>=2.39 - libgcc - libstdc++ + - libgomp - alsa-lib - libxcb - libxkbcommon diff --git a/LinuxWindows/scripts/package.sh b/LinuxWindows/scripts/package.sh index f3a3e239..4b1b5d0e 100755 --- a/LinuxWindows/scripts/package.sh +++ b/LinuxWindows/scripts/package.sh @@ -2,11 +2,27 @@ # Builds release binaries and packs them for the current platform into dist/. # Linux: LokalBot--linux-x86_64.tar.gz (with install.sh) # Windows (Git Bash or CI): LokalBot--windows-x86_64.zip +# +# VC_REDIST_DIR (Windows): a Microsoft.VC14x.CRT folder to take the Visual C++ +# runtime from, instead of the newest Visual Studio with the C++ build tools. set -euo pipefail cd "$(dirname "$0")/.." VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) # Self-hosted CI runners keep a warm target directory elsewhere. TARGET=${CARGO_TARGET_DIR:-target} + +# The x64 Microsoft.VC14x.CRT folder of the newest Visual Studio (or Build +# Tools) with the C++ build tools, at its default redistributable version. +vc_redist_dir() { + local vswhere vs version + vswhere=$(cygpath -u 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe') + vs=$("$vswhere" -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath | tr -d '\r') + [ -n "$vs" ] || { echo "vswhere found no Visual Studio with the C++ build tools; set VC_REDIST_DIR." >&2; return 1; } + vs=$(cygpath -u "$vs") + version=$(tr -d '[:space:]' < "$vs/VC/Auxiliary/Build/Microsoft.VCRedistVersion.default.txt") + ls -d "$vs/VC/Redist/MSVC/$version/x64/Microsoft.VC"*.CRT | sort -V | tail -1 +} + cargo build --release --locked -p lokalbot-app -p lokalbot-cli mkdir -p dist case "$(uname -s)" in @@ -32,6 +48,16 @@ case "$(uname -s)" in STAGE="dist/$NAME" rm -rf "$STAGE" && mkdir -p "$STAGE" cp "$TARGET/release/lokalbot.exe" "$TARGET/release/lokalbot-cli.exe" "$STAGE/" + # llama.cpp's Windows builds import the Visual C++ runtime, which Windows + # lacks until something installs the Visual C++ Redistributable. Ship the + # build machine's copy, unmodified (Distributable Code under the Visual + # Studio license terms); LokalBot copies it beside each llama-server.exe + # (lokalbot-ai's runtime.rs). + CRT=${VC_REDIST_DIR:-$(vc_redist_dir)} + mkdir -p "$STAGE/vc-runtime" + for dll in msvcp140.dll vcruntime140.dll vcruntime140_1.dll; do + cp "$CRT/$dll" "$STAGE/vc-runtime/" + done cp ../LICENSE "$STAGE/LICENSE.txt" 2>/dev/null || true cp ../THIRD_PARTY_NOTICES.md "$STAGE/" cp -R ../LICENSES "$STAGE/LICENSES" diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index c5045bf6..14c8ed64 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -174,7 +174,22 @@ On Linux, `freetype-sys` compiles its bundled FreeType (FreeType License or GPL-2.0-or-later) only when the build machine has no FreeType of its own; the release builds contain no FreeType code. Libraries the programs load from the system at run time (the C and C++ runtimes, ALSA, X11 and Wayland libraries, -the Vulkan loader) are not distributed with LokalBot. +the Vulkan loader) are not distributed with LokalBot, apart from the Visual C++ +runtime below. + +### Microsoft Visual C++ runtime (Windows) + +The Windows archive and installer include `msvcp140.dll`, `vcruntime140.dll` +and `vcruntime140_1.dll` from the Microsoft Visual C++ Redistributable, +unmodified, in the `vc-runtime` folder. LokalBot's own programs link the C +runtime statically and don't use them: it copies them beside each +`llama-server.exe` it downloads, so llama.cpp also runs where the Visual C++ +Redistributable isn't installed. They are Copyright (c) Microsoft Corporation +and are distributed as Distributable Code under the Microsoft Visual Studio +license terms (https://learn.microsoft.com/visualstudio/releases/2022/redistribution), +not under LokalBot's license. Anyone who distributes them further must keep +them unmodified and bind the people they distribute them to under terms that +protect them at least as much as Microsoft's own terms. ### Assets compiled into the app