# Dealing with optional dependencies in v1.5?

**URL:** <https://discourse.julialang.org/t/dealing-with-optional-dependencies-in-v1-5/44411>\
**Category:** General Usage\
**Created:** [August 6, 2020, 10:11am UTC](https://discourse.julialang.org/t/dealing-with-optional-dependencies-in-v1-5/44411 "2020-08-06T10:11:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [August 6, 2020, 10:11am UTC](https://discourse.julialang.org/t/dealing-with-optional-dependencies-in-v1-5/44411/1 "2020-08-06T10:11:32Z")

</div>

I’ve been having an [issue](https://github.com/GiovineItalia/Compose.jl/issues/308) for a long time with Compose and its optional Cairo backend. Compose [uses](https://github.com/GiovineItalia/Compose.jl/blob/master/src/Compose.jl#L175) Requires.jl to support Cairo. This works fine unless you make a new package that uses both :

```julia
module TestCompose
    using Cairo
    using Compose

    import Compose.absolute_native_units            
end 

```

This throws a warning, showing that the Cairo optional code hasn’t been loaded :

```julia
julia> using TestCompose
[Info: Precompiling TestCompose [8e4707c8-58a9-410c-9b10-f498f0d6d1ed]
WARNING: could not import Compose.absolute_native_units into TestCompose

```

Previously I would force Compose to load compose to load Cairo code using `@eval`, but in v1.5 this had been turned into a precompilation error (instead of a warning).

I’ve tried to do it from ` __init__ ()` too and it does work when using the module in isolation but If you try to use it in another module it crashes again at precompilation.

```julia
function __init__ ()
    Compose.link_cairo() #or @eval...
end

```

Any way to make this work ? It’s not clear to me if it’s an issue with my code, Compose, or Require.

The error message tells me not to do this, but not what to do :

`ERROR: LoadError: InitError: Evaluation into the closed module `Compose` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `Compose` with `eval` during precompilation - don't do this.`

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 7, 2020, 1:51pm UTC](https://discourse.julialang.org/t/dealing-with-optional-dependencies-in-v1-5/44411/2 "2020-08-07T13:51:42Z")

</div>

I haven’t thought about the actual problem much, but you might be able to work around that `InitError` by only running `link_cairo` when

```julia
isprecompiling() = ccall(:jl_generating_output, Cint, ()) == 1

```

returns `false`.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [August 7, 2020, 2:08pm UTC](https://discourse.julialang.org/t/dealing-with-optional-dependencies-in-v1-5/44411/3 "2020-08-07T14:08:42Z")

</div>

That works yes, thanks. Feels a bit like a hack though.

On the other hand the startup time is awesome on v1.5, I haven’t timed it but it almost feels fast.
