Bundle Stockfish 19 with every package and set it up on first start
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run

- packaging/stockfish.sh fetches the pinned official universal build (SHA-256
  checked) for Linux and Windows and the source archive for the release.
- deb/rpm/Arch, AppImage, Flatpak, tarball and Windows zip ship it unmodified
  (AppImage: added after linuxdeploy, packed with appimagetool).
- The app resolves the built-in engine at run time (EngineConfig::builtin),
  adds it on first start (or a system stockfish), and offers engines found on
  the computer in Settings > Engines.
- install.sh installs Stockfish into ~/.local/lib/chesspenguin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubel 2026-10-18 11:53:30 +03:00
parent 6db8d67821
commit 56cfb4d09f
22 changed files with 383 additions and 35 deletions

View file

@ -86,6 +86,11 @@ impl Analysis {
/// Starts the engine in a background thread (handshake blocks for up to ~20 s).
pub fn start(&mut self, cfg: &EngineConfig, ctx: &egui::Context) {
self.stop();
let Some(path) = cfg.executable() else {
self.status =
Status::Failed(tr("The built-in engine is not part of this build").into());
return;
};
let (tx, rx) = channel();
let ctx_w = ctx.clone();
let ctx_done = ctx.clone();
@ -93,12 +98,12 @@ impl Analysis {
self.engine_name = cfg.name.clone();
self.multipv = cfg.multipv.max(1);
self.limit = cfg.search_secs;
self.engine_path = Some(cfg.path.clone());
self.engine_path = Some(path.clone());
let spawned = std::thread::Builder::new()
.name("engine-spawn".into())
.spawn(move || {
let res = uci::Engine::spawn_with(
uci::EngineConfig::new(&cfg.path),
uci::EngineConfig::new(&path),
Box::new(move || ctx_w.request_repaint()),
)
.inspect(|h| {
@ -139,7 +144,7 @@ impl Analysis {
/// Applies Threads/Hash/MultiPV/time of the running engine and restarts the current search.
pub fn reconfigure(&mut self, cfg: &EngineConfig, ctx: &egui::Context) {
if self.engine_path.as_deref() != Some(cfg.path.as_path()) || self.spawning.is_some() {
if self.engine_path != cfg.executable() || self.spawning.is_some() {
self.start(cfg, ctx);
return;
}

View file

@ -91,6 +91,9 @@ impl App {
pub fn new(ctx: &egui::Context) -> Self {
let mut settings = Settings::load();
crate::i18n::set_lang(settings.language);
if crate::engines::first_run_setup(&mut settings) {
let _ = settings.save();
}
// PGN files passed on the command line (e.g. "Open with…") join the library, first one selected.
let args: Vec<PathBuf> = std::env::args_os()
.skip(1)

View file

@ -0,0 +1,94 @@
//! Finding engines without a file dialog: the Stockfish shipped with the packages and a
//! `stockfish` installed by the system package manager.
use std::path::{Path, PathBuf};
use crate::i18n::tr;
use crate::settings::{EngineConfig, Settings};
#[cfg(windows)]
const STOCKFISH: &str = "stockfish.exe";
#[cfg(not(windows))]
const STOCKFISH: &str = "stockfish";
/// The Stockfish shipped next to the application:
/// `<prefix>/lib/chesspenguin/stockfish` for `<prefix>/bin/chesspenguin` (deb, rpm, Arch,
/// AppImage, Flatpak) or `stockfish/stockfish[.exe]` beside the executable (Windows zip,
/// Linux tarball). Resolved at every start: the AppImage mount point changes between runs.
pub fn bundled_stockfish() -> Option<PathBuf> {
let exe = std::env::current_exe().ok()?.canonicalize().ok()?;
let dir = exe.parent()?;
let candidates = [
dir.parent()
.map(|prefix| prefix.join("lib").join("chesspenguin").join(STOCKFISH)),
Some(dir.join("stockfish").join(STOCKFISH)),
];
candidates.into_iter().flatten().find(|p| is_executable(p))
}
/// `stockfish` from `PATH` (for example, the distribution package).
pub fn system_stockfish() -> Option<PathBuf> {
let path = std::env::var_os("PATH")?;
std::env::split_paths(&path)
.map(|dir| dir.join(STOCKFISH))
.find(|p| is_executable(p))
}
fn is_executable(p: &Path) -> bool {
let Ok(meta) = std::fs::metadata(p) else {
return false;
};
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
meta.is_file() && meta.permissions().mode() & 0o111 != 0
}
#[cfg(not(unix))]
{
meta.is_file()
}
}
pub fn builtin_config() -> EngineConfig {
let mut cfg = EngineConfig::new(tr("Stockfish (built-in)").into(), PathBuf::new());
cfg.builtin = true;
cfg
}
/// First start: if no engine is configured, adds the bundled Stockfish (or else the system
/// one) and makes it active, so analysis works right after installation. Runs once.
pub fn first_run_setup(settings: &mut Settings) -> bool {
if settings.engines_discovered {
return false;
}
settings.engines_discovered = true;
if settings.engines.is_empty() {
let found = if bundled_stockfish().is_some() {
Some(builtin_config())
} else {
system_stockfish().map(|p| EngineConfig::new("Stockfish".into(), p))
};
if let Some(cfg) = found {
settings.engines.push(cfg);
settings.active_engine = Some(0);
}
}
true
}
/// Engines found on this system that are not in the list yet (offered in the settings).
pub fn suggestions(settings: &Settings) -> Vec<EngineConfig> {
let mut out = Vec::new();
if bundled_stockfish().is_some() && !settings.engines.iter().any(|e| e.builtin) {
out.push(builtin_config());
}
if let Some(p) = system_stockfish() {
let known = |e: &EngineConfig| {
!e.builtin && (e.path == p || e.path.canonicalize().ok() == p.canonicalize().ok())
};
if !settings.engines.iter().any(known) {
out.push(EngineConfig::new(tr("Stockfish (system)").into(), p));
}
}
out
}

View file

@ -1355,6 +1355,63 @@ const ROWS: &[[&str; 6]] = &[
"Profundo",
"Approfondito",
],
// Engines
[
"The built-in engine is not part of this build",
"Встроенного движка нет в этой сборке",
"Le moteur intégré ne fait pas partie de cette version",
"Die eingebaute Engine ist in diesem Build nicht enthalten",
"El motor integrado no forma parte de esta compilación",
"Il motore integrato non fa parte di questa build",
],
[
"Shipped with ChessPenguin: {path}",
"Поставляется с ChessPenguin: {path}",
"Fourni avec ChessPenguin : {path}",
"Mit ChessPenguin geliefert: {path}",
"Incluido con ChessPenguin: {path}",
"Fornito con ChessPenguin: {path}",
],
[
"Shipped with ChessPenguin: not part of this build",
"Поставляется с ChessPenguin: в этой сборке отсутствует",
"Fourni avec ChessPenguin : absent de cette version",
"Mit ChessPenguin geliefert: in diesem Build nicht enthalten",
"Incluido con ChessPenguin: no está en esta compilación",
"Fornito con ChessPenguin: assente in questa build",
],
[
"Found on this computer:",
"Найдено на этом компьютере:",
"Trouvé sur cet ordinateur :",
"Auf diesem Computer gefunden:",
"Encontrado en este equipo:",
"Trovato su questo computer:",
],
[
"Add",
"Добавить",
"Ajouter",
"Hinzufügen",
"Añadir",
"Aggiungi",
],
[
"Stockfish (built-in)",
"Stockfish (встроенный)",
"Stockfish (intégré)",
"Stockfish (eingebaut)",
"Stockfish (integrado)",
"Stockfish (integrato)",
],
[
"Stockfish (system)",
"Stockfish (системный)",
"Stockfish (système)",
"Stockfish (System)",
"Stockfish (del sistema)",
"Stockfish (di sistema)",
],
];
#[cfg(test)]
@ -1372,6 +1429,7 @@ mod tests {
include_str!("library.rs"),
include_str!("notation.rs"),
include_str!("review.rs"),
include_str!("engines.rs"),
include_str!("settings.rs"),
include_str!("settings_ui.rs"),
include_str!("widgets.rs"),

View file

@ -5,6 +5,7 @@ mod analysis;
mod app;
mod assets;
mod board;
mod engines;
mod game_view;
mod i18n;
mod library;

View file

@ -262,6 +262,10 @@ impl Review {
) -> bool {
self.job = None;
self.error = None;
let Some(path) = engine.executable() else {
self.error = Some(tr("The built-in engine is not part of this build").into());
return false;
};
if full {
self.evals.clear();
self.dirty = true;
@ -288,12 +292,7 @@ impl Review {
let (tx, rx) = channel();
let cancel = Arc::new(AtomicBool::new(false));
let total = targets.len();
let (path, threads, hash, nodes) = (
engine.path.clone(),
rs.threads.max(1),
rs.hash_mb,
rs.nodes(),
);
let (path, threads, hash, nodes) = (path, rs.threads.max(1), rs.hash_mb, rs.nodes());
let (cancel_w, ctx_w) = (cancel.clone(), ctx.clone());
let spawned = std::thread::Builder::new()
.name("game-review".into())

View file

@ -20,6 +20,9 @@ pub struct EngineConfig {
/// Search time per position in seconds; `None` = infinite.
#[serde(default)]
pub search_secs: Option<u32>,
/// The Stockfish shipped with ChessPenguin; `path` is unused and resolved at start.
#[serde(default)]
pub builtin: bool,
}
fn default_threads() -> u32 {
@ -43,6 +46,16 @@ impl EngineConfig {
hash_mb: default_hash(),
multipv: default_multipv(),
search_secs: None,
builtin: false,
}
}
/// Executable to start; `None` if the built-in engine is missing (e.g. a source build).
pub fn executable(&self) -> Option<PathBuf> {
if self.builtin {
crate::engines::bundled_stockfish()
} else {
Some(self.path.clone())
}
}
}
@ -65,6 +78,8 @@ pub struct Settings {
pub databases: Vec<PathBuf>,
/// Whole-game analysis options.
pub review: ReviewSettings,
/// The first-start engine discovery has run (see `engines::first_run_setup`).
pub engines_discovered: bool,
}
/// Options of the whole-game analysis (the engine is the active one).
@ -116,6 +131,7 @@ impl Default for Settings {
show_best_arrow: true,
databases: Vec::new(),
review: ReviewSettings::default(),
engines_discovered: false,
}
}
}

View file

@ -1,6 +1,6 @@
//! Settings window: engines, board & pieces, sound, interface.
use crate::i18n::{Lang, tr};
use crate::i18n::{Lang, tr, trf};
use egui::{RichText, Sense, Ui, vec2};
use shakmaty::{Color, Piece, Role};
@ -136,11 +136,19 @@ impl SettingsWindow {
}
});
});
ui.label(
RichText::new(s.engines[i].path.display().to_string())
.small()
.weak(),
);
let e = &s.engines[i];
let location = if e.builtin {
match crate::engines::bundled_stockfish() {
Some(p) => trf(
"Shipped with ChessPenguin: {path}",
&[("path", &p.display())],
),
None => tr("Shipped with ChessPenguin: not part of this build").into(),
}
} else {
e.path.display().to_string()
};
ui.label(RichText::new(location).small().weak());
});
}
if let Some(i) = remove {
@ -153,6 +161,26 @@ impl SettingsWindow {
*changed = true;
actions.push(SettingsAction::EngineChanged);
}
let found = crate::engines::suggestions(s);
if !found.is_empty() {
ui.add_space(6.0);
ui.label(RichText::new(tr("Found on this computer:")).strong());
for cfg in found {
ui.horizontal(|ui| {
let path = cfg.executable().unwrap_or_default();
ui.label(&cfg.name)
.on_hover_text(path.display().to_string());
if ui.button(tr("Add")).clicked() {
s.engines.push(cfg);
if s.active_engine.is_none() {
s.active_engine = Some(s.engines.len() - 1);
actions.push(SettingsAction::EngineChanged);
}
*changed = true;
}
});
}
}
ui.add_space(6.0);
ui.horizontal(|ui| {
if ui