Skip to content

Commit 85f5b55

Browse files
committed
Fix binary ABI detection.
1 parent 357db25 commit 85f5b55

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Use of this source code is governed by a BSD-style license that can be
2+
// found in the LICENSE file.
3+
4+
import 'dart:ffi';
5+
import 'dart:io';
6+
7+
/// Get executable root directory
8+
String binRootDir() {
9+
final Directory cacheRoot;
10+
if (Platform.resolvedExecutable.contains('flutter_tester')) {
11+
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent;
12+
} else if (Platform.resolvedExecutable.contains('dart')) {
13+
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent;
14+
} else {
15+
throw Exception('Unknown executable: ${Platform.resolvedExecutable}');
16+
}
17+
final String platform;
18+
if (Platform.isWindows) {
19+
if (Abi.current() == Abi.windowsX64) {
20+
platform = 'windows-x64';
21+
} else if (Abi.current() == Abi.windowsArm64) {
22+
platform = 'windows-arm64';
23+
} else {
24+
throw Exception('Unsupported ABI: ${Abi.current()}');
25+
}
26+
} else if (Platform.isMacOS) {
27+
platform = 'darwin-x64';
28+
} else if (Platform.isLinux) {
29+
if (Abi.current() == Abi.linuxX64) {
30+
platform = 'linux-x64';
31+
} else if (Abi.current() == Abi.linuxArm64) {
32+
platform = 'linux-arm64';
33+
} else {
34+
throw Exception('Unsupported ABI: ${Abi.current()}');
35+
}
36+
} else {
37+
throw Exception('Cannot identify platform ${Platform.localeName}');
38+
}
39+
final String output = '${cacheRoot.path}/artifacts/engine/$platform/';
40+
if (!Directory(output).existsSync()) {
41+
throw Exception('Could not find directory ${output} for executables');
42+
}
43+
return output;
44+
}

packages/vector_graphics_compiler/lib/src/_initialize_path_ops_io.dart

+3-16
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,24 @@
33
// found in the LICENSE file.
44

55
import 'dart:io';
6+
7+
import '_bin_root.dart';
68
import 'svg/path_ops.dart';
79

810
/// Look up the location of the pathops from flutter's artifact cache.
911
bool initializePathOpsFromFlutterCache() {
10-
final Directory cacheRoot;
11-
if (Platform.resolvedExecutable.contains('flutter_tester')) {
12-
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent;
13-
} else if (Platform.resolvedExecutable.contains('dart')) {
14-
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent;
15-
} else {
16-
print('Unknown executable: ${Platform.resolvedExecutable}');
17-
return false;
18-
}
19-
20-
final String platform;
2112
final String executable;
2213
if (Platform.isWindows) {
23-
platform = 'windows-x64';
2414
executable = 'path_ops.dll';
2515
} else if (Platform.isMacOS) {
26-
platform = 'darwin-x64';
2716
executable = 'libpath_ops.dylib';
2817
} else if (Platform.isLinux) {
29-
platform = 'linux-x64';
3018
executable = 'libpath_ops.so';
3119
} else {
3220
print('path_ops not supported on ${Platform.localeName}');
3321
return false;
3422
}
35-
final String pathops =
36-
'${cacheRoot.path}/artifacts/engine/$platform/$executable';
23+
final String pathops = '${binRootDir()}/$executable';
3724
if (!File(pathops).existsSync()) {
3825
print('Could not locate libpathops at $pathops.');
3926
print('Ensure you are on a supported version of flutter and then run ');

packages/vector_graphics_compiler/lib/src/_initialize_tessellator_io.dart

+3-16
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,24 @@
33
// found in the LICENSE file.
44

55
import 'dart:io';
6+
7+
import '_bin_root.dart';
68
import 'svg/tessellator.dart';
79

810
/// Look up the location of the tessellator from flutter's artifact cache.
911
bool initializeTessellatorFromFlutterCache() {
10-
final Directory cacheRoot;
11-
if (Platform.resolvedExecutable.contains('flutter_tester')) {
12-
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent;
13-
} else if (Platform.resolvedExecutable.contains('dart')) {
14-
cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent;
15-
} else {
16-
print('Unknown executable: ${Platform.resolvedExecutable}');
17-
return false;
18-
}
19-
20-
final String platform;
2112
final String executable;
2213
if (Platform.isWindows) {
23-
platform = 'windows-x64';
2414
executable = 'libtessellator.dll';
2515
} else if (Platform.isMacOS) {
26-
platform = 'darwin-x64';
2716
executable = 'libtessellator.dylib';
2817
} else if (Platform.isLinux) {
29-
platform = 'linux-x64';
3018
executable = 'libtessellator.so';
3119
} else {
3220
print('Tesselation not supported on ${Platform.localeName}');
3321
return false;
3422
}
35-
final String tessellator =
36-
'${cacheRoot.path}/artifacts/engine/$platform/$executable';
23+
final String tessellator = '${binRootDir()}/$executable';
3724
if (!File(tessellator).existsSync()) {
3825
print('Could not locate libtessellator at $tessellator.');
3926
print('Ensure you are on a supported version of flutter and then run ');

0 commit comments

Comments
 (0)