SunsetWan/xcsift-rust

Streaming Rust port of xcsift for token-efficient Xcode and Swift build output

★ 0Forks 0RustGitHub ↗Compare

README

xcsift-rust

xcsift-rust turns verbose xcodebuild and Swift Package Manager logs into compact JSON, TOON, or GitHub Actions annotations for coding agents. It is an independent Rust port of Łukasz Domaradzki's xcsift, with output behavior based on upstream xcsift 1.3.1 (0a4b128).

The implementation uses Rust 1.97.1, Edition 2024, bounded BufRead streaming, statically initialized regular expressions, and explicit state machines for multi-line linker and test output. Input is processed without retaining the complete build log.

Install

git clone https://github.com/SunsetWan/xcsift-rust.git
cd xcsift-rust
cargo build --release --locked
install target/release/xcsift-rust /usr/local/bin/xcsift-rust

The repository pins Rust/Cargo 1.97.1 in rust-toolchain.toml and exact direct dependency versions in Cargo.toml.

Usage

Always merge stderr into stdout because Apple compilers write diagnostics to stderr.

xcodebuild build 2>&1 | xcsift-rust
xcodebuild test 2>&1 | xcsift-rust --warnings
swift build 2>&1 | xcsift-rust -f toon
swift test 2>&1 | xcsift-rust --slow-threshold 1.0
xcodebuild test -enableCodeCoverage YES 2>&1 | xcsift-rust --coverage

Useful modes:

-w, --warnings              include warning details
-W, --Werror                convert warnings to errors
-q, --quiet                 suppress clean successful output
-E, --exit-on-failure       return 1 unless status is success
-f, --format FORMAT         json, toon, or github-actions
-c, --coverage              discover and convert coverage data
    --coverage-details      include per-file coverage
-e, --executable            report generated app bundles
    --build-info            report target phases, timing, dependencies, top five
    --slow-threshold N      report tests slower than N seconds
    --xcbeautify             parse xcbeautify/Tuist markers

Run xcsift-rust --help for all TOON and configuration options.

Output contract

The parser preserves xcsift 1.3.1's three terminal states:

  • success: a positive success marker or passed tests were observed and no actual failure was parsed.
  • failed: compiler, linker, test, Werror, or terminal failure evidence was observed.
  • incomplete: the stream ended without success or failure evidence.

JSON omits empty detail arrays and absent optional fields. Warning details require --warnings; coverage files require --coverage-details; build information and executables are opt-in. On GITHUB_ACTIONS=true, JSON or TOON is followed by workflow annotations. Explicit -f github-actions emits annotations only.

The line reader buffers at most 5,000 bytes per logical line. Longer lines are discarded as unparseable while the stream continues, preventing a single malformed log line from growing memory without bound.

Configuration

Generate a documented template:

xcsift-rust --init

Configuration search order is:

  1. .xcsift.toml in the current directory
  2. ~/.config/xcsift/config.toml

Use --config PATH for an explicit file. CLI values override file values; boolean flags enable their corresponding option.

format = "toon"
warnings = true
slow_threshold = 1.0
exit_on_failure = true

[toon]
delimiter = "comma"
key_folding = "safe"
flatten_depth = 3

Coverage conversion

--coverage accepts LLVM/SPM JSON, xccov JSON, .xcresult bundles, and directories containing .profraw data. On macOS the converter invokes the same Apple toolchain paths as upstream:

  • xcrun xccov view --report --json RESULT.xcresult
  • xcrun llvm-profdata merge -sparse ...
  • xcrun llvm-cov export TEST_BINARY -instr-profile=... -format=text

Without --coverage-path, a detected test-target hint first selects a matching recent Xcode result and then falls back to standard SwiftPM .build/.../codecov directories. Without a target hint, local SwiftPM coverage is checked first. DerivedData discovery considers only recent .xcresult bundles under project Logs/Test directories; it does not follow symbolic links or recursively scan unrelated build products. Conversion returns no coverage section when the required Apple tools or matching data are unavailable.

Compatibility and intentional differences

This is a parser/formatter-compatible port, not a byte-for-byte reimplementation:

  • Supported: compiler/fatal/generic diagnostics, compile/runtime/SwiftUI warnings, linker failures, XCTest and Swift Testing (including parallel, aggregate, #expect, duration, crash, slow and flaky detection), build/test timing, target build information, executables, xcbeautify input, JSON, TOON, GitHub Actions, TOML configuration, coverage conversion, and upstream exit semantics.
  • TOON is emitted by a native compact encoder. Its data model, delimiters, tabular arrays, safe key folding, and flatten-depth behavior are compatible, but insignificant quoting or field-order details may differ from toon-swift.
  • The upstream Claude Code, Codex, and Cursor installer subcommands are intentionally not included. Install this standalone binary through Cargo or copy the release artifact.
  • The executable is named xcsift-rust, so it can be benchmarked or installed alongside Swift xcsift.

Development

cargo fmt --check
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo test --locked
cargo build --release --locked

The integration suite includes upstream's large build, Swift Testing, and linker fixtures plus process-level checks for exit codes, quiet mode, Werror, and CI annotation appending.

Attribution and license

The product design, fixtures, and behavior contract derive from xcsift 1.3.1 by Łukasz Domaradzki. The original MIT copyright and permission notice are preserved in LICENSE. Rust-specific code in this port is distributed under the same MIT terms.

Contributors

SunsetWan

Issues