resolveRustLibPath function

Future<String> resolveRustLibPath({
  1. bool release = true,
  2. String? checkoutRelativeRustDir,
})

Resolves a Rust cdylib path: local build output → cargo build → precompiled download (Cargokit GitHub releases).

Implementation

Future<String> resolveRustLibPath({
  bool release = true,
  String? checkoutRelativeRustDir,
}) async {
  final existing = await _findExistingCandidate(
    checkoutRelativeRustDir: checkoutRelativeRustDir,
  );
  if (existing != null) return existing;

  final rustDir = checkoutRelativeRustDir ?? checkoutRustDir;
  if (await _cargoAvailable() && Directory(rustDir).existsSync()) {
    return _cargoBuild(rustDir: rustDir, release: release);
  }

  final downloaded = await downloadPrecompiledRustLib(
    manifestDir: Directory(rustDir).existsSync() ? rustDir : rustManifestDir(),
  );
  if (downloaded != null) {
    return p.normalize(File(downloaded).absolute.path);
  }

  throw StateError(
    'No Rust library found. Install Rust and run `cargo build` in $rustDir, '
    'or ensure precompiled binaries are published for this plugin version '
    '(see rust_lib_flutter_alacritty docs/PRECOMPILED_BINARIES.md).',
  );
}