Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_svg] wasm compatibility #8014

Merged
merged 14 commits into from
Nov 7, 2024
Merged
4 changes: 4 additions & 0 deletions packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.14

* Makes the package WASM compatible.

## 1.1.13

* Fix execution on the web with WebAssembly.
Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics/lib/src/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export '_debug_web.dart' if (dart.library.io) '_debug_io.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was changed for wasm support in #7991; why is it being re-changed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't now this one works too, I always used the inverse with dart.library.js_interop to be consistent

export '_debug_io.dart' if (dart.library.js_interop) '_debug_web.dart';
4 changes: 2 additions & 2 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
# See https://github.com/flutter/flutter/issues/157626 before publishing a new
# version.
publish_to: none
version: 1.1.13
version: 1.1.14

environment:
sdk: ^3.4.0
Expand All @@ -22,7 +22,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
# See https://github.com/flutter/flutter/issues/157626
vector_graphics_compiler: ">=1.1.11+1 <= 1.1.12"
vector_graphics_compiler: ">=1.1.11+1 <= 1.1.13"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1.13 doesn't exist; what's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as #8014 (comment)


platforms:
android:
Expand Down
4 changes: 4 additions & 0 deletions packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.13

* Makes the package WASM compatible.

## 1.1.12

* Transfers the package source from https://github.com/dnfield/vector_graphics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import 'src/svg/theme.dart';
import 'src/vector_instructions.dart';

export 'src/_initialize_path_ops_io.dart'
if (dart.library.html) 'src/_initialize_path_ops_web.dart';
if (dart.library.js_interop) 'src/_initialize_path_ops_web.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally be consistent about how we switch on web compilation. @kevmoo / @ditman is there a preference between this and io (as was done in #7991)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io is probably more "permanent" a library, for web conditional imports js_interop has changed in the past (used to be html).

js_interop however is going to be with us for a few years, so it probably doesn't matter much which conditional import to do.

(It feels a little bit weird to export "web" first though, but that's just me because I've almost always started from a mobile implementation!)

export 'src/_initialize_tessellator_io.dart'
if (dart.library.html) 'src/_initialize_tessellator_web.dart';
if (dart.library.js_interop) 'src/_initialize_tessellator_web.dart';
export 'src/geometry/basic_types.dart';
export 'src/geometry/matrix.dart';
export 'src/geometry/path.dart';
Expand Down
4 changes: 2 additions & 2 deletions packages/vector_graphics_compiler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
# See https://github.com/flutter/flutter/issues/157626 before publishing a new
# version.
publish_to: none
version: 1.1.12
version: 1.1.13

executables:
vector_graphics_compiler:
Expand Down Expand Up @@ -36,7 +36,7 @@ dev_dependencies:
sdk: flutter
test: ^1.20.1
# See https://github.com/flutter/flutter/issues/157626
vector_graphics: ">=1.1.11+1 <= 1.1.12"
vector_graphics: ">=1.1.11+1 <= 1.1.14"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1.14 doesn't exist yet, so we don't know if it'll be compatible under the versioning system vector_graphics has used previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on pub.dev, but I just bumped it here https://github.com/flutter/packages/pull/8014/files#diff-ae3c1055bc547ec174edea702c972431d2d3d46fb9bd78a31378cacf0fd051eaR8

If I don't bump the constraints here, how is it supposed to work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed that you were changing vector_graphics, because #7991 already did vector_graphics, and the PR title says this is flutter_svg, not vector_graphics. If vector_graphics* still needs changes, those should be a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Didn't notice someone already made vector_graphics wasm compatible. I just fixed the dev_dependency constraint to use the minimum the WASM version. Do you prefer another PR for a single line change (just dev_dependency)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the changes aren't interdependent, they can be in a single PR. If there are still any cases where you need to both change a package, and change the minimum dependency on that package in another package, that must be multiple PRs because it won't compile in CI.

If you're only changing a dev dependency in v_g_c, it should be fine to include here. But that would also mean you can't have (and shouldn't need) this change in the PR.

Copy link
Contributor

@stuartmorgan stuartmorgan Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't 1.1.13 the minimum required for wasm compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector_graphics was already at 1.1.13, I bumped it to 1.1.14 but the v1.1.13 was not used here, no idea why

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You bumped the maximum, not the minimum. The CHANGELOG entry says this PR makes the package wasm compatible, which would generally involve also setting the minimum versions of any dependencies to wasm-compatible versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, updated it right now

vector_math: ^2.1.2

platforms:
Expand Down
4 changes: 4 additions & 0 deletions third_party/packages/flutter_svg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.12

* Makes the package WASM compatible.

## 2.0.11

* Transfers the package source from https://github.com/dnfield/flutter_svg
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export '_file_io.dart' if (dart.library.html) '_file_none.dart';
export '_file_io.dart' if (dart.library.js_interop) '_file_none.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, this might still rank this package as NOT wasm-compatible in pub due to issues with configuration specific imports.

Better to do

Suggested change
export '_file_io.dart' if (dart.library.js_interop) '_file_none.dart';
export '_file_none.dart' if (dart.library.io) '_file_io.dart';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other PRs that this one relies on have already landed using this version since #8014 (comment) didn't raise any objection.

Could you elaborate on the issue?

Copy link
Contributor Author

@nank1ro nank1ro Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I can confirm this works because I did it with the fork I published, flutter_svg_plus

You can check the platform support inside the score here https://pub.dev/packages/flutter_svg_plus/score

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no doubt that it works at runtime. I'm concerned that the wasm classification on pub.dev will still be broken without this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://pub.dev/api/packages/flutter_svg/metrics

Search for package:flutter_svg/src/utilities/file.dart

Copy link
Contributor Author

@nank1ro nank1ro Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think the score for wasm on pub.dev is wrong, I assure you it is not.
See here https://pub.dev/api/packages/flutter_svg_plus/metrics and here https://pub.dev/api/packages/vector_graphics_compiler/metrics.
The latter is the one which has been already merged using dart.library.js_interop as a conditional import

Copy link
Contributor

@stuartmorgan stuartmorgan Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See dart-lang/pana#1324

I'm confused; I don't see anything in that issue that says that a conditional import based on js_interop wouldn't work, and it's currently working in practice. Could you point to a specific discussion/comment that makes you think this won't work in the future?

See https://pub.dev/api/packages/flutter_svg/metrics

Search for package:flutter_svg/src/utilities/file.dart

Why are we looking at the published version of flutter_svg, which doesn't have the fix in this PR and still uses dart:html?

6 changes: 3 additions & 3 deletions third_party/packages/flutter_svg/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_svg
description: An SVG rendering and widget library for Flutter, which allows painting and displaying Scalable Vector Graphics 1.1 files.
repository: https://github.com/flutter/packages/tree/main/third_party/packages/flutter_svg
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_svg%22
version: 2.0.11
version: 2.0.12

environment:
sdk: ^3.4.0
Expand All @@ -13,9 +13,9 @@ dependencies:
sdk: flutter
http: ^1.0.0
# See https://github.com/flutter/flutter/issues/157626
vector_graphics: ">=1.1.11+1 <= 1.1.12"
vector_graphics: ">=1.1.11+1 <= 1.1.14"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same notes here as in the other package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as #8014 (comment)

vector_graphics_codec: ">=1.1.11+1 <= 1.1.12"
vector_graphics_compiler: ">=1.1.11+1 <= 1.1.12"
vector_graphics_compiler: ">=1.1.11+1 <= 1.1.13"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here as in the other package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as #8014 (comment)


dev_dependencies:
flutter_test:
Expand Down