mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-11-16 15:14:56 +00:00
* Install and update Craft apps from a local mirror Add an opt-in developer mode for installing the Craft apps from builds on this machine instead of GitHub: - ARTCRAFT_LAUNCHER_DOWNLOAD_BASE (loopback http only) points the launcher at a local mirror. While set, every check reads the mirror's release_info.json, trusts download links under the mirror, never treats entries as stale, and never falls back to GitHub or ArtCraft's API. - cargo xtask local sync pulls every sibling app checkout (git pull --ff-only --recurse-submodules), packages each app whose version isn't mirrored yet with its own packaging script, and files the results under <mirror>/<app>/<version>/ with SHA256SUMS.txt and notes from git log. - cargo xtask local serve serves the mirror on 127.0.0.1 (with range requests, so paused downloads resume) and writes the feed fresh from the mirror's contents on every request. - cargo xtask local status compares each checkout with what's mirrored. * Sync the local mirror on an interval while serving it cargo xtask local serve --sync-every <30m|1h|1d…> runs the same sync as cargo xtask local sync on a background thread, one after another, so the mirror follows origin without a second process. Downloads keep being served during a build, and a version only joins the feed once its build is complete. Pulls are --no-stat to keep the server's log readable. * Build every new commit as a dev version with --every-commit cargo xtask local sync --every-commit (and serve --sync-every … --every-commit) builds each new commit rather than only new versions. A commit of a 0.4.0 checkout is packaged as 0.4.1-dev.<commit time> through the app's <APP>_VERSION override, so it orders after 0.4.0, after earlier commits, and before the real 0.4.1. The full version lands in the bundle's <App>Version key, which the launcher reads, so it offers each build as an update and sees it as current once installed. * Keep the local mirror out of release builds; parse loopback URLs strictly ARTCRAFT_LAUNCHER_DOWNLOAD_BASE makes the launcher trust the mirror's own checksums and skip GitHub, so a shipped launcher must not read it: it now needs the local-mirror cargo feature (cargo run --features local-mirror), which release builds never enable. The loopback check parsed the URL by prefix, so http://127.0.0.1:1@evil.example/ passed; it now requires the host to be exactly 127.0.0.1, localhost or [::1] with a numeric port. The same check guards ARTCRAFT_LAUNCHER_FEED_URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: khutchings <7854672+khutchings@users.noreply.github.com> Co-authored-by: Brandon Thomas <echelon@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
4.5 KiB
Rust
125 lines
4.5 KiB
Rust
//! Workspace tooling: `cargo xtask <command>`.
|
|
//!
|
|
//! Pure Rust (std only). External tools (`cargo`) are invoked through `std::process::Command`.
|
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
|
|
mod icns;
|
|
mod ico;
|
|
mod local;
|
|
mod version;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::{Command, ExitCode};
|
|
|
|
const USAGE: &str = "\
|
|
usage: cargo xtask <command>
|
|
|
|
commands:
|
|
ci fmt --check, clippy -D warnings, test, wasm (stops at first failure)
|
|
wasm cargo check --target wasm32-unknown-unknown for the wasm-safe crates
|
|
version [set X.Y.Z[-pre]]
|
|
print the workspace version, or set it (Cargo.toml + Cargo.lock)
|
|
ico <out.ico> <in.png>...
|
|
pack square PNGs (<= 256 px) into a Windows .ico (see packaging/icons.sh)
|
|
icns <out.icns> <in.png>...
|
|
pack square PNGs (16-1024 px) into a macOS .icns, on any OS
|
|
local sync | serve | status
|
|
build the Craft apps from their checkouts and install them from this machine
|
|
(cargo xtask local help)
|
|
";
|
|
|
|
/// Packages that must build for wasm32-unknown-unknown: the pure core and the web app (which
|
|
/// pulls in the shared egui UI).
|
|
const WASM_PACKAGES: &[&str] = &["artcraft-launcher-core", "artcraft-launcher-web"];
|
|
|
|
fn main() -> ExitCode {
|
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
|
let rest: Vec<&str> = args.iter().skip(1).map(String::as_str).collect();
|
|
let result = match args.first().map(String::as_str) {
|
|
Some("ci") => cmd_ci(),
|
|
Some("wasm") => cmd_wasm(),
|
|
Some("version") => version::run(&root(), &rest),
|
|
Some("ico") => ico::run(&rest),
|
|
Some("icns") => icns::run(&rest),
|
|
Some("local") => local::run(&rest),
|
|
Some("-h" | "--help" | "help") | None => {
|
|
print!("{USAGE}");
|
|
Ok(())
|
|
}
|
|
Some(other) => Err(format!("unknown command `{other}`\n\n{USAGE}")),
|
|
};
|
|
match result {
|
|
Ok(()) => ExitCode::SUCCESS,
|
|
Err(e) => {
|
|
eprintln!("error: {e}");
|
|
ExitCode::FAILURE
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Workspace root (parent of the xtask crate).
|
|
pub fn root() -> PathBuf {
|
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
manifest_dir.parent().unwrap_or(manifest_dir).to_path_buf()
|
|
}
|
|
|
|
pub fn cargo() -> Command {
|
|
let mut c = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()));
|
|
c.current_dir(root());
|
|
c
|
|
}
|
|
|
|
fn run(mut cmd: Command, what: &str) -> Result<(), String> {
|
|
eprintln!("$ {what}");
|
|
let status = cmd.status().map_err(|e| format!("{what}: failed to spawn: {e}"))?;
|
|
if status.success() { Ok(()) } else { Err(format!("{what}: exited with {status}")) }
|
|
}
|
|
|
|
fn cargo_step(args: &[&str]) -> Result<(), String> {
|
|
let mut c = cargo();
|
|
c.args(args);
|
|
run(c, &format!("cargo {}", args.join(" ")))
|
|
}
|
|
|
|
fn cmd_wasm() -> Result<(), String> {
|
|
let mut results = Vec::new();
|
|
for pkg in WASM_PACKAGES {
|
|
let ok = cargo_step(&["check", "--target", "wasm32-unknown-unknown", "-p", pkg]).is_ok();
|
|
results.push((*pkg, ok));
|
|
}
|
|
println!("\nwasm32-unknown-unknown check:");
|
|
for (p, ok) in &results {
|
|
println!(" {:<6} {p}", if *ok { "ok" } else { "FAIL" });
|
|
}
|
|
let failed = results.iter().filter(|r| !r.1).count();
|
|
if failed == 0 { Ok(()) } else { Err(format!("{failed} crate(s) failed the wasm check")) }
|
|
}
|
|
|
|
fn cmd_ci() -> Result<(), String> {
|
|
type Step = (&'static str, Box<dyn Fn() -> Result<(), String>>);
|
|
let steps: Vec<Step> = vec![
|
|
("fmt", Box::new(|| cargo_step(&["fmt", "--all", "--", "--check"]))),
|
|
("clippy", Box::new(|| cargo_step(&["clippy", "--workspace", "--all-targets", "--", "-D", "warnings"]))),
|
|
("test", Box::new(|| cargo_step(&["test", "--workspace"]))),
|
|
("wasm", Box::new(cmd_wasm)),
|
|
];
|
|
let mut done = Vec::new();
|
|
for (name, f) in &steps {
|
|
eprintln!("\n=== ci: {name} ===");
|
|
if let Err(e) = f() {
|
|
println!("\nCI summary:");
|
|
for d in &done {
|
|
println!(" ok {d}");
|
|
}
|
|
println!(" FAIL {name}: {e}");
|
|
for (n, _) in steps.iter().skip(done.len().saturating_add(1)) {
|
|
println!(" skip {n}");
|
|
}
|
|
return Err(format!("ci failed at `{name}`"));
|
|
}
|
|
done.push(*name);
|
|
}
|
|
println!("\nCI summary: all {} steps passed ({})", done.len(), done.join(", "));
|
|
Ok(())
|
|
}
|