Skip to content

Add 'dart.tool.dart2wasm' to environment during wasm compilation #61464

Open

Description

@biggs0125

Right now some libraries are depending on 'dart.library.html' being available (or not) to determine if the app is running w/ wasm or not.

Since 'dart:html' may eventually be removed, this isn't a great long term strategy.

Dart2js injects 'dart.tool.dart2js' into the environment:

environment['dart.tool.dart2js'] = '${true}';

We can do something similar in dart2wasm and use that here.

Activity

  1. lrhn commented on Sep 8, 2025

    @lrhn
    Member

    Be aware that the current restrictions on conditional imports do not allow using dart.tool.* to choose imports, only dart.library.*.

    There is (AFAIK) no non-deprecated library that differ in availability between Wasm from Dart2js.

    (We should probably allow some more environment variables to be used, as long as they are correlated to the distinctions we use for modular compilation today. We don't want to introduce more distinct compilation targets for build systems.)

  2. mkustermann commented on Sep 8, 2025

    @mkustermann
    Member

    I believe we already added dart.tool.dart2wasm to the environment, which allows const bool.fromEnvironment('dart.tool.dart2wasm').

    It's really what @lrhn points out: Those don't work in conditional imports atm

  3. biggs0125 commented on Sep 8, 2025

    @biggs0125
    Author

    Ah @lrhn is there a plan to allow more environment variables in conditional imports then? As things stand we're actively adding new conditional imports to a now deprecated library. This obviously isn't ideal so we should find an alternative solution sooner rather than later.

  4. lrhn commented on Sep 8, 2025

    @lrhn
    Member

    No concrete plan, at least not that I'm aware of.
    I just keep suggesting it, but we probably want to have a proper design work. Or at least have some agreement on how we'll handle adding more allowed env-variables in the future.

    Definitely want anything we add to be coordinated and consistent across platforms.

    I wrote #54785 as a starting point.

  5. sigmundch commented on Sep 9, 2025

    @sigmundch
    Member

    Assuming we get alignment/design in place. The technical challenges vary a bit. The CFE's logic has a special check to only allow dart.library. and it wouldn't be too much work to expand it to accept more.

    The bazel rules, however, have more assumptions about knowing ahead of time the set of configurations that are accepted, and includes logic to discern based on certain library imports. I expect there may be more work needed in that integration than inside our tools, but it's mostly a hunch, I haven't looked closely.

  6. lrhn commented on Sep 9, 2025

    @lrhn
    Member

    I would definitely, at least initially, go for extensions that align with the existing Bazel configurations.
    That is, you can only ask about something that would be consistently true or false for each configuration, and not anything where one configuration could have either value.

    I don't know what those configurations are. I hope that no two backends use the same configuration, in which case dart.tool.<backend> should be acceptable.
    (If no Bazel configuration uses the analyzer, we can even have dart.tool.analyzer as a configuration, to tell the analyzer which import it should prefer to show instead of always using the first one.)

    Other options that are aligned with backends are something like dart.something.webNumbers or even dart.something.minified, if production building is a separate configuration.

    Those would be useful to have as constants, and the web-numbers as an import guard to choose between implementations (like what we are trying to do for package:fixednum).

  7. added a commit that references this issue on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions