Skip to content

Commit 53d1a67

Browse files
committed
auto merge of #10944 : metajack/rust/pkgid-docs, r=cmr
2 parents 7eb50c2 + da9a02a commit 53d1a67

File tree

4 files changed

+36
-52
lines changed

4 files changed

+36
-52
lines changed

doc/rust.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,8 @@ Attributes on the anonymous crate module define important metadata that influenc
609609
the behavior of the compiler.
610610

611611
~~~~
612-
// Linkage attributes
613-
#[ link(name = "projx",
614-
vers = "2.5",
615-
uuid = "9cccc5d5-aceb-4af5-8285-811211826b82") ];
612+
// Package ID
613+
#[ pkgid = "projx#2.5" ];
616614
617615
// Additional metadata attributes
618616
#[ desc = "Project X" ];
@@ -775,36 +773,24 @@ An _`extern mod` declaration_ specifies a dependency on an external crate.
775773
The external crate is then bound into the declaring scope
776774
as the `ident` provided in the `extern_mod_decl`.
777775

778-
The external crate is resolved to a specific `soname` at compile time,
779-
and a runtime linkage requirement to that `soname` is passed to the linker for
780-
loading at runtime.
781-
The `soname` is resolved at compile time by scanning the compiler's library path
782-
and matching the `link_attrs` provided in the `use_decl` against any `#link` attributes that
783-
were declared on the external crate when it was compiled.
784-
If no `link_attrs` are provided,
785-
a default `name` attribute is assumed,
786-
equal to the `ident` given in the `use_decl`.
787-
788-
Optionally, an identifier in an `extern mod` declaration may be followed by an equals sign,
789-
then a string literal denoting a relative path on the filesystem.
790-
This path should exist in one of the directories in the Rust path,
791-
which by default contains the `.rust` subdirectory of the current directory and each of its parents,
792-
as well as any directories in the colon-separated (or semicolon-separated on Windows)
793-
list of paths that is the `RUST_PATH` environment variable.
794-
The meaning of `extern mod a = "b/c/d";`, supposing that `/a` is in the RUST_PATH,
795-
is that the name `a` should be taken as a reference to the crate whose absolute location is
796-
`/a/b/c/d`.
776+
The external crate is resolved to a specific `soname` at compile time, and a
777+
runtime linkage requirement to that `soname` is passed to the linker for
778+
loading at runtime. The `soname` is resolved at compile time by scanning the
779+
compiler's library path and matching the optional `pkgid` provided as a string literal
780+
against the `pkgid` attributes that were declared on the external crate when
781+
it was compiled. If no `pkgid` is provided, a default `name` attribute is
782+
assumed, equal to the `ident` given in the `extern_mod_decl`.
797783

798784
Four examples of `extern mod` declarations:
799785

800786
~~~~ {.xfail-test}
801-
extern mod pcre (uuid = "54aba0f8-a7b1-4beb-92f1-4cf625264841");
787+
extern mod pcre;
802788
803-
extern mod extra; // equivalent to: extern mod extra ( name = "extra" );
789+
extern mod extra; // equivalent to: extern mod extra = "extra";
804790
805-
extern mod rustextra (name = "extra"); // linking to 'extra' under another name
791+
extern mod rustextra = "extra"; // linking to 'extra' under another name
806792
807-
extern mod complicated_mod = "some-file/in/the-rust/path";
793+
extern mod foo = "some/where/foo#1.0"; // a full package ID for rustpkg
808794
~~~~
809795

810796
##### Use declarations
@@ -1742,7 +1728,8 @@ names are effectively reserved. Some significant attributes include:
17421728
* The `doc` attribute, for documenting code in-place.
17431729
* The `cfg` attribute, for conditional-compilation by build-configuration.
17441730
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
1745-
* The `link` attribute, for describing linkage metadata for a crate.
1731+
* The `link` attribute, for describing linkage metadata for a extern blocks.
1732+
* The `pkgid` attribute, for describing the package ID of a crate.
17461733
* The `test` attribute, for marking functions as unit tests.
17471734
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
17481735
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
@@ -3795,7 +3782,7 @@ specified then log level 4 is assumed. Debug messages can be omitted
37953782
by passing `--cfg ndebug` to `rustc`.
37963783

37973784
As an example, to see all the logs generated by the compiler, you would set
3798-
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `link`
3785+
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `pkgid`
37993786
[attribute](#attributes)). To narrow down the logs to just crate resolution,
38003787
you would set it to `rustc::metadata::creader`. To see just error logging
38013788
use `rustc=0`.

doc/rustdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ comments":
1313
~~~
1414
// the "link" crate attribute is currently required for rustdoc, but normally
1515
// isn't needed.
16-
#[link(name="universe")];
16+
#[pkgid = "universe"];
1717
#[crate_type="lib"];
1818
1919
//! Tools for dealing with universes (this is a doc comment, and is shown on

doc/rustpkg.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ as well as `foo/src/bar/extras/baz/lib.rs`,
8989
then both `bar` and `bar/extras/baz` are valid package identifiers
9090
in the workspace `foo`.
9191

92+
Because rustpkg uses generic source file names as the main inputs, you will
93+
need to specify the package identifier in them using the `pkgid` attribute
94+
on the crate.
95+
9296
## Source files
9397

9498
rustpkg searches for four different fixed filenames in order to determine the crates to build:
@@ -108,9 +112,6 @@ When building a package that is not under version control,
108112
or that has no tags, `rustpkg` assumes the intended version is 0.1.
109113

110114
> **Note:** A future version of rustpkg will support semantic versions.
111-
> Also, a future version will add the option to specify a version with a metadata
112-
> attribute like `#[link(vers = "3.1415")]` inside the crate module,
113-
> though this attribute will never be mandatory.
114115
115116
# Dependencies
116117

doc/tutorial.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,22 +3070,21 @@ Therefore, if you plan to compile your crate as a library, you should annotate i
30703070
// lib.rs
30713071
30723072
# #[crate_type = "lib"];
3073-
// Crate linkage metadata
3074-
#[link(name = "farm", vers = "2.5")];
3073+
// Package ID
3074+
#[pkgid = "farm#2.5"];
30753075
30763076
// ...
30773077
# fn farm() {}
30783078
~~~~
30793079

3080-
You can also in turn require in a `extern mod` statement that certain link metadata items match some criteria.
3081-
For that, Rust currently parses a comma-separated list of name/value pairs that appear after
3082-
it, and ensures that they match the attributes provided in the `link` attribute of a crate file.
3083-
This enables you to, e.g., pick a crate based on its version number, or link a library under a
3084-
different name. For example, these two `mod` statements would both accept and select the crate define above:
3080+
You can also specify package ID information in a `extern mod` statement. For
3081+
example, these `extern mod` statements would both accept and select the
3082+
crate define above:
30853083

30863084
~~~~ {.xfail-test}
3087-
extern mod farm(vers = "2.5");
3088-
extern mod my_farm(name = "farm", vers = "2.5");
3085+
extern mod farm;
3086+
extern mod farm = "farm#2.5";
3087+
extern mod my_farm = "farm";
30893088
~~~~
30903089

30913090
Other crate settings and metadata include things like enabling/disabling certain errors or warnings,
@@ -3096,21 +3095,18 @@ or setting the crate type (library or executable) explicitly:
30963095
// ...
30973096
30983097
// This crate is a library ("bin" is the default)
3098+
#[pkgid = "farm#2.5"];
30993099
#[crate_type = "lib"];
31003100
31013101
// Turn on a warning
31023102
#[warn(non_camel_case_types)]
31033103
# fn farm() {}
31043104
~~~~
31053105

3106-
If you're compiling your crate with `rustpkg`,
3107-
link annotations will not be necessary, because they get
3108-
inferred by `rustpkg` based on the Package id and naming conventions.
3109-
3110-
3111-
> ***Note:*** The rules regarding link metadata, both as attributes and on `extern mod`,
3112-
as well as their interaction with `rustpkg`
3113-
are currently not clearly defined and will likely change in the future.
3106+
> ***Note:*** The rules regarding package IDs, both as attributes and as used
3107+
in `extern mod`, as well as their interaction with `rustpkg` are
3108+
currently not clearly defined and will likely change in the
3109+
future.
31143110

31153111
## A minimal example
31163112

@@ -3120,7 +3116,7 @@ We define two crates, and use one of them as a library in the other.
31203116

31213117
~~~~
31223118
// world.rs
3123-
#[link(name = "world", vers = "0.42")];
3119+
#[pkgid = "world#0.42"];
31243120
# extern mod extra;
31253121
pub fn explore() -> &'static str { "world" }
31263122
# fn main() {}
@@ -3144,7 +3140,7 @@ Now compile and run like this (adjust to your platform if necessary):
31443140
Notice that the library produced contains the version in the file name
31453141
as well as an inscrutable string of alphanumerics. As explained in the previous paragraph,
31463142
these are both part of Rust's library versioning scheme. The alphanumerics are
3147-
a hash representing the crates link metadata.
3143+
a hash representing the crates package ID.
31483144

31493145
## The standard library and the prelude
31503146

0 commit comments

Comments
 (0)