Files
Synapse/app/rust_builder/cargokit/build_tool/lib/src/cargo.dart
T
dasemuandClaude Opus 5.5 df42d4010f feat(app): Flutter outliner with journals, page view and timeline
Logseq-like outliner (render/edit Markdown per block, Enter/Tab/Shift-Tab,
backspace merge, arrow navigation, drag to reorder, collapse, [[ # ((
autocomplete, TODO/DONE), journals feed with prev/next links, page view with
linked references and related panel, virtualised CustomPainter timeline,
Ctrl+K quick switcher, sidebar with recents, light/dark theme with bundled
Inter, Noto Serif and Source Code Pro. Edits are optimistic and serialised
to the core through one write queue. Cargokit builds synapse-ffi; its build
tool is patched to use the library name (synapse_ffi) of hyphenated crates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 03:59:42 +02:00

52 lines
1.5 KiB
Dart

/// This is copied from Cargokit (which is the official way to use it currently)
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:toml/toml.dart';
class ManifestException {
ManifestException(this.message, {required this.fileName});
final String? fileName;
final String message;
@override
String toString() {
if (fileName != null) {
return 'Failed to parse package manifest at $fileName: $message';
} else {
return 'Failed to parse package manifest: $message';
}
}
}
class CrateInfo {
CrateInfo({required this.packageName});
final String packageName;
/// Library (artifact) name: cargo turns `-` in the package name into `_`.
String get libName => packageName.replaceAll('-', '_');
static CrateInfo parseManifest(String manifest, {final String? fileName}) {
final toml = TomlDocument.parse(manifest);
final package = toml.toMap()['package'];
if (package == null) {
throw ManifestException('Missing package section', fileName: fileName);
}
final name = package['name'];
if (name == null) {
throw ManifestException('Missing package name', fileName: fileName);
}
return CrateInfo(packageName: name);
}
static CrateInfo load(String manifestDir) {
final manifestFile = File(path.join(manifestDir, 'Cargo.toml'));
final manifest = manifestFile.readAsStringSync();
return parseManifest(manifest, fileName: manifestFile.path);
}
}