-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Move Platform (or similar) to dart:core #35969
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
Comments
Are there any other parts of dart:io that you would like to use on the web? @lrhn We talked a bit about the the Platform class before, any thoughts? |
I was going to create issues for other parts separately, as I discover them, but to answer your question, I think we may also need the subset of the |
I would very much recommend not making It's far safer to just say no to If there is something non-platform specific or generalizable in If the only functionality you need is the OS name, which is just one string, then I'd just make The static String get operatingSystem => _operatingSystem;
static final bool isLinux = (_operatingSystem == "linux"); Those booleans don't need to be in the platform libraries, and indeed it makes it harder to port Dart to a new OS when you have to add an Also, "the subset of the |
@lrhn I think your solution would be fine if we had no existing Dart code in the wild. However, currently in Flutter
While I agree that having |
I would move the shared Client libraries can directly and unconditionally import the other It will require a migration for code that uses No matter what we do, making Just creating a fake |
Agreed!
…On Wed, Mar 6, 2019 at 3:48 AM Lasse R.H. Nielsen ***@***.***> wrote:
I would move the shared Platform functionality to another dart:* library.
Then unconditionally import that into dart:io and use it for the dart:io
Platform class.
That keeps dart:io's Platform available, while also providing a new and
direct access to the functionality.
Client libraries can directly and unconditionally import the other dart:*
library instead of dart:io if all they need is platform information.
Client libraries that use any other dart:io functionality would still not
work on non-IO-supporting platforms anyway.
It *will* require a migration for code that uses dart:io only for
platform flags, in order for them to be compilable to platforms without
dart:io. That was always the case, nothing new here. You can't depend on
something which isn't there. Claiming it's there means that someone might
use it, and that's a run-time failure instead of a compile-time failure.
No matter what we do, making dart:io available on a platform that doesn't
support a majority of the functionality is actively harmful, and we should
not do that. Making the right size of puzzle pieces and making them fit
together is a design task that we can iterate on. That all comes down to *which
functionality* we are talking about. How much is it? How general is it?
If the shared functionality is equivalent to the Platform class
declaration, we can just move that in its entirety, and make dart:io
export the declaration.
Just creating a fake dart:io is an anti-goal, even in the short run.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#35969 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCimR2BjBJmbpmjW2U6paw_4ZLcKJLks5vT6sggaJpZM4a_TIG>
.
|
Ok, I think I'm sold on the idea that if we give access to a Perhaps we are looking at the problem from different angles. I think there is middle ground though. The way I see it is we have Flutter that currently provides access to a bunch of From your angle, it seems the risk is messing up existing Dart ecosystem by introducing What if we make |
Packages will have to do work to support the web anyway. Instead of adding special-case hacks, let's figure out a common package (or dart: lib, I guess). We can create lints/hints to help folks start migrating now. |
I think it's a little early for a migration. There's a lot of value in learning from the current Flutter ecosystem in a non-disruptive way before we ask people to start adapting their code. This will give us time to design a solution and plan out migration steps. I just want to keep it independent from the goal of launching web support in Flutter. |
Well, we can't stop you from doing that. The Flutter tools can add any You will risk that configurable imports might choose |
I'm not suggesting a mutiny, just trying to find an option that satisfies our constraints. My understanding was that dart2js/DDC implemented some compiler intrinsics around Adding it to the Flutter's build of the SDK makes sense. This way we won't be polluting existing Web code or the Dart SDK. It will also temporarily unblock us until we decide on the long-term solution. @jonahwilliams How straightforward is it to add a custom
As of now whether you use |
It's not straightforward at all really. Presumably we could only really support a subset of dart:io, so this would need to be done by supplying our own patch files, building our own dartdevc sdk, and so on. Then there are the code size concerns, et cetera. Ultimately it would be a lot of duplicated work, and if we're only realistically going to support 1 or 2 types then I'm more in favor of using conditional imports. While there are plenty of existing flutter apps that make heavy use of dart:io, there are no existing flutter apps which compile to the web so I don't see this as breaking. Ultimately a user attempt to port their application to run on the web will need to make some adjustments regardless. |
I think we should go ahead and move |
@vsmenon Is there a concrete proposal for where exactly to move it? |
I like this idea! |
I believe that @lrhn is referring to things for which a subset of the full features are available on some platforms. So the |
Oh, I totally misread that, sorry. I thought there would be one library that allows dynamically checking which features are supported. But could we support dynamic feature selection? This way we would only need one library that scales to all platforms. |
If we have different implementations depending on the supported library, It's usually a bad idea. Users won't check individual features, they'll just check which platform they are on, and use whatever features they know work on that platform. Or forget to check, and only work on one platform. Or wait for someone else to build an abstraction library on top which only exposes the features that are available everywhere. We could make the "GeneralFile" class expose the |
Have we reached agreement here to move forward with the option described in #35969 (comment)? |
I might have a solution for that: dart-lang/language#416
I'm still worried that we'll go into all this trouble carefully refactoring the core libraries and telling our users to migrate, and in the end we'll end up with platforms that can only implement these libraries partially leaving us exactly where we started. We can only predict the future so far. Any rigid structure we come up with today is bound to get outdated. I think there might be a way to have something more malleable that changes its shape as we onboard more platforms. However, it will require some design work, perhaps new language features. We might be better off doing something that feels hacky short-term and invest our energy into something that lasts. |
The proposal in that comment isn't to refactor the core libraries, it's to expose the platform independent parts in a package. One of the key benefits of this is that packages are versioned, so there's a story for changing the functionality provided by the package if and when we add platforms. |
Is this a D26 issue ? |
Not D26, but I believe we need this no later than D27. |
Pushing from D27 to next as we haven't nailed down what / requirements yet. |
litle case: import 'player_base.dart'
if (dart.platform.html) 'web_player.dart'
if (Platform.isWindows) 'winmm_player.dart'
if (Platform.isLinux) 'alsa_player.dart'
if (Platform.isMacOS) 'audiotoolbox_player.dart'
if (Platform.isAndroid) 'audiotrack_player.dart'
// ...
; ``` |
This case is interesting because it requires environment declarations in order to drive configurable imports. import 'player_base.dart'
if (dart.library.html) 'web_player.dart' // Already works!
if (dart.platform.os == "windows") 'winmm_player.dart'
if (dart.platform.os == "linux") 'also_player.dart'
// ...
; That comes with some complications too. It means that platform agnostic compilation is impossible when you have to specify the target platform at compile-time, ... which you do because it affects which libraries are imported and compiled. On the other hand, any new platform (like the sweet SugarOS platform) can introduce itself by simply setting the platform OS variable to, fx, It's only an approach which works for fairly static things, and not something we can do for, say, supporting |
OS specific imports are not something we want to support on the build system side. We will be doubling our "platforms" for compilation with NNBD, multiplying that again by the number of operating systems is not feasible. cc @jakemac53 |
Just want to chime in and mention that if this value was |
Note that configurable imports also enable tree-shaking, but actually in a much more powerful sense. Only the matching import ever exists in the program at all. The other code never has to be tree shaken by the compiler because it is never imported. This includes all the transitive deps of each platform specific import. |
@lrhn - should we close this in favor of a different issue re |
I believe we should, @lrhn ? |
The current plan is to provide a package which supports the behavior of |
While adding Web support to Flutter we'd like to minimize the amount of disruption for Flutter developers, and maximize their code portability. As part of that, we'd like to make as much of the standard library API as possible available to the Web compilation target.
Flutter uses
Platform
fromdart:io
to detect current OS. This function should be implementable on the Web via Window.navigator./cc @vsmenon @kevmoo
The text was updated successfully, but these errors were encountered: