• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dart-lang / wasm / 4775430471

23 Apr 2023 12:22AM UTC coverage: 90.827%. Remained the same
4775430471

push

github

GitHub
Fix formatting (#142)

604 of 665 relevant lines covered (90.83%)

13.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.88
/wasm/lib/src/wasmer_locator.dart
1
// Copyright (c) 2020, the Dart project authors.  Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4

5
import 'dart:ffi';
6
import 'dart:io';
7

8
/// Attempts to locate the Wasmer dynamic library.
9
///
10
/// Throws [WasmLocatorError] if the dynamic library could not be found.
11
DynamicLibrary loadWasmerDynamicLibrary() {
16✔
12
  String locate(String libName) {
16✔
13
    final dir = '$_wasmToolDir$libName';
16✔
14
    final value = _packageRootUri(Platform.script.resolve('./')) ??
48✔
15
        _packageRootUri(Directory.current.uri);
48✔
16
    if (value != null) {
17
      return value.resolve(dir).toFilePath();
32✔
18
    } else {
19
      throw WasmLocatorError(
×
20
        'Wasm library not found. Did you run `$invocationString`?',
×
21
      );
22
    }
23
  }
24

25
  if (Platform.isIOS) {
16✔
26
    return DynamicLibrary.process();
×
27
  } else if (Platform.isMacOS) {
16✔
28
    return DynamicLibrary.open(locate(appleLib));
×
29
  } else if (Platform.isWindows) {
16✔
30
    return DynamicLibrary.open(locate(windowsLib));
×
31
  } else if (Platform.isLinux) {
16✔
32
    return DynamicLibrary.open(locate(linuxLib));
32✔
33
  } else if (Platform.isAndroid) {
×
34
    return DynamicLibrary.open(linuxLib);
×
35
  } else if (Platform.isFuchsia) {
×
36
    throw WasmLocatorError(
×
37
      'Wasm is currently not supported on Fuchsia.',
38
    );
39
  } else {
40
    throw WasmLocatorError(
×
41
      'Wasm is currently not supported on this platform.',
42
    );
43
  }
44
}
45

46
/// This error is thrown when the dynamic library could not be found.
47
class WasmLocatorError extends Error {
48
  final String message;
49

50
  WasmLocatorError(
×
51
    this.message,
52
  );
53

54
  @override
×
55
  String toString() => 'WasmLocatorError: $message';
×
56
}
57

58
/// The command that can be used to set up this package.
59
const invocationString = 'dart run wasm:setup';
60

61
/// The expected name of the Wasmer library when compiled for Apple devices.
62
const appleLib = 'libwasmer.dylib';
63

64
/// The expected name of the Wasmer library when compiled for Linux devices.
65
const linuxLib = 'libwasmer.so';
66

67
/// The expected name of the Wasmer library when compiled for Windows devices.
68
const windowsLib = 'wasmer.dll';
69

70
/// Returns the uri representing the target output directory of generated
71
/// dynamic libraries.
72
Uri libBuildOutDir(Uri root) {
×
73
  final pkgRoot = _packageRootUri(root);
×
74
  if (pkgRoot == null) {
75
    throw ArgumentError('Could not find "$_pkgConfigFile" within "$root".');
×
76
  }
77
  return pkgRoot.resolve(_wasmToolDir);
×
78
}
79

80
const _wasmToolDir = '.dart_tool/wasm/';
81

82
const _pkgConfigFile = '.dart_tool/package_config.json';
83

84
Uri? _packageRootUri(Uri root) {
16✔
85
  do {
86
    if (FileSystemEntity.isFileSync(
16✔
87
      root.resolve(_pkgConfigFile).toFilePath(),
32✔
88
    )) {
89
      return root;
90
    }
91
  } while (root != (root = root.resolve('..')));
32✔
92
  return null;
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc