Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler lookup path separation #19767

Closed
alexcrichton opened this issue Dec 12, 2014 · 6 comments · Fixed by #19941
Closed

Compiler lookup path separation #19767

alexcrichton opened this issue Dec 12, 2014 · 6 comments · Fixed by #19941
Milestone

Comments

@alexcrichton
Copy link
Member

Right now the compiler has one lookup path, defined by -L and RUST_PATH. This one lookup path is used for many different purposes, leading to a number of conflicts. In the compiler today there are a number of distinct concepts of lookup paths, including:

  • A lookup path to find native libraries for inclusion in rlibs
  • A lookup path to find extern crate dependencies
  • A lookup path to find transitive dependencies of extern crate directives.

Conflating all of these concepts into one lookup path leads to bugs such as rust-lang/cargo#1037 and #16402 which would benefit greatly from distinct sets of lookup paths.

I would initially propose something like:

    -L [KIND=]PATH      Add a directory to the compiler's search paths. The
                        KIND provided may be omitted or one of `crate`,
                        `native`, or `dependency`. Each value adds the lookup
                        path to a separate lookup path in the compiler, and if
                        omitted the path is added to all lookup paths.

Using this, cargo itself would only pass -L dependency=..., build scripts would pass -L native=..., and normal uses of the compiler would continue just using -L. This behavior is also backwards compatible with today's semantics.

I'd like to nominate this issue, however, as rust-lang/cargo#1037 is quite a worrying issue which needs to be solved as part of Cargo's stability story.

@emberian
Copy link
Member

This design seems sensible to me.

@codyps
Copy link
Contributor

codyps commented Dec 14, 2014

An alternative here is to use prioritization of libraries based on the path they're found in (as traditional linkers do) insead of failing when 2 of the same lib are found.

If we do impliment filesearch path categories, do they really eliminate all the duplicate lib conditions we could run into?

@alexcrichton
Copy link
Member Author

I thought we would be able to do so, but I don't think that it will solve all of our problems. It would primarily not solve rust-lang/cargo#1037 as it wouldn't prevent the operation, and it would only solve #16402 if the compiler's rustlib directory had the highest priority (which seems a little backwards).

We could still choose to do what traditional linkers do with conflicting libs if we have path categories, however.

@pnkfelix
Copy link
Member

P-backcompat-libs, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Dec 18, 2014
@codyps
Copy link
Contributor

codyps commented Dec 18, 2014

Another thing to consider (gcc, ld, and probably others allow) is simply being able to specify the full path to a library when linking, rather than appending a path & library name and hoping that we manage to choose the one intended.

Doing this would also allow cargo (and others) to more accurately communicate their intent to rustc.

@alexcrichton
Copy link
Member Author

That's largely what --extern can be used for, but we'd need to extend it to support native libraries as well as transitive dependencies as well.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 23, 2014
This commit adds support for the compiler to distinguish between different forms
of lookup paths in the compiler itself. Issue rust-lang#19767 has some background on this
topic, as well as some sample bugs which can occur if these lookup paths are not
separated.

This commits extends the existing command line flag `-L` with the same trailing
syntax as the `-l` flag. Each argument to `-L` can now have a trailing `:all`,
`:native`, `:crate`, or `:dependency`. This suffix indicates what form of lookup
path the compiler should add the argument to. The `dependency` lookup path is
used when looking up crate dependencies, the `crate` lookup path is used when
looking for immediate dependencies (`extern crate` statements), and the `native`
lookup path is used for probing for native libraries to insert into rlibs. Paths
with `all` are used for all of these purposes (the default).

The default compiler lookup path (the rustlib libdir) is by default added to all
of these paths. Additionally, the `RUST_PATH` lookup path is added to all of
these paths.

Closes rust-lang#19767
bors added a commit that referenced this issue Dec 30, 2014
This commit adds support for the compiler to distinguish between different forms
of lookup paths in the compiler itself. Issue #19767 has some background on this
topic, as well as some sample bugs which can occur if these lookup paths are not
separated.

This commits extends the existing command line flag `-L` with the same trailing
syntax as the `-l` flag. Each argument to `-L` can now have a trailing `:all`,
`:native`, `:crate`, or `:dependency`. This suffix indicates what form of lookup
path the compiler should add the argument to. The `dependency` lookup path is
used when looking up crate dependencies, the `crate` lookup path is used when
looking for immediate dependencies (`extern crate` statements), and the `native`
lookup path is used for probing for native libraries to insert into rlibs. Paths
with `all` are used for all of these purposes (the default).

The default compiler lookup path (the rustlib libdir) is by default added to all
of these paths. Additionally, the `RUST_PATH` lookup path is added to all of
these paths.

Closes #19767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants