run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<bool> run() async {
var ok = true;
void report(bool pass, String message, {bool warnOnly = false}) {
final tag = pass ? 'ok ' : (warnOnly ? 'warn' : 'FAIL');
if (!pass && !warnOnly) ok = false;
print('$tag $message');
}
// Tools register.
final tools = buildTools();
report(
tools.length == allToolNames.length,
'${tools.length} tools registered',
);
const limits = McpLimits();
const dart = 'int main(List a){ print("ok"); return 1; }';
final parse = await computeTool(parseToolName, {
'language': 'dart',
'source': dart,
}, limits);
report(parse['isError'] != true, 'apollovm.parse');
final exec = await computeTool(executeToolName, {
'language': 'dart',
'source': dart,
}, limits);
report(exec['isError'] != true, 'apollovm.execute');
final translate = await computeTool(translateToolName, {
'from': 'dart',
'to': 'python',
'source': dart,
}, limits);
report(translate['isError'] != true, 'apollovm.translate');
final wasm = await computeTool(wasmToolName, {
'language': 'dart',
'source': 'int run(int a, int b){ return a + b; }',
}, limits);
report(wasm['isError'] != true, 'apollovm.wasm (compile)');
// Optional: the native runtime needed to *run* compiled Wasm. It ships
// separately (`package:apollovm_wasm`) so that `package:apollovm` stays
// free of a native/FFI toolchain; without it Wasm still compiles.
try {
final runtime = _wasmRuntimeSupported();
report(
runtime,
runtime
? 'native Wasm runtime available (apollovm.wasm modules are runnable)'
: 'native Wasm runtime missing — apollovm.wasm still COMPILES; '
'running compiled modules needs `package:apollovm_wasm` '
'(call `registerApolloVMWasmRuntime()`) and '
'`dart run wasm_run:setup`',
warnOnly: !runtime,
);
} catch (_) {
report(
false,
'native Wasm runtime missing — add `package:apollovm_wasm` and call '
'`registerApolloVMWasmRuntime()` to run compiled modules',
warnOnly: true,
);
}
print(ok ? '\nAll checks passed.' : '\nSome checks failed.');
return ok;
}