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

Support cross-platform packages #6943

Closed
DartBot opened this issue Nov 26, 2012 · 20 comments
Closed

Support cross-platform packages #6943

DartBot opened this issue Nov 26, 2012 · 20 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 26, 2012

This issue was originally filed by ladicek@gmail.com


I know that Dart wants to solve environment-specific libraries somehow, see for example the notes from November 5th language design meeting. Here is my proposal that I also posted as a reply on the list.


This isn't about a general facility for configuration-specific code, but only for code that varies between different Dart execution environments. I've always believed that solving this on library level would be good enough. Having one 'browser' and one 'standalone' library and being able to import them in a unified way, that solves a lot of issues.

And thinking about it more, it would totally suffice to only modify the 'export' directive. Look at this:

awesome_lib_browser.dart:
...

awesome_lib_standalone.dart:
...

awesome_lib.dart:

library awesome_lib;

export 'awesome_lib_browser.dart' if in 'browser';
export 'awesome_lib_standalone.dart' if in 'standalone';

I would be able to write

import 'awesome_lib.dart';

and get awesome_lib_browser.dart imported in the browser or awesome_lib_standalone.dart imported in the standalone VM. (Note that I'm specifically not using the term VM, because the VM can be both in the browser and in the standalone environment.)

Semantics: the Dart compiler always knows what execution environment it targets (in case of the VM, I'm not sure if the embedder takes care of exports in the same way it takes care of imports, but I guess it could), so it only processes those exports that are appropriate and ignores all the other ones.

It would be possible to add similar clause to 'import' (and it would make them more symetric), but I believe that adding it only to 'export' is sufficient.

Notice that it looks like english sentence and I didn't have to add any new keyword :-) Also, this allows for additional execution environments (like Dart on JVM), but I'm not sure if that is necessary.

@gbracha
Copy link
Contributor

gbracha commented Nov 26, 2012

We are faced with both the per platform problem and the general configuration problem. Neither can be ignored for too long. It is best to think of the two together. Solutions exist, but they need to fit in with the constraints of Dart and its user culture.


Set owner to @gbracha.
Added Area-Language, Accepted labels.

@nex3
Copy link
Member

nex3 commented Sep 5, 2013

Marked this as blocking #13062.

@peter-ahe-google
Copy link
Contributor

Unmarked this as blocking #13062.

@nex3
Copy link
Member

nex3 commented Jul 9, 2014

Since there's been no progress on this on the language front, we've decided (at Kasper's suggestion) to use the transformer infrastructure to handle it in pub.


Set owner to @nex3.
Removed Type-Defect, Area-Language labels.
Added Type-Enhancement, Area-Pub, Started labels.

@nex3
Copy link
Member

nex3 commented Jul 15, 2014

Changed the title to: "Support cross-platform packages".

@nex3
Copy link
Member

nex3 commented Jul 15, 2014

Marked this as blocking #20068.

@DartBot
Copy link
Author

DartBot commented Aug 11, 2014

This comment was originally written by @kaendfinger


@NweiZ Can you comment with an explanation of how this would work?

@nex3
Copy link
Member

nex3 commented Aug 12, 2014

In the system I've been working on, imports of "dart:io" and "dart:html" would work on all platforms. All types would be available everywhere, but the implementations would throw UnsupportedErrors on platforms where they're unavailable. This may not end up landing, though.


Removed the owner.
Added Triaged label.

@DartBot
Copy link
Author

DartBot commented Aug 12, 2014

This comment was originally written by hach...@gmail.com


I would like this solution.

@DartBot
Copy link
Author

DartBot commented Aug 12, 2014

This comment was originally written by @radicaled


Who do we have to bribe and how much do we have to give them to get your implementation integrated?

@nex3
Copy link
Member

nex3 commented Aug 12, 2014

Lars is ultimately the one who decides on the solution. He and Bob have been discussing it.

@DartBot
Copy link
Author

DartBot commented Aug 13, 2014

This comment was originally written by @Emasoft


Why throwing "UnsupportedErrors" when we can adopt a "polyfill" like approach to this, like we make with browsers? If a specific platform is missing some functionality, Dart should just emulate it. It should do it at the lowest possible level, to avoid too much abstraction, but it should do it for everything. Node.js is messy but is running on dozen of platforms and OS's now, and because of this its adoption is growing fast. Dart should be what Node.js is trying to be. The polyfill approach is what is going to make Dart succeed where even Java failed (too much abstraction) and where Node.js strives to achieve.

@nex3
Copy link
Member

nex3 commented Aug 13, 2014

Polyfilling is a good approach for packages, but not for the core libraries. There's too much fundamental difference in capabilities; for example, the browser fundamentally can't support standard input or custom SSL certificates. This proposal allows packages to build their own polyfills with more restrictive APIs.

@DartBot
Copy link
Author

DartBot commented Aug 13, 2014

This comment was originally written by @Emasoft


Ok, but Dart should try to avoid throwing errors as much as possible. If STDIN or another device is not present it should not throw an error, but just return an empty, silent stream.
For all missing devices it would start listening but nothing will be heard because the device is not there. That way the code will retain its functionality and would not throw errors. Also device states Enumerators would be VERY useful to be included in all libraries for checking the presence of something before trying to use it, as good practice. For example this check could be a strongly reccomended coding practice:

 if( console.currentStatus == consoleStatus.DeviceNotPresent ) ... then ... doSomethingElse()

Custom SSL certificates can be generated in the browser to be used in Data Channels (the DTLS handshake performed between two WebRTC p2p clients relies on self-signed certificates), so the library to generate them should be always there.

@nex3
Copy link
Member

nex3 commented Aug 13, 2014

If that's the behavior you want, you're welcome to implement a package that exposes it.

@munificent
Copy link
Member

Bouncing this back to the language since the team decided pub wasn't the right place to handle it.


cc @lrhn.
cc @larsbak.
Removed Area-Pub label.
Added Area-Language label.

@nex3
Copy link
Member

nex3 commented Dec 19, 2014

Marked this as blocking #21917.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed Priority-Medium labels Mar 1, 2016
@stevenroose
Copy link

Anything new on this issue?

This is still a big issue for libraries that want to use HTTP or WebSockets internally.

@zoechi
Copy link
Contributor

zoechi commented Oct 16, 2016

#24581

@munificent munificent added the closed-duplicate Closed in favor of an existing report label Dec 16, 2016
@munificent
Copy link
Member

Right, you can do this with config-specific imports now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

8 participants