### Build All Examples with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().examples()` to compile all example targets in the crate. This is convenient for building and testing all provided examples simultaneously. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build all examples CargoBuild::new() .examples() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Execute Cargo Build and Process Messages Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new()` to start a build subcommand. Specify targets like binaries with `.bin()`, examples with `.example()`, or tests with `.test()`. Set the manifest path and target directory, then execute with `.exec()`. The result is an iterator over compiler messages which can be decoded. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build a specific binary let messages = CargoBuild::new() .bin("my_binary") .manifest_path("path/to/Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); // Iterate over compiler messages for msg in messages { let msg = msg.unwrap(); let decoded = msg.decode().unwrap(); println!("{:?}", decoded); } ``` -------------------------------- ### Build Specific Example with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().example("example_name")` to compile a single specified example target. This allows targeted building of individual examples for testing or demonstration. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build an example named "demo" CargoBuild::new() .example("demo") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Build and Get Executable Path Source: https://context7.com/crate-ci/escargot/llms.txt Builds the target and returns a CargoRun that provides the path to the compiled binary. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build and get the executable let run = CargoBuild::new() .bin("my_app") .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Get the path to the compiled binary println!("Binary path: {}", run.path().display()); // Execute the binary with arguments let output = run.command() .arg("--help") .output() .unwrap(); println!("Output: {}", String::from_utf8_lossy(&output.stdout)); ``` -------------------------------- ### CargoBuild::run - Build and Get Executable Path Source: https://context7.com/crate-ci/escargot/llms.txt Builds the target and returns a `CargoRun` object, which provides the path to the compiled binary and allows executing it. ```APIDOC ## CargoBuild::run - Build and Get Executable Path ### Description Builds the target and returns a `CargoRun` that provides the path to the compiled binary. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.run()`. Configuration is done via preceding methods. ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); let run = CargoBuild::new() .bin("my_app") .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Get the path to the compiled binary println!("Binary path: {}", run.path().display()); // Execute the binary with arguments let output = run.command() .arg("--help") .output() .unwrap(); println!("Output: {}", String::from_utf8_lossy(&output.stdout)); ``` ### Response * **CargoRun** - An object that contains the path to the compiled binary and allows executing it. * **path()** - Returns the `PathBuf` to the compiled binary. * **command()** - Returns a `std::process::Command` that can be used to execute the binary with custom arguments. ``` -------------------------------- ### Create and Run Cargo Build Command Source: https://context7.com/crate-ci/escargot/llms.txt Use `Cargo::new()` to create a new cargo command builder. Chain methods like `.arg()` for custom arguments and `.build()` to return a `CargoBuild` instance. Alternatively, use `.build_with()` for custom build commands or `.into_command()` to get the underlying `process::Command`. ```rust use escargot::Cargo; // Create a new cargo command and run build subcommand let build = Cargo::new() .arg("--verbose") // Pass custom arguments .build(); // Returns CargoBuild // Use a custom build command (e.g., xargo) let custom_build = Cargo::new() .build_with("xbuild"); // Get the underlying process::Command for manual execution let cmd = Cargo::new().into_command(); ``` -------------------------------- ### CargoBuild::run_tests - Build and Run Tests Source: https://context7.com/crate-ci/escargot/llms.txt Builds all test targets (including library, binaries, and examples marked as tests) and provides an iterator over `CargoTest` objects. This is useful for programmatic test execution and result analysis. Requires the `test_unstable` feature. ```APIDOC ## CargoBuild::run_tests - Build and Run Tests (Unstable) ### Description Builds test targets and returns an iterator of `CargoTest` for running tests. Requires the `test_unstable` feature. ### Method POST (Implicit, as it triggers a build) ### Endpoint N/A (Method on `CargoBuild` struct) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build and get test executables let tests: Vec<_> = CargoBuild::new() .tests() .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run_tests() .unwrap() .collect(); for test_result in tests { let test = test_result.unwrap(); println!("Test name: {}", test.name()); println!("Test kind: {}", test.kind()); // "bin", "lib", or "test" println!("Test path: {}", test.path().display()); // Run the test let output = test.command().output().unwrap(); println!("Test passed: {}", output.status.success()); } ``` ### Response #### Success Response (200) - **tests** (Iterator>) - An iterator yielding `CargoTest` objects for each discovered test. #### Response Example ```rust // Each item in the iterator is a Result containing a CargoTest object or a CargoError. // Example of accessing test details: // Test name: my_test // Test kind: test // Test path: /path/to/project/target/debug/deps/my_crate-abcdef1234567890 // Test passed: true ``` ``` -------------------------------- ### Get Binary Path with CargoRun::path Source: https://context7.com/crate-ci/escargot/llms.txt Use `path()` to retrieve the filesystem path of a compiled binary. This is useful for executing the binary directly or with custom configurations. ```rust use escargot::CargoBuild; use std::process::Command; let target_dir = tempfile::TempDir::new().unwrap(); let run = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Use path() to get the binary location let binary_path = run.path(); // Use with custom process spawning let child = Command::new(binary_path) .env("CUSTOM_VAR", "value") .spawn() .unwrap(); ``` -------------------------------- ### CargoRun::path - Get Binary Path Source: https://context7.com/crate-ci/escargot/llms.txt Retrieves the filesystem path to the compiled binary. This is useful for executing the compiled application directly or for further processing. ```APIDOC ## CargoRun::path - Get Binary Path ### Description Returns the filesystem path to the compiled binary. ### Method GET (Implicit) ### Endpoint N/A (Method on a `CargoRun` object) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; use std::process::Command; let target_dir = tempfile::TempDir::new().unwrap(); let run = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Use path() to get the binary location let binary_path = run.path(); // Use with custom process spawning let child = Command::new(binary_path) .env("CUSTOM_VAR", "value") .spawn() .unwrap(); ``` ### Response #### Success Response (200) - **binary_path** (PathBuf) - The filesystem path to the compiled binary. #### Response Example ```rust // Example output (path will vary) // "/path/to/your/project/target/debug/my_app" ``` ``` -------------------------------- ### Build All Binaries with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().bins()` to compile all binary targets defined in the crate. This is useful when you need to build every executable provided by your project. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build all binaries in the crate CargoBuild::new() .bins() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Build in Release Mode Source: https://context7.com/crate-ci/escargot/llms.txt Enables optimizations by building in release mode. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build in release mode CargoBuild::new() .bin("my_app") .release() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Create Command to Run Binary with CargoRun::command Source: https://context7.com/crate-ci/escargot/llms.txt Creates a `std::process::Command` pre-configured to execute the compiled binary. This allows for further customization like adding arguments or environment variables before execution. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); let run = CargoBuild::new() .example("demo") .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Run the compiled binary let status = run.command() .arg("--verbose") .env("LOG_LEVEL", "debug") .status() .unwrap(); assert!(status.success()); ``` -------------------------------- ### Enable All Features Source: https://context7.com/crate-ci/escargot/llms.txt Enables all available features during the build. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build with all features CargoBuild::new() .bin("my_app") .all_features() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CargoBuild::all_features - Enable All Features Source: https://context7.com/crate-ci/escargot/llms.txt Enables all available features defined in the Cargo.toml file during the build. ```APIDOC ## CargoBuild::all_features - Enable All Features ### Description Enables all available features during the build. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.all_features()` ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .all_features() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.all_features()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Cargo Command Builder Source: https://context7.com/crate-ci/escargot/llms.txt The Cargo struct serves as the primary entry point for constructing and executing Cargo commands. ```APIDOC ## Cargo Command Builder ### Description Initializes a new Cargo process command builder. ### Methods - **Cargo::new()** - Creates a new Cargo command instance. - **arg(string)** - Adds a custom argument to the command. - **build()** - Returns a CargoBuild instance. - **build_with(string)** - Uses a custom build command (e.g., xargo). - **into_command()** - Returns the underlying process::Command for manual execution. ``` -------------------------------- ### Build Specific Binary with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().bin("binary_name")` to compile a single specified binary target. Ensure the `manifest_path` and `target_dir` are correctly set before executing the build. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build a single binary named "cli" CargoBuild::new() .bin("cli") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CargoRun::command - Create Command to Run Binary Source: https://context7.com/crate-ci/escargot/llms.txt Generates a `std::process::Command` object that is pre-configured to execute the compiled binary. This allows for easy customization of arguments, environment variables, and other command properties before execution. ```APIDOC ## CargoRun::command - Create Command to Run Binary ### Description Creates a `std::process::Command` configured to run the compiled binary. ### Method GET (Implicit) ### Endpoint N/A (Method on a `CargoRun` object) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); let run = CargoBuild::new() .example("demo") .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run() .unwrap(); // Run the compiled binary let status = run.command() .arg("--verbose") .env("LOG_LEVEL", "debug") .status() .unwrap(); assert!(status.success()); ``` ### Response #### Success Response (200) - **command** (`std::process::Command`) - A command object ready to be executed. #### Response Example ```rust // The returned object is a std::process::Command, which can be used like: // let output = command.output().unwrap(); ``` ``` -------------------------------- ### Build All Tests with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().tests()` to compile all test targets within the crate. This is useful for building all tests, including unit and integration tests, in one go. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build all tests CargoBuild::new() .tests() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Build Package from Workspace with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt When working with workspaces, use `CargoBuild::new().package("package_name")` to specify which package to build. This is often combined with other target specifiers like `.bin()`. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build a specific package in a workspace CargoBuild::new() .package("my-lib") .bin("my-lib") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Infer Release Mode Source: https://context7.com/crate-ci/escargot/llms.txt Automatically matches the build mode of the current process. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Match the current process's build mode CargoBuild::new() .bin("my_app") .current_release() // Release if running release build, debug otherwise .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Set Environment Variables Source: https://context7.com/crate-ci/escargot/llms.txt Sets environment variables for the cargo build process. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build with custom environment variables CargoBuild::new() .bin("my_app") .env("RUST_BACKTRACE", "1") .env("MY_CONFIG", "value") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Current Process Target Source: https://context7.com/crate-ci/escargot/llms.txt Uses the same target triplet as the current running process. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build for the same target as the current process CargoBuild::new() .bin("my_app") .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CargoBuild API Source: https://context7.com/crate-ci/escargot/llms.txt The CargoBuild struct provides methods for configuring and executing build-related Cargo subcommands. ```APIDOC ## CargoBuild API ### Description Configures and executes build operations for binaries, examples, tests, and workspace packages. ### Methods - **bin(string)** - Build a specific binary target. - **bins()** - Build all binary targets. - **example(string)** - Build a specific example. - **examples()** - Build all examples. - **test(string)** - Build a specific test target. - **tests()** - Build all test targets. - **package(string)** - Specify a package in a workspace. - **manifest_path(string)** - Set the path to Cargo.toml. - **target_dir(path)** - Set the target directory. - **exec()** - Executes the command and returns compiler messages. ``` -------------------------------- ### CargoBuild::current_target - Current Process Target Source: https://context7.com/crate-ci/escargot/llms.txt Uses the same target triplet as the current running process, simplifying builds when the target environment is known. ```APIDOC ## CargoBuild::current_target - Current Process Target ### Description Uses the same target triplet as the current running process. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.current_target()` ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.current_target()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Enable Specific Features Source: https://context7.com/crate-ci/escargot/llms.txt Enables specific cargo features during the build. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build with specific features enabled CargoBuild::new() .bin("my_app") .features("feature1 feature2") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Build and Run Tests with CargoBuild::run_tests Source: https://context7.com/crate-ci/escargot/llms.txt Builds test targets and returns an iterator of `CargoTest` for running tests. Requires the `test_unstable` feature. Each `CargoTest` can be executed independently. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build and get test executables let tests: Vec<_> = CargoBuild::new() .tests() .current_release() .current_target() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run_tests() .unwrap() .collect(); for test_result in tests { let test = test_result.unwrap(); println!("Test name: {}", test.name()); println!("Test kind: {}", test.kind()); // "bin", "lib", or "test" println!("Test path: {}", test.path().display()); // Run the test let output = test.command().output().unwrap(); println!("Test passed: {}", output.status.success()); } ``` -------------------------------- ### CargoBuild::arg / CargoBuild::args - Custom Arguments Source: https://context7.com/crate-ci/escargot/llms.txt Passes custom arguments directly to the underlying cargo command, allowing for advanced configuration. ```APIDOC ## CargoBuild::arg / CargoBuild::args - Custom Arguments ### Description Passes custom arguments to the cargo command. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters * **arg** (string) - Required - A single custom argument to pass to cargo. * **args** (array of strings) - Required - Multiple custom arguments to pass to cargo. ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .arg("--verbose") .args(["--jobs", "4"]) .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.arg()` or `.args()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### CargoBuild::current_release - Infer Release Mode Source: https://context7.com/crate-ci/escargot/llms.txt Automatically uses release mode if the current process was built in release mode. Otherwise, it defaults to debug mode. ```APIDOC ## CargoBuild::current_release - Infer Release Mode ### Description Automatically uses release mode if the current process was built in release mode. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.current_release()` ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .current_release() // Release if running release build, debug otherwise .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.current_release()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### CargoBuild::no_default_features - Disable Default Features Source: https://context7.com/crate-ci/escargot/llms.txt Disables the default features specified in the Cargo.toml file, allowing for a more minimal build. ```APIDOC ## CargoBuild::no_default_features - Disable Default Features ### Description Disables the default features during the build. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.no_default_features()` ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .no_default_features() .features("minimal") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.no_default_features()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Error Handling with CargoError Source: https://context7.com/crate-ci/escargot/llms.txt Demonstrates how to handle errors returned by Escargot operations. It shows how to inspect the `CargoError` and its `ErrorKind` to provide specific feedback or take appropriate actions based on the type of failure. ```APIDOC ## Error Handling with CargoError ### Description Escargot provides structured error handling through `CargoError` and `ErrorKind`. ### Method GET/POST (Implicit, depending on the operation that might fail) ### Endpoint N/A (Error handling for various Escargot operations) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; use escargot::error::{CargoError, ErrorKind}; let target_dir = tempfile::TempDir::new().unwrap(); let result = CargoBuild::new() .bin("nonexistent_binary") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run(); match result { Ok(run) => { println!("Binary path: {}", run.path().display()); } Err(err) => { match err.kind() { ErrorKind::InvalidCommand => { eprintln!("Failed to spawn cargo: {}", err); } ErrorKind::CommandFailed => { eprintln!("Cargo command failed: {}", err); } ErrorKind::InvalidOutput => { eprintln!("Failed to parse cargo output: {}", err); } } } } ``` ### Response #### Error Response - **CargoError** - A structured error object containing details about the failure. - **kind()** (`ErrorKind`) - Returns the specific type of error. - `InvalidCommand`: Failed to spawn the Cargo process. - `CommandFailed`: The Cargo command exited with a non-zero status. - `InvalidOutput`: Failed to parse the output from the Cargo command. #### Response Example ```rust // Example error output for a non-existent binary: // Failed to parse cargo output: cargo exited with an error: ... ``` ``` -------------------------------- ### Custom Arguments Source: https://context7.com/crate-ci/escargot/llms.txt Passes custom arguments to the cargo command. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build with custom arguments CargoBuild::new() .bin("my_app") .arg("--verbose") .args(["--jobs", "4"]) .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CargoBuild::release - Release Mode Build Source: https://context7.com/crate-ci/escargot/llms.txt Builds artifacts in release mode with optimizations enabled. This is useful for production builds where performance is critical. ```APIDOC ## CargoBuild::release - Release Mode Build ### Description Builds artifacts in release mode with optimizations enabled. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters None directly for `.release()` ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .release() .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.release()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### CargoBuild::features - Enable Specific Features Source: https://context7.com/crate-ci/escargot/llms.txt Enables specific cargo features during the build process, allowing for conditional compilation. ```APIDOC ## CargoBuild::features - Enable Specific Features ### Description Enables specific cargo features during the build. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters * **features** (string) - Required - A space-separated string of feature names to enable. ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .features("feature1 feature2") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.features()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### CargoBuild::env - Set Environment Variables Source: https://context7.com/crate-ci/escargot/llms.txt Sets environment variables that will be available to the cargo build process. This is useful for configuring build-time behavior. ```APIDOC ## CargoBuild::env - Set Environment Variables ### Description Sets environment variables for the cargo build process. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters * **name** (string) - Required - The name of the environment variable. * **value** (string) - Required - The value to set for the environment variable. ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .env("RUST_BACKTRACE", "1") .env("MY_CONFIG", "value") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.env()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Build Specific Test with CargoBuild Source: https://context7.com/crate-ci/escargot/llms.txt Use `CargoBuild::new().test("test_name")` to compile a single specified test target, such as an integration test. This enables focused compilation of individual tests. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build a test named "integration_test" CargoBuild::new() .test("integration_test") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CommandMessages - Iterate Cargo Output Source: https://context7.com/crate-ci/escargot/llms.txt Provides an iterator over JSON messages emitted by Cargo commands. This allows for fine-grained parsing and handling of build events, compiler artifacts, and diagnostic messages. ```APIDOC ## CommandMessages - Iterate Cargo Output ### Description `CommandMessages` provides an iterator over JSON messages from cargo commands. ### Method GET (Implicit) ### Endpoint N/A (Iterator from `CargoBuild::exec()`) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; use escargot::format::Message; let target_dir = tempfile::TempDir::new().unwrap(); let messages = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); for msg_result in messages { let msg = msg_result.unwrap(); let decoded: Message = msg.decode().unwrap(); match decoded { Message::CompilerArtifact(artifact) => { println!("Built: {:?}", artifact.target.name); println!("Files: {:?}", artifact.filenames); println!("Fresh: {}", artifact.fresh); } Message::CompilerMessage(compiler_msg) => { println!("Message: {}", compiler_msg.message.message); if let Some(rendered) = &compiler_msg.message.rendered { println!("Rendered: {}", rendered); } } Message::BuildScriptExecuted(script) => { println!("Script executed for: {:?}", script.package_id); } Message::BuildFinished(finished) => { println!("Build success: {}", finished.success); } _ => {} } } ``` ### Response #### Success Response (200) - **messages** (Iterator>) - An iterator yielding `MessageWrapper` objects, which can be decoded into various `Message` types. #### Response Example ```rust // Example output for a CompilerArtifact message: // Built: "my_app" // Files: ["/path/to/target/debug/my_app"] // Fresh: false ``` ``` -------------------------------- ### Iterate Cargo Output with CommandMessages Source: https://context7.com/crate-ci/escargot/llms.txt `CommandMessages` provides an iterator over JSON messages emitted by Cargo commands. This allows for fine-grained parsing of build artifacts, compiler messages, and build script execution details. ```rust use escargot::CargoBuild; use escargot::format::Message; let target_dir = tempfile::TempDir::new().unwrap(); let messages = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); for msg_result in messages { let msg = msg_result.unwrap(); let decoded: Message = msg.decode().unwrap(); match decoded { Message::CompilerArtifact(artifact) => { println!("Built: {:?}", artifact.target.name); println!("Files: {:?}", artifact.filenames); println!("Fresh: {}", artifact.fresh); } Message::CompilerMessage(compiler_msg) => { println!("Message: {}", compiler_msg.message.message); if let Some(rendered) = &compiler_msg.message.rendered { println!("Rendered: {}", rendered); } } Message::BuildScriptExecuted(script) => { println!("Script executed for: {:?}", script.package_id); } Message::BuildFinished(finished) => { println!("Build success: {}", finished.success); } _ => {} } } ``` -------------------------------- ### CargoBuild::target - Cross-Compilation Target Source: https://context7.com/crate-ci/escargot/llms.txt Specifies a target triplet for cross-compilation, allowing you to build for different architectures and operating systems. ```APIDOC ## CargoBuild::target - Cross-Compilation Target ### Description Specifies a target triplet for cross-compilation. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters * **target** (string) - Required - The target triplet string (e.g., "x86_64-unknown-linux-gnu"). ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .target("x86_64-unknown-linux-gnu") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.target()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Process Cargo Compiler Messages Source: https://context7.com/crate-ci/escargot/llms.txt Iterate through Cargo build messages to extract and handle compiler diagnostics, errors, and span information. ```rust use escargot::CargoBuild; use escargot::format::{Message, Artifact, FromCompiler}; use escargot::format::diagnostic::{Diagnostic, DiagnosticLevel}; let target_dir = tempfile::TempDir::new().unwrap(); let messages = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); for msg_result in messages { let msg = msg_result.unwrap(); let decoded = msg.decode().unwrap(); if let Message::CompilerMessage(from_compiler) = decoded { let diagnostic: &Diagnostic = &from_compiler.message; match diagnostic.level { DiagnosticLevel::Error => { eprintln!("ERROR: {}", diagnostic.message); } DiagnosticLevel::Warning => { eprintln!("WARNING: {}", diagnostic.message); } DiagnosticLevel::Note | DiagnosticLevel::Help => { println!("INFO: {}", diagnostic.message); } _ => {} } // Access span information for span in &diagnostic.spans { if span.is_primary { println!(" at {}:{}:{}", span.file_name.display(), span.line_start, span.column_start ); } } } } ``` -------------------------------- ### Cross-Compilation Target Source: https://context7.com/crate-ci/escargot/llms.txt Specifies a target triplet for cross-compilation. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build for a specific target CargoBuild::new() .bin("my_app") .target("x86_64-unknown-linux-gnu") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### CargoBuild::env_remove - Remove Environment Variables Source: https://context7.com/crate-ci/escargot/llms.txt Removes environment variables from the cargo build process, ensuring a clean build environment. ```APIDOC ## CargoBuild::env_remove - Remove Environment Variables ### Description Removes environment variables from the cargo build process. ### Method Not applicable (method chaining on CargoBuild) ### Endpoint Not applicable (local build process) ### Parameters * **name** (string) - Required - The name of the environment variable to remove. ### Request Example ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); CargoBuild::new() .bin("my_app") .env_remove("CARGO_TARGET_DIR") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` ### Response None directly from `.env_remove()`, the result of `.exec()` or `.run()` indicates success or failure. ``` -------------------------------- ### Error Handling with CargoError Source: https://context7.com/crate-ci/escargot/llms.txt Escargot provides structured error handling through `CargoError` and `ErrorKind`. This allows for specific handling of different failure scenarios, such as invalid commands or failed Cargo executions. ```rust use escargot::CargoBuild; use escargot::error::{CargoError, ErrorKind}; let target_dir = tempfile::TempDir::new().unwrap(); let result = CargoBuild::new() .bin("nonexistent_binary") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .run(); match result { Ok(run) => { println!("Binary path: {}", run.path().display()); } Err(err) => { match err.kind() { ErrorKind::InvalidCommand => { eprintln!("Failed to spawn cargo: {}", err); } ErrorKind::CommandFailed => { eprintln!("Cargo command failed: {}", err); } ErrorKind::InvalidOutput => { eprintln!("Failed to parse cargo output: {}", err); } } } } ``` -------------------------------- ### Remove Environment Variables Source: https://context7.com/crate-ci/escargot/llms.txt Removes environment variables from the cargo build process. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build with certain env vars removed CargoBuild::new() .bin("my_app") .env_remove("CARGO_TARGET_DIR") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Disable Default Features Source: https://context7.com/crate-ci/escargot/llms.txt Disables the default features during the build. ```rust use escargot::CargoBuild; let target_dir = tempfile::TempDir::new().unwrap(); // Build without default features CargoBuild::new() .bin("my_app") .no_default_features() .features("minimal") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); ``` -------------------------------- ### Message::decode_custom - Custom Deserialization Source: https://context7.com/crate-ci/escargot/llms.txt Allows deserializing Cargo's JSON output messages into custom Rust structs that implement `serde::Deserialize`. This is useful for extracting specific information without needing to parse the full `Message` enum. ```APIDOC ## Message::decode_custom - Custom Deserialization ### Description Deserializes messages into custom types for advanced use cases. ### Method GET (Implicit) ### Endpoint N/A (Method on a `MessageWrapper` object) ### Parameters None ### Request Example ```rust use escargot::CargoBuild; use serde::Deserialize; #[derive(Deserialize)] struct MinimalArtifact { reason: String, target: Option, } #[derive(Deserialize)] struct MinimalTarget { name: String, } let target_dir = tempfile::TempDir::new().unwrap(); let messages = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); for msg_result in messages { let msg = msg_result.unwrap(); // Decode into a custom type let custom: MinimalArtifact = msg.decode_custom().unwrap(); println!("Reason: {}", custom.reason); } ``` ### Response #### Success Response (200) - **custom_data** (T) - The deserialized data of type `T`, where `T` must implement `serde::Deserialize`. #### Response Example ```rust // Example output for a custom deserialized artifact: // Reason: build-finished ``` ``` -------------------------------- ### Custom Deserialization with Message::decode_custom Source: https://context7.com/crate-ci/escargot/llms.txt Deserializes Cargo JSON messages into custom types for advanced use cases. This is useful when you only need specific fields from a message type. ```rust use escargot::CargoBuild; use serde::Deserialize; #[derive(Deserialize)] struct MinimalArtifact { reason: String, target: Option, } #[derive(Deserialize)] struct MinimalTarget { name: String, } let target_dir = tempfile::TempDir::new().unwrap(); let messages = CargoBuild::new() .bin("my_app") .manifest_path("Cargo.toml") .target_dir(target_dir.path()) .exec() .unwrap(); for msg_result in messages { let msg = msg_result.unwrap(); // Decode into a custom type let custom: MinimalArtifact = msg.decode_custom().unwrap(); println!("Reason: {}", custom.reason); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.