-
Notifications
You must be signed in to change notification settings - Fork 207
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
Discussion: Dart Codegen and Platforms #1436
Comments
@davidmorgan as well because this also has implications for |
One possibly amendment/optimization for this proposal, would be to change the meaning of There would be a few advantages to this:
I see one primary disadvantage here, which is subtle changes in your package could change the platform that the platform agnostic builders end up getting. We could allow an override in some way, possibly for the |
I'm not sure of this. I think certain things like the name of the type are likely to be required for platform agnostic codegen.
Which summaries or kernel files do we use for platform agnostic codegen? |
I think for most cases this won't matter, and I also don't see a way to avoid the restriction other than the options I have listed above:
Same answer - use ideally some restricted platform summary ( |
cc @vsmenon as well |
After some more brainstorming we have a few approaches to consider. Static configurationThis is essentially the above proposal optionally combined (or superseded) by configuration at the target level alongside (or instead) of the builder level. By allowing configuration on the target we would solve the case of resolving specific types from Pros
Cons
"Merge" SDK dill filesWe might be able to know at the start of a build what the combined set of SDKs are, and it might be possible to take multiple SDK dill files and use them simultaneously. This would take some work in the front_end and we'd need to carefully consider what should be exposed - ie if 2 SDKs have a different value for some constant or for resolved types how should we surface that? Pros
Cons
Generate a Dart source file per platformFor any Builder which uses a Resolver we could build an output per platform where each one had a Resolver backed by that platform's SDK. We could force these builders to be lazy so that we only run for the platforms where we need to (requires getting our full kernel pipeline working for the VM so we can lazily build Dart sources for that platform). Pros
Cons
|
Regarding the final option, one thought that comes to mind is that this is already a problem we have inside the analyzer: for instance, the dart2js vs dartium flavors of dart:html. And the vm vs js forms of dart:http. I believe we currently assume they are equally viable and pick one, which may not work here. we could also use conditional imports, but that requires code generators to write an interface file in addition to a source code per configuration. I'm basing that off of this proposal, which may be out of date and/or differ from the spec though... https://github.com/munificent/dep-interface-libraries/blob/master/Proposal.md I think in general we would want to shy away from analysis depending upon things that can't be known at analysis time, though. That for instance is what led to the auto const issues. |
Closing this - we now build the SDK summary on the fly from your current sdk which solves the flutter case, which was the primary thing we care about. |
See #1430 and dart-lang/sdk#32960 for context.
As we expand support for build_runner to support non-web customers as first class clients, we need to figure out how users will write and run
Builder
s that require certain platforms, and how we will provide support for that withinbuild_runner
andbazel_codegen
.I envision in the short term essentially two classes of
Builder
:source
, which means shipping the generated code with the package, and it should be cross-platform compatible.To solve both of these use cases, I propose that we add a
platform
field to thebuilder
definition inbuild.yaml
. This would take a single value, which is either a platform identifier such asweb
(angular would do this), orall
. For now at least, we would not allow you to support multiple explicit platforms.If you opt into a specific platform in your builder, then we would ensure that the
Resolver
you get is specific to that platform. Otherwise, we would either use a newcore_libs
platform or in absence of that simply choose a canonical platform (likelyvm
, although this really isn't ideal).In the presence of config specific imports, platform agnostic builders would get the
default
import, while platform specific builders would get the import resolving to their platform, if available.This enables "safe" cross-platform builders by not exposing much from any specific platform to cross-platform generated code (you would still have some constants most likely, and I am sure a few other things, but the hypothesis is that its unlikely to cause real world problems). This would create a limitation on what platform agnostic builders can do potentially, but the use cases should be narrow and there should be at least one workaround available, which is to use config specific imports with stubs in the
default
import.This also enables platform specific builders to ensure they can access everything from the platform they are targeting.
Note that this proposal would almost certainly be blocked on using summary/kernel based
Resolver
s implementation (in build_runner) to make it sufficiently cheap to create multiple analysis contexts.cc @sigmundch @leafpetersen @natebosch @grouma @dgrove @matanlurey
The text was updated successfully, but these errors were encountered: