Using multiple packages in extensions for Julia 1.9

I’m very excited to see the new features in Julia 1.9. I’m interested in how it is decided which packages are required for loading extensions. Specifically, consider an example:

A package “MyPackage” has an optional dependency on CUDA.jl, but also uses Adapt.jl within the CUDA.jl dependency. This is added to the [extensions] section of the Project.toml:

Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

CUDAExt = ["Adapt", "CUDA"]

with some code in CUDAExt.jl

module CUDAExt

using MyPackage, CUDA, Adapt

function Adapt.adapt_structure(::CUDA.CuArrayAdaptor, x::MyDefinedType)
    # new rule for how to convert MyDefinedType to a CuArray

function do_a_cuda_thing()
    x = MyDefinedType( [0.3f0, 0.5f0] )
    cu_x = cu(x)
    # do some computation

Does the user now have to load both Adapt and CUDA before CUDAExt gets activated? Ideally, the user would not need to be exposed to the Adapt dependency; they could just run

using CUDA
using MyPackage

and CUDAExt would be activated. Would this work with just [weakdeps]? What if the Project.toml were written as

Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"


Would CUDAExt now still work? Or is this not allowed? Is there any documented behaviors for such “weak-subdependencies”?

(PS if this were a full release I would just try these things out, but since it is a pre-release the functionality might not be entirely as planned. Therefore I suppose the question is more about what should be allowed rather than what already is)


Not an answer to your question, but the current version of Julia 1.9 is already RC3… I don’t really think there is something that is planned for Julia 1.9 that is not already in the RC3, for testing your code you can safely consider RC3 as the final release. If there is something that is not working, it’s a bug, not something that is still planned to be added…

Do we know when 1.9 will be officially released?



The closest you can get to what you want with the current functionality is:

  • Make Adapt a normal dependency to your package.
  • But only load Adapt in the extension.

Users will unconditionally install Adapt, but will only pay the cost of loading it once the extension loads.