From f34245b6735ae0321b8a01a038f7303ced76a784 Mon Sep 17 00:00:00 2001 From: Ali Ebrahim Date: Tue, 16 Jul 2024 22:56:59 +0000 Subject: [PATCH 1/3] Fix binary ABI detection. --- .../lib/src/_bin_root.dart | 44 +++++++++++++++++++ .../lib/src/_initialize_path_ops_io.dart | 19 ++------ .../lib/src/_initialize_tessellator_io.dart | 19 ++------ 3 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 packages/vector_graphics_compiler/lib/src/_bin_root.dart diff --git a/packages/vector_graphics_compiler/lib/src/_bin_root.dart b/packages/vector_graphics_compiler/lib/src/_bin_root.dart new file mode 100644 index 00000000..00344f30 --- /dev/null +++ b/packages/vector_graphics_compiler/lib/src/_bin_root.dart @@ -0,0 +1,44 @@ +// 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'; + +/// Get executable root directory +String binRootDir() { + final Directory cacheRoot; + if (Platform.resolvedExecutable.contains('flutter_tester')) { + cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent; + } else if (Platform.resolvedExecutable.contains('dart')) { + cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent; + } else { + throw Exception('Unknown executable: ${Platform.resolvedExecutable}'); + } + final String platform; + if (Platform.isWindows) { + if (Abi.current() == Abi.windowsX64) { + platform = 'windows-x64'; + } else if (Abi.current() == Abi.windowsArm64) { + platform = 'windows-arm64'; + } else { + throw Exception('Unsupported ABI: ${Abi.current()}'); + } + } else if (Platform.isMacOS) { + platform = 'darwin-x64'; + } else if (Platform.isLinux) { + if (Abi.current() == Abi.linuxX64) { + platform = 'linux-x64'; + } else if (Abi.current() == Abi.linuxArm64) { + platform = 'linux-arm64'; + } else { + throw Exception('Unsupported ABI: ${Abi.current()}'); + } + } else { + throw Exception('Cannot identify platform ${Platform.localeName}'); + } + final String output = '${cacheRoot.path}/artifacts/engine/$platform/'; + if (!Directory(output).existsSync()) { + throw Exception('Could not find directory $output for executables'); + } + return output; +} diff --git a/packages/vector_graphics_compiler/lib/src/_initialize_path_ops_io.dart b/packages/vector_graphics_compiler/lib/src/_initialize_path_ops_io.dart index 33cf375c..aea59bb2 100644 --- a/packages/vector_graphics_compiler/lib/src/_initialize_path_ops_io.dart +++ b/packages/vector_graphics_compiler/lib/src/_initialize_path_ops_io.dart @@ -3,37 +3,24 @@ // found in the LICENSE file. import 'dart:io'; + +import '_bin_root.dart'; import 'svg/path_ops.dart'; /// Look up the location of the pathops from flutter's artifact cache. bool initializePathOpsFromFlutterCache() { - final Directory cacheRoot; - if (Platform.resolvedExecutable.contains('flutter_tester')) { - cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent; - } else if (Platform.resolvedExecutable.contains('dart')) { - cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent; - } else { - print('Unknown executable: ${Platform.resolvedExecutable}'); - return false; - } - - final String platform; final String executable; if (Platform.isWindows) { - platform = 'windows-x64'; executable = 'path_ops.dll'; } else if (Platform.isMacOS) { - platform = 'darwin-x64'; executable = 'libpath_ops.dylib'; } else if (Platform.isLinux) { - platform = 'linux-x64'; executable = 'libpath_ops.so'; } else { print('path_ops not supported on ${Platform.localeName}'); return false; } - final String pathops = - '${cacheRoot.path}/artifacts/engine/$platform/$executable'; + final String pathops = '${binRootDir()}/$executable'; if (!File(pathops).existsSync()) { print('Could not locate libpathops at $pathops.'); print('Ensure you are on a supported version of flutter and then run '); diff --git a/packages/vector_graphics_compiler/lib/src/_initialize_tessellator_io.dart b/packages/vector_graphics_compiler/lib/src/_initialize_tessellator_io.dart index 9783089e..dfbee07e 100644 --- a/packages/vector_graphics_compiler/lib/src/_initialize_tessellator_io.dart +++ b/packages/vector_graphics_compiler/lib/src/_initialize_tessellator_io.dart @@ -3,37 +3,24 @@ // found in the LICENSE file. import 'dart:io'; + +import '_bin_root.dart'; import 'svg/tessellator.dart'; /// Look up the location of the tessellator from flutter's artifact cache. bool initializeTessellatorFromFlutterCache() { - final Directory cacheRoot; - if (Platform.resolvedExecutable.contains('flutter_tester')) { - cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent.parent; - } else if (Platform.resolvedExecutable.contains('dart')) { - cacheRoot = File(Platform.resolvedExecutable).parent.parent.parent; - } else { - print('Unknown executable: ${Platform.resolvedExecutable}'); - return false; - } - - final String platform; final String executable; if (Platform.isWindows) { - platform = 'windows-x64'; executable = 'libtessellator.dll'; } else if (Platform.isMacOS) { - platform = 'darwin-x64'; executable = 'libtessellator.dylib'; } else if (Platform.isLinux) { - platform = 'linux-x64'; executable = 'libtessellator.so'; } else { print('Tesselation not supported on ${Platform.localeName}'); return false; } - final String tessellator = - '${cacheRoot.path}/artifacts/engine/$platform/$executable'; + final String tessellator = '${binRootDir()}/$executable'; if (!File(tessellator).existsSync()) { print('Could not locate libtessellator at $tessellator.'); print('Ensure you are on a supported version of flutter and then run '); From f66480edb6c123504034d65d4c76a83a882abc48 Mon Sep 17 00:00:00 2001 From: Ali Ebrahim Date: Tue, 16 Jul 2024 23:44:37 +0000 Subject: [PATCH 2/3] Set up multi-platform tests. --- .github/workflows/compiler.yml | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/compiler.yml b/.github/workflows/compiler.yml index 22618582..8e3a10ec 100644 --- a/.github/workflows/compiler.yml +++ b/.github/workflows/compiler.yml @@ -28,3 +28,39 @@ jobs: # with: # lcov-file: ./packages/vector_graphics_compiler/coverage/lcov.info # github-token: ${{ secrets.GITHUB_TOKEN }} + + test_windows: + runs-on: windows-2022 + defaults: + run: + working-directory: packages/vector_graphics_compiler + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + cache: true + - run: flutter test + + test_mac_x86: + runs-on: macos-13 + defaults: + run: + working-directory: packages/vector_graphics_compiler + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + cache: true + - run: flutter test + + test_mac_m1: + runs-on: macos-14 + defaults: + run: + working-directory: packages/vector_graphics_compiler + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + cache: true + - run: flutter test From 72e8562360d7a3bd26eb403c1b0219603538d793 Mon Sep 17 00:00:00 2001 From: Ali Ebrahim Date: Wed, 17 Jul 2024 00:29:52 +0000 Subject: [PATCH 3/3] Skip test on windows. --- packages/vector_graphics_compiler/test/parser_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/vector_graphics_compiler/test/parser_test.dart b/packages/vector_graphics_compiler/test/parser_test.dart index e32f4a23..e6220a30 100644 --- a/packages/vector_graphics_compiler/test/parser_test.dart +++ b/packages/vector_graphics_compiler/test/parser_test.dart @@ -925,6 +925,8 @@ void main() { .translated(-250, -250), ), ); + }, onPlatform: { + 'windows': const Skip('small floating point differences on Windows') }); test('Opaque blend mode gets a save layer', () {