blob: 330c1cb9d0be545748713ac27a0450639294ea22 [file] [edit]
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:dart2wasm/dev/compile.dart';
Future<void> main(List<String> args) async {
Uri? platformPath;
Uri? librariesSpecPath;
final rest = <String>[];
for (final arg in args) {
if (arg.startsWith('--platform=')) {
platformPath = Uri.base.resolveUri(
Uri.file(arg.substring('--platform='.length)),
);
} else if (arg.startsWith('--libraries-spec=')) {
librariesSpecPath = Uri.base.resolveUri(
Uri.file(arg.substring('--libraries-spec='.length)),
);
} else {
rest.add(arg);
}
}
if (rest.length != 2 || !rest[1].endsWith('.wasm')) {
stderr.writeln(
'Usage: dart2wasm_dev.dart [options] <input.dart> <output.wasm>',
);
exit(64);
}
final mainUri = Uri.base.resolveUri(Uri.file(rest[0]));
final outputPath = rest[1];
final modules = await compile(
mainUri,
platformPath: platformPath,
librariesSpecPath: librariesSpecPath,
);
final prefix = outputPath.substring(0, outputPath.length - '.wasm'.length);
for (var i = 0; i < modules.length; i++) {
final modulePath = i == 0 ? outputPath : '${prefix}_module$i.wasm';
File(modulePath).writeAsBytesSync(modules[i]);
}
}