Files
sdk/samples/ffi/http/lib/dylib_utils.dart
T
Liam Appelbe baaf5e1116 [ffi] Reland the iNativeCallable.listener example test.
The documentation changes already relanded. This is just relanding the
example.

Patchset 1 is a pure reland. Other patchsets are fixes.

Original CL:
https://dart-review.googlesource.com/c/sdk/+/326580

Change-Id: I04d24d63f08a351db7a6e43f331904274e28e2d5
Bug: https://github.com/dart-lang/sdk/issues/53435
TEST=samples/ffi/http/test/http_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328681
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-09-28 22:41:42 +00:00

21 lines
832 B
Dart

// Copyright (c) 2023, 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:ffi';
import 'dart:io' show File, Platform;
Uri dylibPath(String name, Uri path) {
if (Platform.isLinux || Platform.isAndroid || Platform.isFuchsia) {
return path.resolve("lib$name.so");
}
if (Platform.isMacOS) return path.resolve("lib$name.dylib");
if (Platform.isWindows) return path.resolve("$name.dll");
throw Exception("Platform not implemented");
}
DynamicLibrary dlopenPlatformSpecific(String name, {List<Uri>? paths}) =>
DynamicLibrary.open((paths ?? [Uri()])
.map((path) => dylibPath(name, path).toFilePath())
.firstWhere((lib) => File(lib).existsSync()));