Bug: Nimbus' JS code is shipped on toolkit (incl. Android, AFAICT) but messaging system + asrouter are not so there are some tricky dependencies
Status: NEW
Priority: P3
Created: 2024-05-21 16:27:32+00:00
Resolved: 2024-06-10 19:48:58+00:00

Apologies for the messy title. We should morph this report as needed. Also this may not be the right component in the end.

For context, I'm trying to make FeatureGates use JEXL bits from Nimbus code for targeting. FeatureGate code is shipped on android and nominally feed into Troubleshoot.sys.mjs [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/modules/Troubleshoot.sys.mjs#8) - but then we promptly bail out [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/modules/Troubleshoot.sys.mjs#473-476). However, after my changes some more of the code gets loaded and things sort of fell apart a bit. So then I investigated and found...

1. `toolkit/components/nimbus/` is, AFAICT, shipped on android - cf. [toolkit/components/moz.build](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/moz.build#136), [and this intriguing comment in nimbus' own moz.build](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/nimbus/moz.build#16-22). But, AIUI, Nimbus integration on android is primarily done via the rust component and not via this library, and JS access would need to use a JVM delegate mechanism instead of this code.
2. in practice that code depends on ASRouter [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs#11-13) and [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs#550) and on Messaging System code [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs#19) and [here](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs#547-556).
3. but ASRouter lives in `browser/` so is "obviously" not available on android
4. and Messaging System code I think is also not available on android, given my backout errors (xpcshell errors not being able to load modules) and [this if condition](https://searchfox.org/mozilla-central/rev/c84d3db8d7d6503b1208a0378db640095e106355/toolkit/components/moz.build#133-134).

I expect that we may want/need to do one or more of the following:

1. make toolkit/components/nimbus/ cope with ASRouter not being available (on non-desktop-Firefox environments like Thunderbird or Fenix or ...), or move the ASRouter targeting bits specifically into Nimbus or a sibling toolkit directory that is shipped in the same circumstances.
2. unship these bits of Nimbus on Android if we're relying solely on the rust component there (but somehow make sure they're in sync about what list of features/experiments/whatever are available, and that the jexl parser behaves the same etc.).
3. move the jexl/targetingcontext bits out of messaging-system such that they are available everywhere `toolkit/components/nimbus` is.
4. or perhaps instead, move all the toolkit nimbus code into `browser/` if we don't think it should be available to toolkit/android/thunderbird/whatever. (unlikely, but want to explicitly call out this is also an option)