buildAndRun static method

Future<void> buildAndRun(
  1. String serverDir
)

Build and run the Rust server with inherited stdio.

Implementation

static Future<void> buildAndRun(String serverDir) async {
  final Map<String, String> env = {
    'RUSTFLAGS': '',
    'RUST_BACKTRACE': '0',
  };

  Logger.info(_tag, 'Building...');
  final int buildExit = await Shell.runInteractive(
    'cargo',
    ['build'],
    workingDirectory: serverDir,
    environment: env,
  );
  if (buildExit != 0) {
    Logger.error('Build failed.');
    exit(1);
  }
  Logger.info(_tag, 'Build succeeded.');

  Logger.info(_tag, 'Starting...');
  final int runExit = await Shell.runInteractive(
    'cargo',
    ['run'],
    workingDirectory: serverDir,
    environment: env,
  );
  if (runExit != 0) {
    Logger.info(_tag, 'Server exited with code $runExit.');
  }
}