Merge pull request #3195 from horizon-rust/feat/launcher-native-mods-window

🤖 Agent: proven with a real launcher GUI run in isolated dirs (Settings → Native mods row, red warning naming veinminer 0.3.0, trust → cached build reused, status line); launcher clippy and 265 tests green; #3194 merged and this now targets main with only its own 5 files. Verify green at 505de825.
This commit is contained in:
Ludovic Marie
2026-10-28 14:51:41 +01:00
committed by GitHub
5 changed files with 214 additions and 12 deletions
+14 -10
View File
@@ -7,7 +7,7 @@ RETURN, MODIFY_ARG, OVERWRITE...; the tool's README lists them). A port such as
one module. Start a mod from [horizon-native-mod-template](https://github.com/horizon-rust/horizon-native-mod-template).
Native mods are native code with the player's rights, not sandboxed. The launcher offers them off by default, behind
a warning, reviewed before the registry lists one, and in a game and an instance of their own.
a warning, reviewed before the registry lists one, and in a game of their own, built for the instance they are installed in.
## Pinned to a Nightly
@@ -21,9 +21,12 @@ pin builds on the commit of the installed version the build starts from.
## What the launcher does
`horizon-launcher native-build FOLDER --trust-native-code` (the window's switch and Mods page come next). FOLDER
is a bundle, an unpacked `.hnmod`, or a folder of them. It is not an MCP tool: trusting native code is the
player's decision, never an agent's.
In the window: install a native mod from the Mods page, turn on Settings → Game → **Native mods (experimental)**,
then **Build**. The launcher names the mods, warns in red, and builds only from "I trust these mods: build"; the
row shows each step, the error if one fails, and the build the instance plays. From the command line:
`horizon-launcher native-build [FOLDER] [--instance NAME] --trust-native-code`. FOLDER is a bundle, an unpacked
`.hnmod`, or a folder of them; without it, the native mods turned on in the instance. It is not an MCP tool:
trusting native code is the player's decision, never an agent's.
1. **Rust.** The launcher's own toolchain ([`rust_toolchain`](../launcher/src/rust_toolchain.rs)): Rust 1.99.1's
official `rustc`, `cargo` and `rust-std` (and `rust-mingw` on Windows), each pinned by SHA-256, downloaded once
@@ -45,7 +48,8 @@ player's decision, never an agent's.
horizon-mixins diagnostic in one line).
6. **Install**: a new version, `native-<commit>-<key>`, a copy of the starting version's folder (resources
included, cloned on APFS, Btrfs and ReFS) with the built game in place of its own, and a `native-mods.json`
saying which commit, mods, horizon-mixins and Rust made it. The **Native mods** instance plays it.
saying which commit, mods, horizon-mixins and Rust made it. The instance the mods are installed in plays it (a
folder built from the command line, or mods of the default home, go to the **Native mods** instance).
## Cache and disk
@@ -66,16 +70,17 @@ Measured 2026-10-28 on the Mac mini (M4 Pro, 14 cores) with Veinminer 0.3.0 on N
| Rebuild after a helper's code changed | 2 min 46 s of compiling (only `horizon-client`), 2 min 53 s in all |
| A change horizon-mixins ignores (a comment) | nothing compiled; 31 s, mostly the version folder's copy |
Only the newest native build is kept (`native_mods::prune`); `native/target/` stays for the next one.
Only the native builds an instance plays are kept (`native_mods::prune`); `native/target/` stays for the next one.
## Trust
- **Off by default.** The command needs `--trust-native-code`; the window will show a warning in red before every
build: the mods run with full access to the computer, their ids and versions, and who made them.
- **Off by default.** The command needs `--trust-native-code`; the window shows a warning in red before every
build: the mods run with full access to the computer, and their ids and versions. The Mods page says who made
each one, and "Not made or endorsed by the Horizon project" for any mod not Horizon's own.
- **The registry** (horizon-rust/horizon-mods) lists them as their own kind, `native-mod`, only after a maintainer
has read the source: the `.hnmod` *is* the source (only `.rs` and `.toml`, checked without running anything),
pinned by SHA-256 like every registry file. An update is reviewed again; `revoked.toml` takes one down.
- **Isolation of data.** The Native mods instance has its own worlds, options and logs.
- **Isolation of data.** Native mods run only in the instance built for them, with its own worlds, options and logs.
- What this does not do: sandbox the compiled game. horizon-mixins' checks stop mistakes, not a malicious helper
([security notes](https://github.com/horizon-rust/horizon-mixins/blob/main/docs/security.md)).
@@ -88,7 +93,6 @@ Only the newest native build is kept (`native_mods::prune`); `native/target/` st
## Left to do
- The window: a Native mods switch, `native-mod` entries on the Mods page, the warning and the progress screen.
- Rebuild after the mods or the Nightly change (asking first, as it compiles for minutes).
- A prebuilt horizon-mixins from its CI instead of building it on the player's computer.
- Windows and Linux: the toolchains are pinned, but a full game build on them is unproven.
+10 -1
View File
@@ -176,5 +176,14 @@
"Download and prepare": "Télécharger et préparer",
"Not prepared. Horizon can download Minecraft {version} from Mojang for your account, or use your own install.": "Pas préparé. Horizon peut télécharger Minecraft {version} depuis Mojang pour votre compte, ou utiliser votre propre installation.",
"Not prepared. Sign in with the Microsoft account that owns Minecraft {version} first.": "Pas préparé. Connectez-vous d'abord avec le compte Microsoft qui possède Minecraft {version}.",
"Cancel": "Annuler"
"Cancel": "Annuler",
"Native mods (experimental)": "Mods natifs (expérimental)",
"Native mods from the Mods page compile into the game with the launcher's own Rust. Not sandboxed: they can do anything you can on this computer.": "Les mods natifs de la page Mods sont compilés dans le jeu avec le Rust du launcher. Sans bac à sable : ils peuvent faire tout ce que vous pouvez faire sur cet ordinateur.",
"{version} plays in this instance.": "Cette instance joue {version}.",
"Install Horizon first.": "Installez d'abord Horizon.",
"Starting the build": "Début de la compilation",
"These mods will run with full access to your computer": "Ces mods auront un accès complet à votre ordinateur",
"They can read, change or delete your files, and use your accounts and network, like any program you run. Build them only if you trust their authors: the Mods page names them.": "Ils peuvent lire, modifier ou supprimer vos fichiers, et utiliser vos comptes et votre réseau, comme tout programme que vous lancez. Ne les compilez que si vous faites confiance à leurs auteurs : la page Mods les nomme.",
"Mods: {mods}": "Mods : {mods}",
"The build compiles the game: about ten minutes and a few GB of disk the first time, a few minutes after that.": "La compilation construit le jeu : une dizaine de minutes et quelques Go de disque la première fois, quelques minutes ensuite."
}
+10 -1
View File
@@ -176,5 +176,14 @@
"Download and prepare": "Скачать и подготовить",
"Not prepared. Horizon can download Minecraft {version} from Mojang for your account, or use your own install.": "Не подготовлено. Horizon может скачать Minecraft {version} у Mojang для вашего аккаунта или взять вашу установку.",
"Not prepared. Sign in with the Microsoft account that owns Minecraft {version} first.": "Не подготовлено. Сначала войдите в аккаунт Microsoft, у которого есть Minecraft {version}.",
"Cancel": "Отмена"
"Cancel": "Отмена",
"Native mods (experimental)": "Нативные моды (экспериментально)",
"Native mods from the Mods page compile into the game with the launcher's own Rust. Not sandboxed: they can do anything you can on this computer.": "Нативные моды со страницы «Моды» компилируются в игру собственным Rust лаунчера. Без песочницы: они могут делать на этом компьютере всё, что можете вы.",
"{version} plays in this instance.": "В этой сборке запускается {version}.",
"Install Horizon first.": "Сначала установите Horizon.",
"Starting the build": "Начало сборки",
"These mods will run with full access to your computer": "Эти моды получат полный доступ к вашему компьютеру",
"They can read, change or delete your files, and use your accounts and network, like any program you run. Build them only if you trust their authors: the Mods page names them.": "Они могут читать, изменять и удалять ваши файлы, использовать ваши аккаунты и сеть, как любая запущенная вами программа. Собирайте их, только если доверяете авторам: они указаны на странице «Моды».",
"Mods: {mods}": "Моды: {mods}",
"The build compiles the game: about ten minutes and a few GB of disk the first time, a few minutes after that.": "Сборка компилирует игру: около десяти минут и несколько ГБ на диске в первый раз, потом несколько минут."
}
+8
View File
@@ -2495,6 +2495,10 @@ pub enum Msg {
NightlyProgress(f32),
/// A nightly check ended: the version installed (None: already up to date), or why not.
Nightly(Result<Option<String>, String>),
/// Where the native-mods build is (`native_mods::Step::label`).
NativeProgress(String),
/// The native-mods build ended: the version built, or why not.
Native(Result<String, String>),
}
/// A running process; its output arrives as `Msg::Line`, its end as `Msg::Exit`.
@@ -2681,6 +2685,10 @@ pub struct Settings {
/// instance. Off by default.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub nightly: bool,
/// The player turned Native mods (experimental) on (`native_mods`): mixin mods compiled into
/// a game of their own. Off by default.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub native_mods: bool,
}
impl Settings {
+172
View File
@@ -53,6 +53,7 @@ use horizon_launcher::account::{self, Accounts, SignIn, SignInState};
use horizon_launcher::backend::{self, Job, Msg, Release, Running, Settings, Updates};
use horizon_launcher::i18n::{self, tr, trf};
use horizon_launcher::instances;
use horizon_launcher::native_mods;
use horizon_launcher::nightly;
use horizon_launcher::telemetry;
use scrollbar::Scrollbar;
@@ -176,6 +177,11 @@ struct Launcher {
nightly_error: Option<String>,
/// Play the Nightly instance once its first install ends: the player just turned Nightly on.
nightly_select: bool,
/// Native mods (`native_mods`): the build's step while it runs, why it failed, and the
/// warning before a build while it is open, with the mods it names.
native_step: Option<String>,
native_error: Option<String>,
native_confirm: Option<Result<Vec<native_mods::Bundle>, String>>,
confirm_remove: Option<String>,
picker_open: bool,
/// The top bar's quick switch of who plays (`switch_page.rs`).
@@ -389,6 +395,9 @@ impl Launcher {
nightly_progress: None,
nightly_error: None,
nightly_select: false,
native_step: None,
native_error: None,
native_confirm: None,
confirm_remove: None,
picker_open: false,
account_menu: false,
@@ -578,6 +587,56 @@ impl Launcher {
/// Turns Nightly on (install it, then play its instance) or off (play the release again; the
/// Nightly instance and its worlds stay).
/// The native mods turned on in the instance Play starts, unpacked and checked, with their
/// bundles: what the warning names and the build compiles.
fn native_mods_to_build(
&self,
) -> Result<(std::path::PathBuf, Vec<native_mods::Bundle>), String> {
let folder = native_mods::installed_mods(&instances::selected().home)?;
let found = native_mods::bundles(&folder)?;
Ok((folder, found))
}
/// Builds the selected instance's native mods, once the player accepted the warning. The
/// build reuses the game files of the version the instance plays, else the newest installed.
fn build_native(&mut self) {
if self.native_step.is_some() {
return;
}
self.native_confirm = None;
self.native_error = None;
let instance = instances::selected();
let base = instance
.version
.clone()
.filter(|v| !native_mods::is_native(v))
.or_else(|| {
self.installed
.iter()
.find(|t| backend::is_game_tag(t) || t.starts_with("nightly-"))
.cloned()
});
let Some(base) = base else {
self.native_error = Some(tr("Install Horizon first.").into());
return;
};
let folder = match self.native_mods_to_build() {
Ok((folder, _)) => folder,
Err(e) => {
self.native_error = Some(e);
return;
}
};
self.native_step = Some(tr("Starting the build").into());
let tx = self.tx.clone();
std::thread::spawn(move || {
let result = native_mods::build(&base, &folder, Some(&instance), |step| {
let _ = tx.send(Msg::NativeProgress(step.label()));
});
let _ = tx.send(Msg::Native(result));
});
}
fn set_nightly(&mut self, on: bool) {
self.settings.nightly = on;
if on {
@@ -776,6 +835,15 @@ impl Launcher {
}
Msg::Updates(Err(e)) => self.update_error = Some(e),
Msg::NightlyProgress(p) => self.nightly_progress = Some(p),
Msg::NativeProgress(step) => self.native_step = Some(step),
Msg::Native(result) => {
self.native_step = None;
self.installed = backend::installed();
self.reload_instances();
if let Err(e) = result {
self.native_error = Some(e);
}
}
Msg::Nightly(result) => {
self.nightly_progress = None;
self.installed = backend::installed();
@@ -2953,6 +3021,7 @@ impl Launcher {
.child(self.proxy_row(n + 4, cx))
.child(group("Game", "gamepad"))
.child(self.game_args_row(n + 5, cx))
.child(self.native_mods_row(n + 5, cx))
.child(group("AI", "terminal"))
.child(self.no_ai_row(n + 6, cx))
.child(group("About", "info-box"))
@@ -3061,6 +3130,109 @@ impl Launcher {
/// Settings' Game arguments row: the extra arguments the game starts with, kept in
/// `settings.json` and appended to the launcher's own (quotes group a word with spaces).
/// Settings' Native mods row (docs/native-mods.md): off by default. On, Build compiles the
/// native mods installed in the instance Play starts, after a warning that names them, and
/// that instance then plays the build.
fn native_mods_row(&self, n: usize, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let on = self.settings.native_mods;
let toggle =
switch("native-mods", on, &t).on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.settings.native_mods = !this.settings.native_mods;
this.native_confirm = None;
this.settings.save();
cx.notify();
}));
let mut detail = div().flex().flex_col().gap(px(4.)).child(
tr("Native mods from the Mods page compile into the game with the launcher's own Rust. Not sandboxed: they can do anything you can on this computer.").to_string(),
);
if on {
let status = match (&self.native_step, &self.native_error) {
(Some(step), _) => Some(div().child(step.clone())),
(None, Some(e)) => Some(div().text_color(t.danger).child(e.clone())),
(None, None) => instances::selected()
.version
.filter(|v| native_mods::is_native(v))
.map(|v| {
div().child(trf("{version} plays in this instance.", &[("version", &v)]))
}),
};
detail = detail.children(status);
if self.native_step.is_none() && self.native_confirm.is_none() {
detail = detail.child(div().flex().gap(px(8.)).mt(px(4.)).child(
button("native-build", "Build", Kind::Primary, &t).on_click(cx.listener(
|this, _: &ClickEvent, _, cx| {
this.native_confirm = Some(this.native_mods_to_build().map(|(_, b)| b));
cx.notify();
},
)),
));
}
if let Some(mods) = &self.native_confirm {
detail = detail.child(self.native_warning(mods, cx));
}
}
index_row(
n,
tr("Native mods (experimental)"),
Some(detail.into_any_element()),
Some(toggle.into_any_element()),
&t,
)
}
/// The warning before a native build: what the mods can do and which mods. The build starts
/// only from its button.
fn native_warning(
&self,
mods: &Result<Vec<native_mods::Bundle>, String>,
cx: &mut Context<Self>,
) -> Div {
let t = self.theme;
let list = match mods {
Ok(found) => found
.iter()
.map(|b| format!("{} {}", b.id, b.version))
.collect::<Vec<_>>()
.join(", "),
Err(e) => e.clone(),
};
let panel = div()
.flex()
.flex_col()
.gap(px(6.))
.mt(px(8.))
.p(px(12.))
.bg(t.well)
.child(div().text_color(t.danger).child(tr("These mods will run with full access to your computer").to_string()))
.child(tr("They can read, change or delete your files, and use your accounts and network, like any program you run. Build them only if you trust their authors: the Mods page names them.").to_string())
.child(trf("Mods: {mods}", &[("mods", &list)]))
.child(tr("The build compiles the game: about ten minutes and a few GB of disk the first time, a few minutes after that.").to_string());
let mut buttons = div().flex().gap(px(8.)).mt(px(4.));
if mods.is_ok() {
buttons = buttons.child(
button(
"native-trust",
"I trust these mods: build",
Kind::Primary,
&t,
)
.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.build_native();
cx.notify();
})),
);
}
panel.child(buttons.child(
button("native-cancel", "Cancel", Kind::Secondary, &t).on_click(cx.listener(
|this, _: &ClickEvent, _, cx| {
this.native_confirm = None;
cx.notify();
},
)),
))
}
fn game_args_row(&self, n: usize, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let focused = self.args_focused;