Use jemalloc by default for some targets, but allow it to be enabled for others

I would like to enable using jemalloc by default on platforms where it is easy to build, but optional on other platforms, so that it can still be compiled with jemalloc if the user has jemalloc set up, but won't try by default, when it is likely to fail.

The current options I see are:

  • Make the tikv-jemallocator dep always optional, and users must opt-in to using it, regardless of platform
  • Use target.cfg(...).dependencies to only add the dependency for some platforms. But then platforms that don't match can't use jemalloc, even if they want to. (this is what fd currently does, but see Set use-jemalloc conditionally instead of ignoring it for some targets · Issue #1822 · sharkdp/fd · GitHub}.
  • Always include jemalloc in the default features, and on platforms where building jemalloc is more difficult, the user must opt out by not using the default features.

None of these options are very good.

Is there a better way to handle this?