gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.48k stars 726 forks source link

Transitive Dependency Warnings via gleam compile-package #2566

Open tynanbe opened 7 months ago

tynanbe commented 7 months ago

As mentioned in https://github.com/gleam-lang/mix_gleam/issues/38

The gleam compile-package API should perhaps not generate these warnings, or have a flag to disable them.

tim2CF commented 7 months ago

Not sure what exactly happen, but this change did solve the transitive dependency issue at least in my project https://github.com/gleam-lang/mix_gleam/pull/39

brunoparga commented 5 months ago

So, I have never written a line of Rust in my life, but I'm trying to follow what exactly causes this to happen, and think in general terms of a solution.

analyse::record_imported_items_for_use_detection emits the warning if !direct_dependencies.contains_key(&module_info.package) (and other conditions). I presume that if dependencies from mix.exs make their way into this direct_dependencies HashMap argument, the issue will be solved; I would like y'all's opinion on whether this is indeed the case and a desirable solution.

I tried to figure out how the dependencies from gleam.toml make their way to this direct_dependencies thingy. Here's the path of function calls I could identify:

Here it branches into two paths, each reaching two very similar functions:

-or-

Both these read functions parse TOML. ProjectCompiler also has a compile_mix_dep_package method, which I don't know if it is related.

So, a few questions: 1 - should there really be these two almost identical read functions? 2 - how can they be modified to include dependencies from mix.exs so the transitive deps warning goes away? 3 - is this all anywhere near correct?

lpil commented 5 months ago

As Tynan says the solution is to have the gleam compile-package API not emit that warning ever, so it just needs to set some extra configuration on the package compiler which is passed to the analyser.

brunoparga commented 5 months ago

Yeah, that seems more complicated than I can do with zero Rust knowledge.