]> git.lizzy.rs Git - rust.git/blob - doc/rustpkg.md
auto merge of #8357 : omasanori/rust/cleanup, r=alexcrichton
[rust.git] / doc / rustpkg.md
1 % Rustpkg Reference Manual
2
3 # Introduction
4
5 This document is the reference manual for the Rustpkg packaging and build tool for the Rust programming language.
6
7 ## Disclaimer
8
9 Rustpkg is a work in progress, as is this reference manual.
10 If the actual behavior of rustpkg differs from the behavior described in this reference,
11 that reflects either an incompleteness or a bug in rustpkg.
12
13 # Package searching
14
15 rustpkg searches for packages using the `RUST_PATH` environment variable,
16 which is a colon-separated list (semicolon-separated on Windows) of directories.
17
18 Each directory in this list is a *workspace* for rustpkg.
19
20 `RUST_PATH` implicitly contains an entry for `./.rust` (as well as
21 `../.rust`, `../../.rust`,
22 and so on for every parent of `.` up to the filesystem root).
23 That means that if `RUST_PATH` is not set,
24 then rustpkg will still search for workspaces in `./.rust` and so on.
25 `RUST_PATH` also implicitly contains an entry for the system path:
26 `/usr/local` or the equivalent on Windows.
27 This entry comes after the implicit entries for `./.rust` and so on.
28 Finally, the last implicit entry in `RUST_PATH` is `~/.rust`
29 or the equivalent on Windows.
30
31 Each workspace may contain one or more packages.
32
33 When building code that contains one or more directives of the form `extern mod P`,
34 rustpkg automatically searches for packages named `P` in the `RUST_PATH` (as described above).
35 It builds those dependencies if necessary.
36 Thus, when using rustpkg,
37 there is no need for `-L` flags to tell the linker where to find libraries for external crates.
38
39 # Package structure
40
41 A valid workspace must contain each of the following subdirectories:
42
43 * 'src/': contains one subdirectory per package. Each subdirectory contains source files for a given package.
44
45      For example, if `foo` is a workspace containing the package `bar`,
46      then `foo/src/bar/main.rs` could be the `main` entry point for
47      building a `bar` executable.
48 * 'lib/': `rustpkg install` installs libraries into a target-specific subdirectory of this directory.
49
50      For example, on a 64-bit machine running Mac OS X,
51      if `foo` is a workspace containing the package `bar`,
52      rustpkg will install libraries for bar to `foo/lib/x86_64-apple-darwin/`.
53      The libraries will have names of the form `foo/lib/x86_64-apple-darwin/libbar-[hash].dylib`,
54      where [hash] is a hash of the package ID.
55 * 'bin/': `rustpkg install` installs executable binaries into a target-specific subdirectory of this directory.
56
57      For example, on a 64-bit machine running Mac OS X,
58      if `foo` is a workspace, containing the package `bar`,
59      rustpkg will install executables for `bar` to
60      `foo/bin/x86_64-apple-darwin/`.
61      The executables will have names of the form `foo/bin/x86_64-apple-darwin/bar`.
62 * 'build/': `rustpkg build` stores temporary build artifacts in a target-specific subdirectory of this directory.
63
64      For example, on a 64-bit machine running Mac OS X,
65      if `foo` is a workspace containing the package `bar` and `foo/src/bar/main.rs` exists,
66      then `rustpkg build` will create `foo/build/x86_64-apple-darwin/bar/main.o`.
67
68 # Package identifiers
69
70 A package identifier identifies a package uniquely.
71 A package can be stored in a workspace on the local file system,
72 or on a remote Web server, in which case the package ID resembles a URL.
73 For example, `github.com/mozilla/rust` is a package ID
74 that would refer to the git repository browsable at `http://github.com/mozilla/rust`.
75 A package ID can also specify a version, like:
76 `github.com/mozilla/rust#0.3`.
77 In this case, `rustpkg` will check that the repository `github.com/mozilla/rust` has a tag named `0.3`,
78 and report an error otherwise.
79 A package ID can also specify a particular revision of a repository, like:
80 `github.com/mozilla/rust#release-0.7`.
81 When the refspec (portion of the package ID after the `#`) can't be parsed as a decimal number,
82 rustpkg passes the refspec along to the version control system without interpreting it.
83 rustpkg also interprets any dependencies on such a package ID literally
84 (as opposed to versions, where a newer version satisfies a dependency on an older version).
85 Thus, `github.com/mozilla/rust#5c4cd30f80` is also a valid package ID,
86 since git can deduce that 5c4cd30f80 refers to a revision of the desired repository.
87
88 ## Source files
89
90 rustpkg searches for four different fixed filenames in order to determine the crates to build:
91
92 * `main.rs`: Assumed to be a main entry point for building an executable.
93 * `lib.rs`: Assumed to be a library crate.
94 * `test.rs`: Assumed to contain tests declared with the `#[test]` attribute.
95 * `bench.rs`: Assumed to contain benchmarks declared with the `#[bench]` attribute.
96
97 ## Versions
98
99 `rustpkg` packages do not need to declare their versions with an attribute inside one of the source files,
100 because `rustpkg` infers it from the version control system.
101 When building a package that is in a `git` repository,
102 `rustpkg` assumes that the most recent tag specifies the current version.
103 When building a package that is not under version control,
104 or that has no tags, `rustpkg` assumes the intended version is 0.1.
105
106 # Dependencies
107
108 rustpkg infers dependencies from `extern mod` directives.
109 Thus, there should be no need to pass a `-L` flag to rustpkg to tell it where to find a library.
110 (In the future, it will also be possible to write an `extern mod` directive referring to a remote package.)
111
112 # Custom build scripts
113
114 A file called `pkg.rs` at the root level in a workspace is called a *package script*.
115 If a package script exists, rustpkg executes it to build the package
116 rather than inferring crates as described previously.
117
118 Inside `pkg.rs`, it's possible to call back into rustpkg to finish up the build.
119 `rustpkg::api` contains functions to build, install, or clean libraries and executables
120 in the way rustpkg normally would without custom build logic.
121
122 # Command reference
123
124 ## build
125
126 `rustpkg build foo` searches for a package with ID `foo`
127 and builds it in any workspace(s) where it finds one.
128 Supposing such packages are found in workspaces X, Y, and Z,
129 the command leaves behind files in `X`'s, `Y`'s, and `Z`'s `build` directories,
130 but not in their `lib` or `bin` directories.
131
132 ## clean
133
134 `rustpkg clean foo` deletes the contents of `foo`'s `build` directory.
135
136 ## install
137
138 `rustpkg install foo` builds the libraries and/or executables that are targets for `foo`,
139 and then installs them either into `foo`'s `lib` and `bin` directories,
140 or into the `lib` and `bin` subdirectories of the first entry in `RUST_PATH`.
141
142 ## test
143
144 `rustpkg test foo` builds `foo`'s `test.rs` file if necessary,
145 then runs the resulting test executable.