Skip to content

Expose build_web_compilers options to customize sdk and kernel paths #4299

@schultek

Description

@schultek

TLDR;

Adding more customization options to build_web_compilers would allow Jaspr to support flutter embedding and flutter plugins without needing to maintain a custom fork of this package. These include changing the sdk-, kernel- and library paths of ddc_builder, adding to the list of platform libraries (to allow dart:ui) and a few more. No custom logic is needed beyond configuration options.


When I initially added flutter embedding support to Jaspr, I was forced to fork the build_web_compilers package because of the deep changes I needed to make to the compilation pipeline. The two main problems were:

  1. Compiling a dart program that uses flutter (and thereby dart:ui).
  2. Correctly initializing any depended-on flutter plugin.

The compilation is solved by:

  • replacing a bunch of paths like the sdk path, sdk kernel path and libraries.json path with ones pointing to the respective assets from the installed flutter framework (compare)
  • adding ui and ui_web to the list of allowed platform libraries (compare)
  • ignoring checks on dart:io (compare)
  • copying dart_sdk.js from flutter instead of compiling from source (compare)

The plugin initialization is solved by generating a custom entrypoint script that initializes all plugins, similar to what flutter is generating when running for web.


In the last release I made significant changes to the framework to reduce the custom logic (including moving all the plugin generation to jaspr_builders) and bring the fork much closer to the original, to a point where I think now there is a way to do everything Jaspr needs with a few additional build options on the original builders.

The following should be all options that would need to be added (preliminary names):

  • build_web_compilers:ddc:
    • platform_sdk_path to be passed to platformSdk of DevCompilerBuilder and KernelBuilder
    • sdk_kernel_path to be passed to sdkKernelPath of DevCompilerBuilder and KernelBuilder
    • libraries_path to be passed to librariesPath of DevCompilerBuilder and KernelBuilder
    • additional_web_libraries to be passed to DartPlatform.register
  • build_web_compilers:entrypoint
    • skip_unsupported_dependencies_check to be passed to module.computeTransitiveDependencies(throwIfUnsupported: ...) inside dart2js_bootstrap and dart2wasm_bootstrap
    • libraries_path to be passed to dart2js_bootstrap
  • build_web_compilers:sdk_js
    • dart_js_path to use for copying the dart_sdk.js file and skipping its compilation (alternatively make compilation work using a different sdk, but so far that was unsuccessful for me)

By exposing these options, the package can stay completely independent and doesn't need any Flutter or Jaspr specific logic, while still enabling this use-case.


I'm happy to work on a PR for this, but before I do I would love some feedback from the team if this is the right direction. Finally I have two specific questions:

  1. Does someone see a way to do the sdk.js compilation work instead of copying over? The only downside rn is that this doesn't allow enabling canary features (whatever that is).
  2. Any concerns regarding the new hot-reload related parts of this package? I haven't tried it out yet and am not familiar enough with the whole thing to evaluate.

CC @parlough @kevmoo @davidmorgan @Markzipan

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions