tdlib2
Dart bindings for TDLib with native prebuilts and source-build fallback.
This repository is a continuation of:
The packages were combined here and rewritten in some areas.
Contents
- Features
- Install
- Quick start
- Prebuilt binaries
- Build from source
- Workflow and manifest generation
- Development
- Notes
Features
- generated TDLib schema bindings
- FFI client for
tdjson - native prebuilt resolution via
native_prebuilt - source fallback for local and platform-specific builds
- support for Android, Linux, Windows, macOS, and iOS
Install
dependencies:
tdlib2: ^1.8.64
Quick start
import 'package:tdlib2/td_api.dart' as td;
import 'package:tdlib2/td_client.dart';
Future<void> main() async {
final client = Client.create();
client.updates.listen((event) {
print(event.toJson());
});
await client.initialize();
final result = client.execute<td.Ok>(
td.SetLogVerbosityLevel(newVerbosityLevel: 0),
);
print(result.toJson());
}
Prebuilt binaries
Prebuilt native libraries are downloaded from GitHub Releases.
Supported release targets:
android-arm64linux-x64windows-x64macos-arm64ios-arm64
Release tags use the form:
tdlib-vX.Y.Z
Build from source
To force a source build instead of using the packaged prebuilt, add this to the consuming package’s pubspec.yaml:
hooks:
user_defines:
tdlib2:
build_from_source: true
That is useful when developing TDLib itself or when you need a local rebuild for a platform.
Workflow and manifest generation
This package uses native_prebuilt to generate release metadata and GitHub Actions scaffolding.
Hook wiring
hook/build.dart stays simple:
Future<void> main(List<String> args) {
return nativePrebuiltBuild(args);
}
native_prebuilt automatically loads native_prebuilt.yaml, and if native_prebuilt.lock.yaml is present it overlays the checked-in release hashes. Use project.copyWith(...) only if you are composing a NativeProject manually and need to override its prebuilts yourself.
Generated lock file
native_prebuilt.lock.yaml is generated by the CLI and checked in. Regenerate it after a release once the release assets exist:
dart run native_prebuilt manifest update \
--config native_prebuilt.yaml \
--output native_prebuilt.lock.yaml \
--tag tdlib-vX.Y.Z
The command reads native_prebuilt.yaml, hashes the built libraries/release assets, and rewrites native_prebuilt.lock.yaml. Commit that file on main; the build hook picks it up automatically.
Workflow templates
dart run native_prebuilt workflow init
To generate GitLab templates for selected platforms:
dart run native_prebuilt workflow init --gitlab --platform linux,windows
workflow init writes the GitHub workflow set by default, or the GitLab set when --gitlab is passed. GitLab outputs can be filtered with --platform.
See the native_prebuilt README for the full YAML build-step reference. For editor validation, point YAML schemas at ../native_prebuilt/schema/native_prebuilt.schema.json.
The native asset is consumed by lib/src/client/platform/io/tdjson_native.dart, which uses @Native bindings rather than DynamicLibrary.open().
Run the Prebuilt workflow manually for a release tag after the manifest commit lands on main; it now takes the release tag as a workflow-dispatch input instead of rebuilding from a pushed tag.
The recipe file uses Liquid templates for paths and environment values, for example:
source_directory: "{{ source.path }}/example/android"
build_directory: "{{ work }}/build"
CMAKE_TOOLCHAIN_FILE: "{{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake"
Development
dart pub get
dart test
dart analyze
Notes
- This repository is intentionally clean and does not preserve old fork history in the README.
archiveSha256andpayloadSha256should always be generated by the CLI, never edited by hand.