How navigraph/cargo-msfs works
Project Type and Purpose
• Cargo MSFS is a command-line utility (Rust) for managing and building WASM modules targeted at Microsoft Flight Simulator (versions 2020 & 2024).
• Its primary functions are: installing/removing/updating the MSFS SDK, building Rust crates into WASM (invoking external tools), and reporting installed SDK info.
File Structure
• Top-level files:
• action.yml, .github/workflows/test.yml, Dockerfile → CI/CD and containerization.
• Cargo.toml → Rust project configuration & dependencies.
• README.md, LICENSE.md → documentation.
• src/main.rs → entry point and CLI parser.
• src/sdk.rs → SDK management logic (install/remove/update/info).
• No explicit “frontend” vs “backend” layers—this is a single binary with internal modules.
README for Insights
• External dependencies:
• Clang 17 (must be present on host).
• wasm-opt (invoked automatically during build).
• Command hierarchy: install, remove, update, build, info.
• Flags: --in-folder, --out-wasm.
Main Components to Highlight
a. CLI Interface (main.rs)
• Arg parsing (StructOpt/clap).
• Dispatch to command handlers.
b. Command Dispatcher / Controller
• Implements the Command pattern—maps user commands to internal operations.
c. SDK Manager Module (sdk.rs)
• install(), remove(), update(), info() sub-functions.
• Handles downloads/unpacks, file-system operations (e.g., where SDKs live).
d. Build Engine
• Orchestrates:
• Invoking cargo build --release with WASM target.
• Invoking wasm-opt for post-processing.
• Accepts input folder & output path.
e. External Tools / Dependencies
• Clang 17 (system tool)
• wasm-opt (from Binaryen)
• Cargo/Rust toolchain
f. File System / SDK Storage
• Directory where MSFS SDKs are installed.
• Crate source & output WASM file paths.
g. CI/CD & Containerization (optional)
• GitHub Actions workflow.
• Dockerfile for packaging/testing.
Relationships & Data Flow
• User → CLI Interface (stdin/args)
• CLI → Command Dispatcher →
• If SDK command: → SDK Manager → File System / Network (download)
• If build command: → Build Engine → External Tools → File System
• If info: → SDK Manager → Read File System → CLI (stdout)
Architectural Patterns & Design Principles
• Command Pattern: each Cargo MSFS subcommand is encapsulated in its own handler.
• Single Responsibility: main.rs only parses and routes commands; sdk.rs only manages SDK.
• Modular Design: future commands (e.g., packaging) can be added as new modules.