Resolving package versions
Currently, we use moc --package pkgname pkgpath to resolve package names, and this package name is global, which applies to all source code.
Consider the following library dependencies:
main.mo
import Lib1 "mo:lib1";
import Lib2 "mo:lib2";
and lib1 depends on a different version of lib2 than what's used in main.mo. Ideally, we should be able to say moc --package lib2 "path_used_by_main" when compiling main.mo, and --package lib2 "path_used_by_lib1" when compiling lib1.
If main.mo is our own code, we could say import Lib2 "mo:lib2V2" as a workaround, but if main.mo is another third-party dependency, we cannot do it.
Maybe we could order the bindings on the command line, so the rightmost binding is used for packages to the right of that one. Won't work for mutually recursive packages but are there any of those?
Dependency cannot have cycles, at least no non-resolvable cycles. We can exclude that from CLI.
So you mean moc --package lib2 "lib2_v2" main.mo --package lib2 "lib2_v1" lib1.mo? Currently, is there a difference between moc main.mo and moc main.mo lib1.mo?
Currently the treatment of more than on .mo file is a hack and just appends the files, so let's ignore that.
Assuming just one .mo file to moc, I meant something like: moc --package base ... --package lib2 "lib2V1" --package lib1 ... -package lib2 "Lib2V2" main.mo
The main.mo uses Lib2V2 for lib2 (the rightmost binding to the left of main.mo), but lib1 uses libs2V1 for lib2 (the rightmost binding to the left of lib1) and all use the same base.
Not sure that works though.