JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.73k stars 5.49k forks source link

Extension not loaded if trigger is a strong dependency [on 1.10] #55723

Open topolarity opened 2 months ago

topolarity commented 2 months ago
# Project.toml
name = "Foo"
uuid = "0a21ebe4-285f-4d3c-b082-40545a858146"
authors = ["Cody Tapscott <topolarity@tapscott.me>"]
version = "0.1.0"

[deps]
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"

[extensions]
ModelingToolkitFooExt = ["ModelingToolkit"]
# ext/ModelingToolkitFooExt/ModelingToolkitFooExt.jl
module ModelingToolkitFooExt

using ModelingToolkit
using Foo

println("loaded ext")

end # ModelingToolkitFooExt

The extension does not load when doing using Foo, ModelingToolkit:

$ julia --project=Foo -q
julia> using Foo, ModelingToolkit

julia> Base.get_extension(Foo, :ModelingToolkitFooExt) === nothing
true
julia> versioninfo()
Julia Version 1.10.5
Commit 6f3fdf7b362 (2024-08-27 14:19 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × 12th Gen Intel(R) Core(TM) i7-1255U
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)

Related: https://github.com/JuliaLang/Pkg.jl/issues/3797 https://github.com/JuliaLang/Pkg.jl/issues/4018

topolarity commented 2 months ago

If I change [deps] in the Project.toml to [weakdeps] and do a Pkg> resolve and Pkg> instantiate then this works:

julia> using Foo, ModelingToolkit
julia> Base.get_extension(Foo, :ModelingToolkitFooExt)
ModelingToolkitFooExt
KristofferC commented 2 months ago

Out or curiosity, what is the use case? Since it is a strong dependency I would thought you would put the code in the package since it will be unconditionally loaded, or?

KristofferC commented 2 months ago

Actually... I thought this would work looking at https://github.com/JuliaLang/julia/pull/54009...

KristofferC commented 2 months ago

Ok, it does work on 1.11, it is just that this feature is not available on 1.10.

topolarity commented 2 months ago

Out or curiosity, what is the use case?

Not a very compelling one, but still something I'd expect would work.

I wanted to ] add the extension package so that I could run my tests and I was using --project=. - Basically, I was messing with my environment temporarily as a poor man's version of TestEnv.jl

KristofferC commented 2 months ago

Yeah, that's the use case that was given in https://github.com/JuliaLang/julia/pull/54009 as well.

topolarity commented 1 month ago

Even if the feature is not available on 1.10, I think we ought to fix the KeyError that can happen here: https://github.com/JuliaLang/Pkg.jl/issues/4018