Files
IKAR/tool/prepare_plugin_runtime.dart
T

72 lines
2.4 KiB
Dart

import 'dart:convert';
import 'dart:io';
Future<void> main() async {
final root = Directory.current;
final configFile = File('${root.path}/.dart_tool/package_config.json');
final config = jsonDecode(await configFile.readAsString()) as Map;
final package = (config['packages'] as List).cast<Map>().singleWhere(
(entry) => entry['name'] == 'fjs',
);
final packageRoot = configFile.uri
.resolve(package['rootUri'] as String)
.toFilePath();
final output = Directory('${root.path}/build/native-tests/fjs');
await output.create(recursive: true);
await File(
'${output.path}/cargokit_options.yaml',
).writeAsString('precompiled_binaries_mode: disabled\n');
final flutterRoot =
Platform.environment['FLUTTER_ROOT'] ??
File(Platform.resolvedExecutable).parent.parent.parent.parent.parent.path;
if (Platform.isMacOS) {
final process = await Process.start('cargo', [
'build',
'--locked',
'--manifest-path',
'$packageRoot/libfjs/Cargo.toml',
'--target-dir',
'${output.path}/temp',
], mode: ProcessStartMode.inheritStdio);
exitCode = await process.exitCode;
if (exitCode != 0) return;
await File(
'${output.path}/temp/debug/libfjs.dylib',
).copy('${output.path}/libfjs.dylib');
return;
}
final target = Platform.isWindows
? 'windows-x64'
: Platform.isLinux
? 'linux-x64'
: throw UnsupportedError('Unsupported test host');
final script =
'$packageRoot/cargokit/run_build_tool.${Platform.isWindows ? 'cmd' : 'sh'}';
final process = await Process.start(
script,
['build-cmake'],
runInShell: Platform.isWindows,
mode: ProcessStartMode.inheritStdio,
environment: {
'FLUTTER_ROOT': flutterRoot,
'CARGOKIT_CONFIGURATION': 'Release',
'CARGOKIT_MANIFEST_DIR': '$packageRoot/libfjs',
'CARGOKIT_TARGET_TEMP_DIR': '${output.path}/temp',
'CARGOKIT_OUTPUT_DIR': output.path,
'CARGOKIT_TARGET_PLATFORM': target,
'CARGOKIT_TOOL_TEMP_DIR': '${output.path}/tool',
'CARGOKIT_ROOT_PROJECT_DIR': output.path,
},
);
exitCode = await process.exitCode;
final library = File(
'${output.path}/${Platform.isWindows ? 'fjs.dll' : 'libfjs.so'}',
);
if (!library.existsSync()) {
stderr.writeln(
'Native plugin library was not produced. Check Rust and libclang installation.',
);
exitCode = 1;
}
}