# Using multiple packages in extensions for Julia 1.9

**URL:** https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237
**Category:** General Usage
**Created:** [May 3, 2023, 8:16am UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237 "2023-05-03T08:16:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![April-Hannah-Lena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/april-hannah-lena/32/38975_2.png) [@April-Hannah-Lena](https://discourse.julialang.org/u/April-Hannah-Lena)
#### Post date: [May 3, 2023, 8:16am UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237/1 "2023-05-03T08:16:08Z")

</div>

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`:

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

[extensions]
CUDAExt = ["Adapt", "CUDA"]

```

with some code in `CUDAExt.jl`

```julia
module CUDAExt

using MyPackage, CUDA, Adapt

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

function do_a_cuda_thing()
    x = MyDefinedType( [0.3f0, 0.5f0] )
    cu_x = cu(x)
    # do some computation
    CUDA.unsafe_free!(cu_x)
end

```

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

```julia
using CUDA
using MyPackage

```

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

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

[extensions]
CUDAExt = "CUDA"

```

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)

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [May 3, 2023, 8:24am UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237/2 "2023-05-03T08:24:35Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [May 3, 2023, 11:46am UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237/3 "2023-05-03T11:46:18Z")

</div>

Do we know when 1.9 will be officially released?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [May 3, 2023, 12:15pm UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237/4 "2023-05-03T12:15:18Z")

</div>

soon

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [May 3, 2023, 12:25pm UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237/5 "2023-05-03T12:25:54Z")

</div>

> [@April-Hannah-Lena](#):
>
> 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

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.
