Replace npm build script with new cargo run tool (#3832)

* move nix flake to root

* cargo run tool

* use thiserror in third-party-licenses tool

* prefere panic over exit

* Add automatic dependency check to cargo run tool

* Skip dependecies that are not needed for the current task

* Fixup

* Fixup

* fix windows

* Fixup

* improve usage text

* Fix linux bundle

* add graphen-cli

* fix build profile

* fix

* release profile should not include debug infos

* Review

* remove profiling profile

was redundent with release

* rename to cargo-run tool

* improve consistency

* rename deps to requirements

* fix

* return success when showing usage
This commit is contained in:
Timon
2026-03-07 14:26:19 +01:00
committed by GitHub
parent 50ef6e15cb
commit 5d22292072
39 changed files with 664 additions and 404 deletions

View File

@@ -1,3 +1,5 @@
#![cfg_attr(target_os = "linux", allow(unused))] // TODO: Remove this when bundling for linux is implemented
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
@@ -27,8 +29,7 @@ pub(crate) fn cef_path() -> PathBuf {
}
pub(crate) fn build_bin(package: &str, bin: Option<&str>) -> Result<PathBuf, Box<dyn Error>> {
let profile = &profile_name();
let mut args = vec!["build", "--package", package, "--profile", profile];
let mut args = vec!["build", "--package", package, "--profile", profile_name()];
if let Some(bin) = bin {
args.push("--bin");
args.push(bin);
@@ -45,7 +46,7 @@ pub(crate) fn build_bin(package: &str, bin: Option<&str>) -> Result<PathBuf, Box
pub(crate) fn run_command(program: &str, args: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
let status = Command::new(program).args(args).stdout(Stdio::inherit()).stderr(Stdio::inherit()).status()?;
if !status.success() {
std::process::exit(1);
return Err(format!("Command '{}' with args {:?} failed with status: {}", program, args, status).into());
}
Ok(())
}

View File

@@ -1,20 +1,19 @@
use std::error::Error;
use crate::common::*;
pub fn main() -> Result<(), Box<dyn Error>> {
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_bin = build_bin("graphite-desktop-platform-linux", None)?;
// TODO: Implement bundling for linux
// TODO: Consider adding more useful cli
if std::env::args().any(|a| a == "open") {
run_command(&app_bin.to_string_lossy(), &[]).expect("failed to open app");
let args: Vec<String> = std::env::args().collect();
if let Some(pos) = args.iter().position(|a| a == "open") {
let extra_args: Vec<&str> = args[pos + 1..].iter().map(|s| s.as_str()).collect();
run_command(&app_bin.to_string_lossy(), &extra_args).expect("failed to open app");
} else {
println!("Binary built and placed at {}", app_bin.to_string_lossy());
eprintln!("Binary built and placed at {}", app_bin.to_string_lossy());
eprintln!("Bundling for Linux is not yet implemented.");
eprintln!("You can still start the app with the `open` subcommand. `cargo run -p graphite-desktop-bundle -- open`");
std::process::exit(1);
}
Ok(())

View File

@@ -22,9 +22,11 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let app_dir = bundle(&profile_path, &app_bin, &helper_bin);
// TODO: Consider adding more useful cli
if std::env::args().any(|a| a == "open") {
let executable_path = app_dir.join(EXEC_PATH).join(APP_NAME);
run_command(&executable_path.to_string_lossy(), &[]).expect("failed to open app");
let args: Vec<String> = std::env::args().collect();
if let Some(pos) = args.iter().position(|a| a == "open") {
let executable = app_dir.join(EXEC_PATH).join(APP_NAME);
let extra_args: Vec<&str> = args[pos + 1..].iter().map(|s| s.as_str()).collect();
run_command(&executable.to_string_lossy(), &extra_args).expect("failed to open app");
}
Ok(())

View File

@@ -12,9 +12,10 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let executable = bundle(&profile_path(), &app_bin);
// TODO: Consider adding more useful cli
if std::env::args().any(|a| a == "open") {
let executable_path = executable.to_string_lossy();
run_command(&executable_path, &[]).expect("failed to open app")
let args: Vec<String> = std::env::args().collect();
if let Some(pos) = args.iter().position(|a| a == "open") {
let extra_args: Vec<&str> = args[pos + 1..].iter().map(|s| s.as_str()).collect();
run_command(&executable.to_string_lossy(), &extra_args).expect("failed to open app")
}
Ok(())