testing/cross_backend/cargo_binary.ts

Cargo-built test binaries for cross-backend projects — build before the spawn, then spawn the binary itself.

A config that spawns cargo run builds inside spawn_backend's health window, so a cold build can outlast the startup timeout, and the build's output is held in the spawn's stderr tail rather than shown. prepare_cargo_binary runs the build first, with its output inherited, as a pre-spawn hook (create_cross_backend_global_setup's before_spawn), and the config's start_command names the built binary (resolve_cargo_binary_path), so the spawn starts at once.

The binary's path comes from cargo metadata: under the workspace's resolved target_directory, so CARGO_TARGET_DIR and build.target-dir are honoured, in the profile's output directory.

view source

Declarations
#

7 declarations

CargoBinaryOptions
#

testing/cross_backend/cargo_binary.ts view source

CargoBinaryOptions import type {CargoBinaryOptions} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

Options naming one Cargo-built binary.

workspace_dir

The Cargo workspace (or package) directory the build runs in.

type string

readonly

package

The Cargo package holding the binary (cargo build -p).

type string

readonly

bin?

The binary target (cargo build --bin). Default the package name.

type string

readonly

profile?

The Cargo profile. Default 'dev', whose output is debug/.

type string

readonly

is_no_rebuild_requested
#

testing/cross_backend/cargo_binary.ts view source

(value: string | undefined): boolean import {is_no_rebuild_requested} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

Whether an NO_REBUILD_ENV value asks to skip the build — only an explicit 1 / true, so FUZ_TESTING_NO_REBUILD=0 still builds.

value

the variable's value, undefined when unset

type string | undefined

returns

boolean

NO_REBUILD_ENV
#

testing/cross_backend/cargo_binary.ts view source

"FUZ_TESTING_NO_REBUILD" import {NO_REBUILD_ENV} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

Env var skipping the build, for iteration on a known-current binary: 1 or true skips it, any other value (0, false, empty) builds.

prepare_cargo_binary
#

testing/cross_backend/cargo_binary.ts view source

(options: CargoBinaryOptions): string import {prepare_cargo_binary} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

Build a Cargo binary before its backend spawns, unless NO_REBUILD_ENV asks to skip it, and return its path. The build's output is inherited, so a cold build shows its progress, and a failed build throws — the project fails loudly rather than spawning a stale binary. cargo build is incremental, so a build with nothing changed is quick.

Synchronous: vitest awaits each project's globalSetup in turn, so one invocation selecting several projects builds once, then finds the build current.

options

the workspace, package, binary and profile

returns

string

the binary's absolute path (resolve_cargo_binary_path)

throws

  • Error - when the workspace is missing, the build fails, or `cargo metadata` fails

resolve_cargo_binary_path
#

testing/cross_backend/cargo_binary.ts view source

(options: CargoBinaryOptions): string import {resolve_cargo_binary_path} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

The path of a Cargo-built binary, without building it — what a config's start_command names. Runs cargo metadata once per process per workspace, so it needs cargo on PATH.

options

the workspace, package, binary and profile

returns

string

the binary's absolute path

throws

  • Error - when the workspace is missing or `cargo metadata` fails

to_cargo_binary_path
#

testing/cross_backend/cargo_binary.ts view source

(metadata_json: string, bin: string, profile: string): string import {to_cargo_binary_path} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

The binary path cargo build --profile <profile> --bin <bin> writes, from cargo metadata --no-deps --format-version 1 output.

metadata_json

the cargo metadata output

type string

bin

the binary's name

type string

profile

the Cargo profile

type string

returns

string

the binary's absolute path

throws

  • Error - when the output carries no `target_directory`

to_cargo_profile_dir
#

testing/cross_backend/cargo_binary.ts view source

(profile: string): string import {to_cargo_profile_dir} from '@fuzdev/fuz_app/testing/cross_backend/cargo_binary.js';

The directory under the target directory a profile's output lands in — debug for dev, the profile's own name otherwise (release, a custom cross-test).

profile

the Cargo profile

type string

returns

string

Depends on
#