Skip to content

Rustpkg should operate on a URL-like pkgid #5679

Closed
@graydon

Description

@graydon

Sub-bug of #5677

Rustpkg and the rust driver currently have several kinds of identifier for packages and crates: the name, url and uuid fields in #[link] and extern mod as well as the putative id of a rustpkg (which is being sketched-out as a reverse-DNS-dot-path the way java packages were named). These are terribly confusing and lead people to randomly cargo-culting variants of redundant sub-naming schemes, few of which are meaningful.

We want to consolidate these as much as possible, and will be following the design of the Go package-naming system, though with a slight simplification in that our packages aren't "self identifying" -- there's no package foo; declaration in each file, for example -- so don't have a separate (default) name aside from their pkgid stem ("import path" stem, in Go-ese). Those can vary in Go but there doesn't seem to be much point to allowing it for us. They exist in Go to disambiguate exported symbols at the linkage level, but our linkage model encodes the metadata-hash (likely, eventually, just a hash of the pkgid) in each symbol, so we're solving this a different (and hopefully less confusing, more robust) way. If you absolutely need to vary the module-local name a crate is bound under when you extern mod it, you'll be able to; the default will be automatically derived from the pkgid stem. I.e. extern mod "github.com/graydon/foo"; will produce a local binding foo, and you'll have to write extern mod bar = "github.com/graydon/foo"; to get a different local name.

An example structure for holding a path is here:

https://github.com/graydon/rust/blob/rustpkg/src/librustpkg/rustpkg.rc#L1046

The main points to ensure are these:

  • A pkgid must be relative-path-like so that it has a natural mapping to both URL-space and filesystem-space
  • A pkgid must have a stem which is a single-identifier component, the final component of the path
  • The pkgid is never written down anywhere inside a file stored in the package itself. Packages are named from the outside, by the user who is operating rustpkg (i.e. from argv or by scanning RUST_PATH) or some version control tool's repo URLs. A file in a directory doesn't repeat the name of the directory holding it. The same notion holds here.

Crate names should be deduced from the directory containing them, rather than a #[link] attribute inside the crate file. This should work whether a package has one or many crates within it: the immediate containing dir provides the short identifier-name for the crate, and this just happens to be the stem of the pkgid if there is only a single crate in the package (and the crate root is found in the package root).

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions