Generated banner for Migrate To Rust
Generated logo for Migrate To Rust

Migrate To Rust

GoogleOfficialPublished by Google

  • Skill
  • Workflow
  • Software development
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

Clones, analyzes, plans, and migrates legacy codebases (C++, Fortran, Java, Python, C, Shell) from a GitHub URL or local directory to a modern, high-performance, deterministic, 100% Safe Rust architecture, tracking live telemetry across every task bucket, test failure/fix cycle, and Profile-Guided Optimization (PGO) stage, and producing a first-person AI storytelling report and interactive HTML infographic. Use when migrating a GitHub repository or local codebase to Rust, porting legacy C++, Fortran, Python, or Java workloads to memory-safe Rust, designing Struct-of-Arrays (SoA) or SIMD Rust architectures, or optimizing Rust ports with LLVM PGO. Don't use for unrelated non-Rust refactoring or single-line syntax questions.
— the description by Google

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a comprehensive, multi-stage process for porting legacy codebases written in languages like C++, Fortran, Java, or Python into modern, memory-safe Rust. It emphasizes a rigorous engineering approach, requiring the use of specific telemetry scripts to track progress, performance benchmarks, and test coverage. The workflow includes architectural planning, iterative refactoring, A/B parity testing, and Profile-Guided Optimization (PGO) to ensure the resulting Rust implementation is both safe and performant. It concludes by generating a detailed, first-person engineering narrative and an interactive HTML infographic to visualize the migration journey.

What it does

  • Analyzes legacy codebases to identify technical debt and architectural opportunities.
  • Scaffolds a Rust workspace with strict memory safety requirements.
  • Performs iterative refactoring with automated test-driven self-healing.
  • Validates output parity between legacy and new implementations using deterministic seeds.
  • Optimizes performance through data-oriented design and LLVM Profile-Guided Optimization.
  • Generates telemetry reports and interactive infographics documenting the migration metrics.

When to use it

  • When migrating a legacy GitHub repository or local codebase to Rust.
  • When porting complex C++, Fortran, Python, or Java workloads to memory-safe Rust.
  • When designing high-performance Struct-of-Arrays or SIMD architectures in Rust.
  • When optimizing Rust ports using LLVM Profile-Guided Optimization.

Advantages

  • Ensures 100% memory safety by forbidding unsafe code blocks.
  • Provides quantified performance improvements across four distinct optimization stages.
  • Maintains high code quality through strict file size and documentation standards.
  • Delivers transparent, data-backed reporting on the migration process and outcomes.

Usage examples

“Migrate the legacy C++ codebase located at /local/path/to/project to Rust.”
The agent initializes the telemetry ledger, scans the legacy project, benchmarks the baseline, and begins the multi-stage migration process.
“Port my Python data processing library to a high-performance Rust implementation.”
The agent audits the Python code, scaffolds a Rust workspace, implements the core logic, and verifies parity before applying PGO.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/google/migrate-to-rust/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip migrate-to-rust.zip -d .agents/skills

Documentation by Google

Migrate Legacy Codebases to Safe Rust

Act as a Systems Architect, Performance Engineer, and Rust Specialist. Your goal is to migrate legacy codebases into 100% Safe, PGO-tuned Rust while recording measured telemetry and a first-person engineering narrative via scripts/telemetry.py.

Execution Contract & Portability

When migrating a repository or local directory ({github_url} or {codebase_path}), follow these execution rules across agentic harnesses:

  1. Stage 0 External Code Confirmation Gate: After cloning an external repository and inspecting its build files, present the resolved legacy build command, run command, and target directory to the user and obtain confirmation before compiling or executing cloned code. (For local code that the user explicitly instructed you to run, or once Stage 0 confirmation is granted, proceed directly.)

  2. Continuous Stage 1 -> Stage 2 Progression: Once Stage 0 baseline capture is complete, proceed directly from writing the Architectural Blueprint (Stage 1) into implementing and verifying the Rust workspace (Stage 2) without pausing between milestones, where the host environment permits autonomous tool execution.

  3. Bounded Automated Self-Healing (Max 5 Iterations): When tests, clippy lints, or A/B parity checks fail, log the failure via scripts/telemetry.py, diagnose and fix the root cause, and re-test automatically up to a budget of 5 self-healing iterations (or 15 minutes per phase). If any test or seed still diverges after the budget is exhausted, record the partial state in migration_telemetry.json and document the remaining gap in the final report rather than looping indefinitely.

  4. Verification Targets & Definition of Done:

    • #![forbid(unsafe_code)] Rust crate compiles with a target of 0 cargo clippy warnings (any unavoidable exception must be documented).

    • Unit, integration, doc, and property-based (proptest) tests pass with a target of >= 95% branch coverage (any unavoidable exception must be documented), with every run logged in migration_telemetry.json.

    • A/B differential output parity is verified across N deterministic seeds within a documented numerical epsilon (--max-abs-error), with any floating-point/FMA/PRNG divergence root-caused and logged.

    • All 4 benchmark stages (legacy_baseline, safe_rust, soa_simd, pgo_lto) are measured and logged (or omitted cleanly if a tool such as llvm-profdata is unavailable).

    • The interactive HTML infographic (migration_infographic.html) is rendered via scripts/telemetry.py render-infographic.

End-to-End Workflow Checklist

Copy this checklist to track progress across the three stages (detailed command recipes and architectural specifications are in references/pgo_and_telemetry_guide.md):

- [ ] Stage 0: Acquire repo, initialize `migration_telemetry.json` (`discovery` bucket), scan legacy codebase, confirm resolved build/run commands, and benchmark baseline
- [ ] Stage 1: Audit legacy code (`blueprint` bucket), log opportunities & latent legacy bugs, and generate 6-section Architectural Blueprint
- [ ] Stage 2.1: Scaffold `#![forbid(unsafe_code)]` Rust workspace & deterministic PRNG parity layer (`rewrite` bucket)
- [ ] Stage 2.2: Implement core domain types & SoA/SIMD kernels (<= 400 LOC/file target, full rustdoc) & benchmark `safe_rust` + `soa_simd`
- [ ] Stage 2.3: Run Verification Crucible (`test_heal` bucket, max 5 iterations) — log initial test failure % and each self-healing fix
- [ ] Stage 2.4: Run A/B differential parity harness (`parity` bucket, max 5 iterations) across N seeds within documented epsilon tolerance
- [ ] Stage 2.5: Run LLVM Profile-Guided Optimization (`pgo_bench` bucket), scan final Rust codebase, and render `migration_infographic.html`

Stage 0: Repository Acquisition, Telemetry Init & Legacy Baseline

Resolve context parameters from the repository or directory:

ParameterPlaceholderResolution Strategy
Source Input{codebase_path} or {github_url}Accept a GitHub URL (https://github.com/...) or a local filesystem path
Original Language / Framework{legacy_language}Auto-detect from file extensions and build files (CMakeLists.txt, Makefile, meson.build, pyproject.toml, pom.xml, *.f90, *.cpp)
Baseline Run Command{baseline_run_command}Identify from README.md, CI workflows (.github/workflows/*.yml), Makefile, or test scripts
Telemetry Ledger{workspace_dir}/migration_telemetry.jsonInitialized via scripts/telemetry.py init at the start of Stage 0
Stage 0 Execution Steps
  1. Clone Repository (if GitHub URL): Choose a clean local directory (default to ~/rust_migrations/{repo_name}, or inside the current workspace if requested) and run git clone {github_url} ~/rust_migrations/{repo_name}.

  2. Initialize Telemetry & Scan Legacy Codebase: Run scripts/telemetry.py init --telemetry "{workspace_dir}/migration_telemetry.json" --project-name "{project_name}" --legacy-lang "{legacy_language}". Start the discovery bucket and run scripts/telemetry.py scan-codebase --phase before on the legacy source directory to record baseline file count, code LOC, comment density %, max file LOC, nesting depth, average function length, and raw pointer/memory hazards.

  3. Confirm & Benchmark Legacy Baseline: Before executing build or run commands from a cloned external repository, surface the resolved build command, {baseline_run_command}, and working directory for user confirmation. Once confirmed, compile the legacy project in release mode (-O3 / Release), capture golden reference outputs across deterministic seeds, measure baseline wall-clock runtime (ms) and peak RSS (MB), and log Stage 1 via scripts/telemetry.py log-benchmark --stage legacy_baseline.


Stage 1: Deep Audit, Opportunity Discovery & Architectural Blueprint

Start the blueprint timer bucket (scripts/telemetry.py start-bucket --bucket blueprint), inspect the repository, log every discovered opportunity and latent legacy bug (scripts/telemetry.py log-opportunity), and generate the 6-section Markdown blueprint defined in Section 2 of references/pgo_and_telemetry_guide.md.

Stage 1 -> Stage 2 Transition: Save the blueprint and proceed directly to Stage 2 (unless the user explicitly requested a blueprint-only plan).


Stage 2: Phased Safe Rust Implementation, Self-Healing, PGO & Infographic

Follow the command recipes and core engineering standards in references/pgo_and_telemetry_guide.md for each step:

Step 1: Scaffold Safe Rust Workspace & Port Modules (rewrite Bucket)
  1. Start the rewrite timer bucket (scripts/telemetry.py start-bucket --bucket rewrite).

  2. Initialize the Rust workspace with #![forbid(unsafe_code)] in src/lib.rs and src/main.rs.

  3. Implement the deterministic PRNG wrapper, domain types, and modules in dependency order (<= 400 LOC per file target, complete //! and /// rustdoc with runnable doc-tests).

  4. Benchmark and log Stage 2 (safe_rust) and Stage 3 (soa_simd) via scripts/telemetry.py log-benchmark.

Step 2: The Verification Crucible — Test, Fail, Diagnose & Fix (test_heal Bucket)
  1. Start the test_heal timer bucket (scripts/telemetry.py start-bucket --bucket test_heal).

  2. Write unit tests, runnable doc-tests, and proptest boundary tests.

  3. Run cargo test --all-targets, cargo test --doc, and cargo clippy --all-targets.

  4. Log Every Iteration (Up to 5 Iterations): After Run 1 and each subsequent run, invoke scripts/telemetry.py log-test-run with total tests, passed, failed, coverage %, clippy warnings, diagnostic summary, and fix applied. Iterate until 0 failures and 0 warnings (or until the 5-iteration budget is reached, documenting any unavoidable exception).

Step 3: A/B Differential Output Parity (parity Bucket)
  1. Start the parity timer bucket (scripts/telemetry.py start-bucket --bucket parity).

  2. Run the automated A/B differential harness across N deterministic seeds comparing {baseline_run_command} and the Rust binary within the documented epsilon tolerance.

  3. Log each parity iteration via scripts/telemetry.py log-parity-run. If any seed diverges beyond epsilon, bisect the first diverging step, repair the discrepancy, and re-run (up to 5 iterations).

Step 4: Profile-Guided Optimization (PGO) & Final Benchmarks (pgo_bench Bucket)
  1. Start the pgo_bench timer bucket (scripts/telemetry.py start-bucket --bucket pgo_bench).

  2. Execute the LLVM PGO workflow in references/pgo_and_telemetry_guide.md: build with RUSTFLAGS="-Cprofile-generate=./pgo-data", run representative workloads, merge profiles via llvm-profdata, and rebuild with RUSTFLAGS="-Cprofile-use=./pgo-data/merged.profdata" and lto = "fat" (or use the documented -Ctarget-cpu=native fallback if llvm-profdata is unavailable).

  3. Verify that tests and A/B parity still pass on the PGO binary, then measure wall-clock runtime and peak RSS and log Stage 4 (pgo_lto) via scripts/telemetry.py log-benchmark --stage pgo_lto.

Step 5: Final Census, First-Person AI Story & Visual Infographic
  1. Run scripts/telemetry.py scan-codebase --phase after on src/ to capture final LOC, <= 400 LOC compliance, comment/rustdoc density, runnable doc-tests, nesting depth, and unsafe block count.

  2. Log a Before vs. After Code Spotlight (scripts/telemetry.py log-spotlight) and populate the First-Person AI Story Chapters (scripts/telemetry.py set-story).

  3. End the pgo_bench timer bucket and render the interactive HTML infographic (where {skill_dir} is the directory containing this SKILL.md):

    python3 "{skill_dir}/scripts/telemetry.py" render-infographic \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --out "{output_dir}/migration_infographic.html" \
      --scope-summary "{short_summary_of_ported_modules}"
  4. Output a concise executive summary referencing the generated migration_infographic.html report and key measured before/after metrics.


Bundled Resources

Files

references/pgo_and_telemetry_guide.md

Engineering Standards, Blueprint Spec, PGO Pipeline & Telemetry Reference

This reference provides the core engineering standards, 6-section Architectural Blueprint specification, exact command recipes for recording continuous migration telemetry via scripts/telemetry.py, and the LLVM Profile-Guided Optimization (PGO) pipeline.

Table of Contents

  • 1. Core Engineering & Verification Standards: Lines 33-102

  • 2. Stage 1 Architectural Blueprint Specification (6 Sections): Lines 104-141

  • 3. Continuous Telemetry Lifecycle (scripts/telemetry.py): Lines 143-281

    • Step A: Initialize Telemetry & Scan Legacy Codebase (discovery Bucket): Lines 150-183

    • Step B: Log Opportunities & Latent Legacy Bugs (blueprint Bucket): Lines 184-208

    • Step C: Safe Rust Rewrite & Modularization (rewrite Bucket): Lines 209-224

    • Step D: Log Every Test Run & Self-Healing Fix (test_heal Bucket): Lines 225-251

    • Step E: Log A/B Differential Parity Iterations (parity Bucket): Lines 252-281

  • 4. Profile-Guided Optimization (PGO) Workflow (pgo_bench Bucket): Lines 283-361

  • 5. Final Census, First-Person Story & Infographic Generation: Lines 363-415


1. Core Engineering & Verification Standards

Every architectural decision in Stage 1 and every module implemented in Stage 2 should follow these seven engineering objectives:

1.1 100% Memory Safety (#![forbid(unsafe_code)])
  • Place #![forbid(unsafe_code)] at the crate root (src/lib.rs and src/main.rs) so the compiler rejects unsafe blocks, raw pointer dereferences, or unchecked indexing at compile time. Replace legacy raw pointers, manual malloc/new/free calls, and mutable globals with safe ownership, slices, and strong types (0 unsafe blocks).

1.2 4-Stage Performance Staircase & PGO
  • Track and benchmark performance across four explicit checkpoints so the contribution of each optimization technique is isolated and quantified:

    1. Legacy Baseline (legacy_baseline): Original implementation (1.0x).

    2. Initial Safe Rust (safe_rust): Idiomatic safe port with zero hot-loop heap allocations.

    3. Data-Oriented SoA & SIMD (soa_simd): Struct-of-Arrays cache-aligned memory layouts, pre-allocated workspace arenas, and auto-vectorization.

    4. Profile-Guided Optimization (pgo_lto): Instrumented binary profiled on representative workloads (-Cprofile-generate -> llvm-profdata merge -> -Cprofile-use + lto = "fat" + codegen-units = 1).

1.3 API, Call-Site & Cognitive Simplification
  • Audit legacy convoluted call trees, deep nesting, out-parameters, and global mutable state.

  • Reduce average function length and maximum nesting depth by decomposing complex imperative loops into composable iterators, builders, and strongly typed domain methods.

1.4 Modular Rebalancing & File Hygiene (<= 400 LOC)
  • Keep individual source files focused and readable: target <= 400 lines of code (LOC) per file (hard ceiling: 600 LOC) by decomposing monolithic legacy files into cohesive, single-responsibility sub-modules.

1.5 Comprehensive Documentation & Comment Expansion (+X% Docs)
  • Document every public module (//!), struct, trait, and function (///) with rustdoc covering purpose, invariants, units/coordinate frames, # Errors, equations, and runnable doc-tests.

1.6 Bounded Verification Crucible & Self-Healing Telemetry
  • Target >= 95% branch coverage with unit, integration, doc, and property-based tests (proptest).

  • Log every test run transparently (up to 5 self-healing iterations): when initial test runs fail (X% failed), record the failure count, root cause, and self-healing fix via scripts/telemetry.py log-test-run before rebuilding and re-testing. If any failures remain after 5 iterations, document the remaining failures honestly in telemetry rather than looping indefinitely.

1.7 Numerical / Epsilon Parity & Determinism
  • Execute both the legacy baseline and the Rust binary side-by-side across N deterministic seeds. Log every parity check (scripts/telemetry.py log-parity-run), bisect and repair any algorithmic or PRNG discrepancy, and verify parity within a documented epsilon tolerance (--max-abs-error), accounting for hardware FMA or extended-precision differences where applicable.


2. Stage 1 Architectural Blueprint Specification (6 Sections)

Structure the Stage 1 Markdown blueprint into these six sections:

  1. Codebase Audit, Legacy Census & Latent Bugs Discovered:

    • Present the automated baseline census from migration_telemetry.json (total LOC, comment %, max file LOC, nesting depth, memory/state hazards).

    • Highlight Latent Bugs & Undefined Behaviors uncovered in the original code (e.g., uninitialized memory, unchecked division by zero, float precision loss, off-by-one boundary reads) with exact file and line references.

  2. Target Safe Rust Architecture & Module Graph:

    • Proposed Rust crate/module layout (#![forbid(unsafe_code)], every file <= 400 LOC target).

    • Mapping Table showing where legacy files, classes, and functions relocate:

      Legacy File & Symbol ({legacy_language})Target Rust Module & Type/FnTransformation & LOC Target
      path/to/legacy.cpp::SimEnginesrc/engine/stepper.rs::SimStepperAoS to SoA; #![forbid(unsafe_code)]; <= 400 LOC
  3. API Ergonomics & Call-Site Modernization:

    • Concrete Before ({legacy_language}) / After (Rust) code examples from actual repository call sites showing how legacy calls become clean, type-safe Rust APIs.

  4. Test Harness, Property Fuzzing & Parity Strategy:

    • Plan for unit, doc, and proptest property tests (>= 95% branch coverage target) and golden output comparison across N deterministic seeds within a documented epsilon tolerance.

  5. 4-Stage Benchmarking & PGO Pipeline Plan:

    • Strategy for measuring the 4-stage speedup staircase: legacy_baseline -> safe_rust -> soa_simd -> pgo_lto (LLVM Profile-Guided Optimization + Fat LTO).

  6. Phased Execution Roadmap:

    • Step-by-step milestones for Stage 2 execution plus any Open Questions.


3. Continuous Telemetry Lifecycle (scripts/telemetry.py)

Resolve {skill_dir} as the directory containing the SKILL.md file you loaded. Invoke python3 {skill_dir}/scripts/telemetry.py at each stage transition so every metric is grounded in real measurements rather than post-hoc estimates.

Step A: Initialize Telemetry & Scan Legacy Codebase (discovery Bucket)

Immediately after cloning or locating the legacy repository:

python3 "{skill_dir}/scripts/telemetry.py" init \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --project-name "{project_name}" \
  --legacy-lang "{legacy_language}"

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket discovery

python3 "{skill_dir}/scripts/telemetry.py" scan-codebase \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --phase before \
  --dir "{legacy_src_dir}"

After confirming and running the legacy baseline binary ({baseline_run_command}) under /usr/bin/time -v (or a Python resource/time wrapper), log the baseline benchmark:

python3 "{skill_dir}/scripts/telemetry.py" log-benchmark \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --stage legacy_baseline \
  --label "1. Legacy {legacy_language} Baseline" \
  --wall-time-ms {legacy_ms} \
  --peak-rss-mb {legacy_rss_mb} \
  --notes "Original legacy implementation baseline."
Step B: Log Opportunities & Latent Legacy Bugs (blueprint Bucket)

When transitioning to Stage 1 (Architectural Blueprint):

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket blueprint

For each architectural opportunity, performance bottleneck, memory hazard, or latent bug in the original code discovered during the audit, log it:

python3 "{skill_dir}/scripts/telemetry.py" log-opportunity \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --category latent_bug \
  --title "Uninitialized boundary state on tick 0" \
  --file "src/solver.cpp:142" \
  --description "Edge cells read uninitialized memory when periodic wrapping is disabled."

Valid --category values: latent_bug, performance, safety, hygiene, architecture.

Step C: Safe Rust Rewrite & Modularization (rewrite Bucket)

At the start of Stage 2 implementation:

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket rewrite
  • Place #![forbid(unsafe_code)] at the top of src/lib.rs and src/main.rs so memory safety is enforced by the compiler.

  • Benchmark both the initial idiomatic Safe Rust port (safe_rust) and the Struct-of-Arrays / SIMD / zero-allocation refactor (soa_simd) using log-benchmark.

Step D: Log Every Test Run & Self-Healing Fix (test_heal Bucket)

Initial test failures form the core of Chapter 3 ("The Verification Crucible"). Start the test_heal bucket and log every test execution iteration, including Iteration 1 where X% of tests fail, what caused the failures, and how you fixed them:

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket test_heal

python3 "{skill_dir}/scripts/telemetry.py" log-test-run \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --iteration 1 \
  --total 42 \
  --passed 34 \
  --failed 8 \
  --coverage-pct 83.5 \
  --clippy-warnings 3 \
  --failures-summary "19.0% failed (8/42): boundary reflection off-by-one and extreme seed NaN handling." \
  --fix-applied "Corrected opposite-direction index LUT and added domain validation."

Repeat log-test-run for each rebuild/re-test cycle (up to 5 iterations) targeting --failed 0, --clippy-warnings 0, and --coverage-pct >= 95.0.

Step E: Log A/B Differential Parity Iterations (parity Bucket)

Start the parity bucket and record each side-by-side comparison run across N seeds, including any initial seed divergence and the fix applied:

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket parity

python3 "{skill_dir}/scripts/telemetry.py" log-parity-run \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --iteration 1 \
  --seeds-tested 100 \
  --seeds-passed 96 \
  --max-abs-error "4.2e-4" \
  --divergence-cause "4 seeds drifted beyond 1e-12 epsilon at step 380 due to f32 accumulator rounding." \
  --fix-applied "Promoted reduction accumulator to f64 to match legacy reference precision."

python3 "{skill_dir}/scripts/telemetry.py" log-parity-run \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --iteration 2 \
  --seeds-tested 100 \
  --seeds-passed 100 \
  --max-abs-error "2.1e-14 (<= 1e-12 epsilon)" \
  --divergence-cause "None — 100/100 seeds matched within 1e-12 epsilon." \
  --fix-applied "Verified equivalence across all 100 deterministic seeds."

4. Profile-Guided Optimization (PGO) Workflow (pgo_bench Bucket)

After completing the test and parity verification passes, start the pgo_bench bucket and execute an LLVM Profile-Guided Optimization pass:

python3 "{skill_dir}/scripts/telemetry.py" start-bucket \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --bucket pgo_bench
Step 1: Locate llvm-profdata

Run rustc --print sysroot first, then locate llvm-profdata inside that toolchain path (or check which llvm-profdata):

rustc --print sysroot
Step 2: Build Instrumented Binary (-Cprofile-generate)

Configure Cargo.toml with release LTO settings:

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
panic = "abort"

Compile with profiling instrumentation enabled using a pgo-data directory inside the project workspace:

RUSTFLAGS="-Cprofile-generate=./pgo-data" cargo build --release
Step 3: Execute Representative Profiling Workload

Run the instrumented binary across 3–5 representative seeds/workloads so LLVM records accurate branch probabilities and hot-loop trip counts:

./target/release/{binary_name} {representative_workload_args}
Step 4: Merge Profile Data & Compile Final PGO Binary (-Cprofile-use)
{llvm_profdata_binary} merge -o ./pgo-data/merged.profdata ./pgo-data
RUSTFLAGS="-Cprofile-use=./pgo-data/merged.profdata -Cllvm-args=-pgo-warn-missing-function" cargo build --release

Fallback if llvm-profdata is not installed in the environment: Compile Step 4 with RUSTFLAGS="-C target-cpu=native -C opt-level=3 -C lto=fat -C codegen-units=1" and note the compiler target-cpu + fat-LTO optimization pass in --notes.

Step 5: Benchmark Final PGO Binary & Log Stage 4

Measure wall-clock time and peak RSS of the PGO binary on the exact baseline workload and log pgo_lto:

python3 "{skill_dir}/scripts/telemetry.py" log-benchmark \
  --telemetry "{workspace_dir}/migration_telemetry.json" \
  --stage pgo_lto \
  --label "4. Profile-Guided Optimization (PGO) + Fat LTO" \
  --wall-time-ms {pgo_ms} \
  --peak-rss-mb {pgo_rss_mb} \
  --notes "Profiled on representative workload and recompiled with -Cprofile-use + Fat LTO."

5. Final Census, First-Person Story & Infographic Generation

Once PGO benchmarking is complete:

  1. Scan the final Rust codebase:

    python3 "{skill_dir}/scripts/telemetry.py" scan-codebase \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --phase after \
      --dir "{rust_crate_dir}/src" \
      --coverage-pct {final_coverage_pct} \
      --clippy-warnings 0
  2. Record a Before/After Code Transformation Spotlight:

    python3 "{skill_dir}/scripts/telemetry.py" log-spotlight \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --explanation "How the legacy hot loop was transformed into a documented, zero-allocation Safe Rust kernel." \
      --legacy-file "{legacy_file_path}" \
      --legacy-code "{legacy_snippet}" \
      --rust-file "{rust_file_path}" \
      --rust-code "{rust_snippet}"
  3. Write the First-Person AI Narrative Chapters: Write from the AI's first-person perspective ("I found...", "I analyzed...", "On my first test run, X% of tests failed...", "I fixed...", "At the end I ran PGO..."):

    python3 "{skill_dir}/scripts/telemetry.py" set-story \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --headline "“I inherited a {legacy_lang} codebase, uncovered {N} latent bugs, self-healed through {X}% initial test failures, and delivered a {S}x faster PGO-tuned Safe Rust port.”" \
      --intro "{2-3 sentence executive summary from AI POV}" \
      --ch1-narrative "{Chapter 1: What I found in the legacy codebase & opportunities/bugs discovered}" \
      --ch2-narrative "{Chapter 2: How I reorganized the architecture, capped files <=400 LOC, and added +X% docs}" \
      --ch3-narrative "{Chapter 3: The test crucible — initial failure %, root causes diagnosed, and self-healing fixes}" \
      --ch4-narrative "{Chapter 4: Proving output parity across N seeds}" \
      --ch5-narrative "{Chapter 5: The 4-stage speedup staircase culminating in PGO}"
  4. End the final timer bucket and render the HTML Infographic:

    python3 "{skill_dir}/scripts/telemetry.py" end-bucket \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --bucket pgo_bench
    
    python3 "{skill_dir}/scripts/telemetry.py" render-infographic \
      --telemetry "{workspace_dir}/migration_telemetry.json" \
      --out "{output_dir}/migration_infographic.html" \
      --scope-summary "{short_summary_of_ported_scope}"

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

Security

What our scanner noticed· Low risk

  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Google
Publisher
Google (Official)
Source
google/skills · skills/developers/migrate-to-rust · commit 2194d3b
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download migrate-to-rust.zip