Process

Function Process 

Source
pub fn Process(Argument: &Argument) -> Result<(), Error>
Expand description

Main orchestration logic for preparing and executing the build.

This function is the core of the build system, coordinating all aspects of preparing, building, and restoring project configurations. It:

  1. Validates the project directory and configuration files
  2. Creates guards to backup and restore configuration files
  3. Generates a unique product name and bundle identifier based on build flags
  4. Modifies Cargo.toml and Tauri configuration files
  5. Optionally stages a Node.js sidecar binary
  6. Executes the provided build command
  7. Cleans up temporary files after successful build

§Parameters

  • Argument - Parsed command-line arguments and environment variables

§Returns

Returns Ok(()) on successful build completion or a BuildError if any step fails.

§Errors

  • BuildError::Missing - If the project directory doesn’t exist
  • BuildError::Config - If Tauri configuration file not found
  • BuildError::Exists - If a backup file already exists
  • BuildError::Io - For file operation failures
  • BuildError::Edit - For TOML editing failures
  • BuildError::Json / BuildError::Jsonfive - For JSON/JSON5 parsing failures
  • BuildError::Parse - For TOML parsing failures
  • BuildError::Shell - If the build command fails

§Build Flavor Generation

The product name and bundle identifier are generated by combining:

  • Environment: Node.js environment (development, production, etc.)
  • Dependency: Dependency information (org/repo or generic)
  • Node Version: Node.js version if bundling a sidecar
  • Build Flags: Bundle, Clean, Browser, Compile, Debug

Example product name: Development_GenDependency_22NodeVersion_Debug_Mountain

Example bundle identifier: land.editor.binary.development.generic.node.22.debug.mountain

§Node.js Sidecar Bundling

If NodeVersion is specified:

  • The Node.js binary is copied from Element/SideCar/{triple}/NODE/{version}/
  • The binary is staged in the project’s Binary/ directory
  • The Tauri configuration is updated to include the sidecar
  • The binary is given appropriate permissions on Unix-like systems
  • The temporary directory is cleaned up after successful build

§File Safety

All configuration file modifications are protected by the Guard pattern:

  • Files are backed up before modification
  • Files are automatically restored on error or when the guard drops
  • This ensures the original state is preserved regardless of build outcome

§Example

use crate::Maintain::Source::Build::Process;
use crate::Maintain::Source::Build::Argument;
let argument = Argument::parse();
Process(&argument)?;