diff --git a/src/doc/CNAME b/src/doc/CNAME deleted file mode 100644 index b68cc5511a4..00000000000 --- a/src/doc/CNAME +++ /dev/null @@ -1 +0,0 @@ -doc.crates.io diff --git a/src/doc/book/src/01-01-installation.md b/src/doc/book/src/01-01-installation.md new file mode 100644 index 00000000000..9f9052344cc --- /dev/null +++ b/src/doc/book/src/01-01-installation.md @@ -0,0 +1,21 @@ +## Installation + +The easiest way to get Cargo is to get the current stable release of Rust by +using the `rustup` script: + +```shell +$ curl -sSf https://static.rust-lang.org/rustup.sh | sh +``` + +This will get you the current stable release of Rust for your platform along +with the latest Cargo. + +If you are on Windows, you can directly download the latest stable Rust and nightly Cargo: + +- [Rust (32-bit)](https://static.rust-lang.org/dist/rust-1.17.0-i686-pc-windows-gnu.msi) +- [Cargo (32-bit)](https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-windows-gnu.tar.gz) + +- [Rust (64-bit)](https://static.rust-lang.org/dist/rust-1.17.0-x86_64-pc-windows-gnu.msi) +- [Cargo (64-bit)](https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-pc-windows-gnu.tar.gz) + +Alternatively, you can [build Cargo from source](https://github.com/rust-lang/cargo#compiling-from-source). diff --git a/src/doc/book/src/01-02-first-steps.md b/src/doc/book/src/01-02-first-steps.md new file mode 100644 index 00000000000..974adecc5a4 --- /dev/null +++ b/src/doc/book/src/01-02-first-steps.md @@ -0,0 +1,70 @@ +## First steps with Cargo + +To start a new project with Cargo, use `cargo new`: + +```shell +$ cargo new hello_world --bin +``` + +We’re passing `--bin` because we’re making a binary program: if we +were making a library, we’d leave it off. + +Let’s check out what Cargo has generated for us: + +```shell +$ cd hello_world +$ tree . +. +├── Cargo.toml +└── src + └── main.rs + +1 directory, 2 files +``` + +This is all we need to get started. First, let’s check out `Cargo.toml`: + +```toml +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name "] +``` + +This is called a **manifest**, and it contains all of the metadata that Cargo +needs to compile your project. + +Here’s what’s in `src/main.rs`: + +``` +fn main() { + println!("Hello, world!"); +} +``` + +Cargo generated a “hello world” for us. Let’s compile it: + +```shell +$ cargo build + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) +``` + +And then run it: + +```shell +$ ./target/debug/hello_world +Hello, world! +``` + +We can also use `cargo run` to compile and then run it, all in one step: + +```shell +$ cargo run + Fresh hello_world v0.1.0 (file:///path/to/project/hello_world) + Running `target/hello_world` +Hello, world! +``` + +## Going further + +For more details on using Cargo, check out the [Cargo Guide](guide.html) diff --git a/src/doc/book/src/02-01-why-cargo-exists.md b/src/doc/book/src/02-01-why-cargo-exists.md new file mode 100644 index 00000000000..6f08a2f4e11 --- /dev/null +++ b/src/doc/book/src/02-01-why-cargo-exists.md @@ -0,0 +1,11 @@ +## Why Cargo exists + +Cargo is a tool that allows Rust projects to declare their various +dependencies and ensure that you’ll always get a repeatable build. + +To accomplish this goal, Cargo does four things: + +* Introduces two metadata files with various bits of project information. +* Fetches and builds your project’s dependencies. +* Invokes `rustc` or another build tool with the correct parameters to build your project. +* Introduces conventions to make working with Rust projects easier. diff --git a/src/doc/book/src/02-02-creating-a-new-project.md b/src/doc/book/src/02-02-creating-a-new-project.md new file mode 100644 index 00000000000..f457f609e56 --- /dev/null +++ b/src/doc/book/src/02-02-creating-a-new-project.md @@ -0,0 +1,111 @@ +## Creating a new project + +To start a new project with Cargo, use `cargo new`: + +```shell +$ cargo new hello_world --bin +``` + +We’re passing `--bin` because we’re making a binary program: if we +were making a library, we’d leave it off. This also initializes a new `git` +repository by default. If you don't want it to do that, pass `--vcs none`. + +Let’s check out what Cargo has generated for us: + +```shell +$ cd hello_world +$ tree . +. +├── Cargo.toml +└── src + └── main.rs + +1 directory, 2 files +``` + +If we had just used `cargo new hello_world` without the `--bin` flag, then +we would have a `lib.rs` instead of a `main.rs`. For now, however, this is all +we need to get started. First, let’s check out `Cargo.toml`: + +```toml +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name "] +``` + +This is called a **manifest**, and it contains all of the metadata that Cargo +needs to compile your project. + +Here’s what’s in `src/main.rs`: + +``` +fn main() { + println!("Hello, world!"); +} +``` + +Cargo generated a “hello world” for us. Let’s compile it: + +```shell +$ cargo build + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) +``` + +And then run it: + +```shell +$ ./target/debug/hello_world +Hello, world! +``` + +We can also use `cargo run` to compile and then run it, all in one step (you +won't see the `Compiling` line if you have not made any changes since you last +compiled): + +```shell +$ cargo run + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) + Running `target/debug/hello_world` +Hello, world! +``` + +You'll notice several new files and directories have been created: +```shell +$ tree . +. +├── Cargo.lock +├── Cargo.toml +├── src +│   └── main.rs +└── target + └── debug + ├── build + ├── deps + │   └── hello_world-2386c2fd0156916f + ├── examples + ├── hello_world + ├── hello_world.d + ├── incremental + └── native + +8 directories, 6 files +``` + +The `Cargo.lock` file contains information about our dependencies. Since we +don’t have any yet, it’s not very interesting. The `target` directory contains +all the build products, and, as can be seen, Cargo produces debug builds by +default. You can use `cargo build --release` to compile your files with +optimizations turned on: + +```shell +$ cargo build --release + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) +``` + +`cargo build --release` puts the resulting binary in `target/release` +instead of `target/debug`. + +Compiling in debug mode is the default for development -- compilation time is +shorter since the compiler doesn't do optimizations, but the code will run +slower. Release mode takes longer to compile, but the code will run faster. diff --git a/src/doc/book/src/02-03-working-on-an-existing-project.md b/src/doc/book/src/02-03-working-on-an-existing-project.md new file mode 100644 index 00000000000..25203988eb4 --- /dev/null +++ b/src/doc/book/src/02-03-working-on-an-existing-project.md @@ -0,0 +1,22 @@ +## Working on an existing Cargo project + +If you download an existing project that uses Cargo, it’s really easy +to get going. + +First, get the project from somewhere. In this example, we’ll use `rand` +cloned from its repository on GitHub: + +```shell +$ git clone https://github.com/rust-lang-nursery/rand.git +$ cd rand +``` + +To build, use `cargo build`: + +```shell +$ cargo build + Compiling rand v0.1.0 (file:///path/to/project/rand) +``` + +This will fetch all of the dependencies and then build them, along with the +project. diff --git a/src/doc/book/src/02-04-dependencies.md b/src/doc/book/src/02-04-dependencies.md new file mode 100644 index 00000000000..4f01b72e860 --- /dev/null +++ b/src/doc/book/src/02-04-dependencies.md @@ -0,0 +1,90 @@ +## Adding dependencies from crates.io + +[crates.io] is the Rust community's central repository that serves +as a location to discover and download packages. `cargo` is configured to use +it by default to find requested packages. + +To depend on a library hosted on [crates.io], add it to your `Cargo.toml`. + +[crates.io]: https://crates.io/ + +### Adding a dependency + +If your `Cargo.toml` doesn't already have a `[dependencies]` section, add that, +then list the crate name and version that you would like to use. This example +adds a dependency of the `time` crate: + +```toml +[dependencies] +time = "0.1.12" +``` + +The version string is a [semver] version requirement. The [specifying +dependencies](03-01-specifying-dependencies.html) docs have more information about +the options you have here. + +[semver]: https://github.com/steveklabnik/semver#requirements + +If we also wanted to add a dependency on the `regex` crate, we would not need +to add `[dependencies]` for each crate listed. Here's what your whole +`Cargo.toml` file would look like with dependencies on the `time` and `regex` +crates: + +```toml +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name "] + +[dependencies] +time = "0.1.12" +regex = "0.1.41" +``` + +Re-run `cargo build`, and Cargo will fetch the new dependencies and all of +their dependencies, compile them all, and update the `Cargo.lock`: + +```shell +$ cargo build + Updating registry `https://github.com/rust-lang/crates.io-index` + Downloading memchr v0.1.5 + Downloading libc v0.1.10 + Downloading regex-syntax v0.2.1 + Downloading memchr v0.1.5 + Downloading aho-corasick v0.3.0 + Downloading regex v0.1.41 + Compiling memchr v0.1.5 + Compiling libc v0.1.10 + Compiling regex-syntax v0.2.1 + Compiling memchr v0.1.5 + Compiling aho-corasick v0.3.0 + Compiling regex v0.1.41 + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) +``` + +Our `Cargo.lock` contains the exact information about which revision of all of +these dependencies we used. + +Now, if `regex` gets updated, we will still build with the same revision until +we choose to `cargo update`. + +You can now use the `regex` library using `extern crate` in `main.rs`. + +``` +extern crate regex; + +use regex::Regex; + +fn main() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); + println!("Did our date match? {}", re.is_match("2014-01-01")); +} +``` + +Running it will show: + +```shell +$ cargo run + Running `target/hello_world` +Did our date match? true +``` diff --git a/src/doc/book/src/02-05-project-layout.md b/src/doc/book/src/02-05-project-layout.md new file mode 100644 index 00000000000..18657225190 --- /dev/null +++ b/src/doc/book/src/02-05-project-layout.md @@ -0,0 +1,136 @@ +## Project layout + +Cargo uses conventions for file placement to make it easy to dive into a new +Cargo project: + +```shell +. +├── Cargo.lock +├── Cargo.toml +├── benches +│   └── large-input.rs +├── examples +│   └── simple.rs +├── src +│   ├── bin +│   │   └── another_executable.rs +│   ├── lib.rs +│   └── main.rs +└── tests + └── some-integration-tests.rs +``` + +* `Cargo.toml` and `Cargo.lock` are stored in the root of your project. +* Source code goes in the `src` directory. +* The default library file is `src/lib.rs`. +* The default executable file is `src/main.rs`. +* Other executables can be placed in `src/bin/*.rs`. +* Integration tests go in the `tests` directory (unit tests go in each file they're testing). +* Examples go in the `examples` directory. +* Benchmarks go in the `benches` directory. + +These are explained in more detail in the [manifest +description](03-02-manifest.html#the-project-layout). + +## Cargo.toml vs Cargo.lock + +`Cargo.toml` and `Cargo.lock` serve two different purposes. Before we talk +about them, here’s a summary: + +* `Cargo.toml` is about describing your dependencies in a broad sense, and is written by you. +* `Cargo.lock` contains exact information about your dependencies. It is maintained by Cargo and should not be manually edited. + +If you’re building a library that other projects will depend on, put +`Cargo.lock` in your `.gitignore`. If you’re building an executable like a +command-line tool or an application, check `Cargo.lock` into `git`. If you're +curious about why that is, see ["Why do binaries have `Cargo.lock` in version +control, but not libraries?" in the +FAQ](faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries). + +Let’s dig in a little bit more. + +`Cargo.toml` is a **manifest** file in which we can specify a bunch of +different metadata about our project. For example, we can say that we depend +on another project: + +```toml +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name "] + +[dependencies] +rand = { git = "https://github.com/rust-lang-nursery/rand.git" } +``` + +This project has a single dependency, on the `rand` library. We’ve stated in +this case that we’re relying on a particular Git repository that lives on +GitHub. Since we haven’t specified any other information, Cargo assumes that +we intend to use the latest commit on the `master` branch to build our project. + +Sound good? Well, there’s one problem: If you build this project today, and +then you send a copy to me, and I build this project tomorrow, something bad +could happen. There could be more commits to `rand` in the meantime, and my +build would include new commits while yours would not. Therefore, we would +get different builds. This would be bad because we want reproducible builds. + +We could fix this problem by putting a `rev` line in our `Cargo.toml`: + +```toml +[dependencies] +rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" } +``` + +Now our builds will be the same. But there’s a big drawback: now we have to +manually think about SHA-1s every time we want to update our library. This is +both tedious and error prone. + +Enter the `Cargo.lock`. Because of its existence, we don’t need to manually +keep track of the exact revisions: Cargo will do it for us. When we have a +manifest like this: + +```toml +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name "] + +[dependencies] +rand = { git = "https://github.com/rust-lang-nursery/rand.git" } +``` + +Cargo will take the latest commit and write that information out into our +`Cargo.lock` when we build for the first time. That file will look like this: + +```toml +[root] +name = "hello_world" +version = "0.1.0" +dependencies = [ + "rand 0.1.0 (git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9)", +] + +[[package]] +name = "rand" +version = "0.1.0" +source = "git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9" + +``` + +You can see that there’s a lot more information here, including the exact +revision we used to build. Now when you give your project to someone else, +they’ll use the exact same SHA, even though we didn’t specify it in our +`Cargo.toml`. + +When we’re ready to opt in to a new version of the library, Cargo can +re-calculate the dependencies and update things for us: + +```shell +$ cargo update # updates all dependencies +$ cargo update -p rand # updates just “rand” +``` + +This will write out a new `Cargo.lock` with the new version information. Note +that the argument to `cargo update` is actually a +[Package ID Specification](03-07-pkgid-spec.html) and `rand` is just a short +specification. diff --git a/src/doc/book/src/02-06-tests.md b/src/doc/book/src/02-06-tests.md new file mode 100644 index 00000000000..db5ec20aff0 --- /dev/null +++ b/src/doc/book/src/02-06-tests.md @@ -0,0 +1,39 @@ +## Tests + +Cargo can run your tests with the `cargo test` command. Cargo looks for tests +to run in two places: in each of your `src` files and any tests in `tests/`. +Tests in your `src` files should be unit tests, and tests in `tests/` should be +integration-style tests. As such, you’ll need to import your crates into +the files in `tests`. + +Here's an example of running `cargo test` in our project, which currently has +no tests: + +```shell +$ cargo test + Compiling rand v0.1.0 (https://github.com/rust-lang-nursery/rand.git#9f35b8e) + Compiling hello_world v0.1.0 (file:///path/to/project/hello_world) + Running target/test/hello_world-9c2b65bbb79eabce + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured +``` + +If our project had tests, we would see more output with the correct number of +tests. + +You can also run a specific test by passing a filter: + +```shell +$ cargo test foo +``` + +This will run any test with `foo` in its name. + +`cargo test` runs additional checks as well. For example, it will compile any +examples you’ve included and will also test the examples in your +documentation. Please see the [testing guide][testing] in the Rust +documentation for more details. + +[testing]: https://doc.rust-lang.org/book/testing.html diff --git a/src/doc/book/src/02-07-continuous-integration.md b/src/doc/book/src/02-07-continuous-integration.md new file mode 100644 index 00000000000..cc10cfe56ed --- /dev/null +++ b/src/doc/book/src/02-07-continuous-integration.md @@ -0,0 +1,21 @@ +## Continuous integration + +### Travis CI + +To test your project on Travis CI, here is a sample `.travis.yml` file: + +``` +language: rust +rust: + - stable + - beta + - nightly +matrix: + allow_failures: + - rust: nightly +``` + +This will test all three release channels, but any breakage in nightly +will not fail your overall build. Please see the [Travis CI Rust +documentation](https://docs.travis-ci.com/user/languages/rust/) for more +information. diff --git a/src/doc/specifying-dependencies.md b/src/doc/book/src/03-01-specifying-dependencies.md similarity index 96% rename from src/doc/specifying-dependencies.md rename to src/doc/book/src/03-01-specifying-dependencies.md index a4b0c342e34..844b9155d9b 100644 --- a/src/doc/specifying-dependencies.md +++ b/src/doc/book/src/03-01-specifying-dependencies.md @@ -1,4 +1,4 @@ -% Specifying Dependencies +## Specifying Dependencies Your crates can depend on other libraries from [crates.io], `git` repositories, or subdirectories on your local file system. You can also temporarily override the @@ -7,7 +7,7 @@ dependency that you are working on locally. You can have different dependencies for different platforms, and dependencies that are only used during development. Let's take a look at how to do each of these. -# Specifying dependencies from crates.io +### Specifying dependencies from crates.io Cargo is configured to look for dependencies on [crates.io] by default. Only the name and a version string are required in this case. In [the cargo @@ -24,7 +24,7 @@ if we had specified `"^0.1.12"`, which is called a caret requirement. [semver]: https://github.com/steveklabnik/semver#requirements -## Caret requirements +### Caret requirements **Caret requirements** allow SemVer compatible updates to a specified version. An update is allowed if the new version number does not modify the left-most @@ -52,7 +52,7 @@ treat a `0.x.y` release in the same way as a `1.x.y` release: that is, `y` is incremented for bugfixes, and `x` is incremented for new features. As such, Cargo considers a `0.x.y` and `0.x.z` version, where `z > y`, to be compatible. -## Tilde requirements +### Tilde requirements **Tilde requirements** specify a minimal version with some ability to update. If you specify a major, minor, and patch version or only a major and minor @@ -67,7 +67,7 @@ version, then minor- and patch-level changes are allowed. ~1 := >=1.0.0 <2.0.0 ``` -## Wildcard requirements +### Wildcard requirements **Wildcard requirements** allow for any version where the wildcard is positioned. @@ -80,7 +80,7 @@ positioned. 1.2.* := >=1.2.0 <1.3.0 ``` -## Inequality requirements +### Inequality requirements **Inequality requirements** allow manually specifying a version range or an exact version to depend on. @@ -94,12 +94,12 @@ Here are some examples of inequality requirements: = 1.2.3 ``` -## Multiple requirements +### Multiple requirements Multiple version requirements can also be separated with a comma, e.g. `>= 1.2, < 1.5`. -# Specifying dependencies from `git` repositories +### Specifying dependencies from `git` repositories To depend on a library located in a `git` repository, the minimum information you need to specify is the location of the repository with the `git` key: @@ -124,7 +124,7 @@ the latest commit on a branch named `next`: rand = { git = "https://github.com/rust-lang-nursery/rand", branch = "next" } ``` -# Specifying path dependencies +### Specifying path dependencies Over time, our `hello_world` project from [the guide](guide.html) has grown significantly in size! It’s gotten to the point that we probably want to @@ -163,7 +163,7 @@ the dependencies line as well: hello_utils = { path = "hello_utils", version = "0.1.0" } ``` -# Overriding dependencies +### Overriding dependencies There are a number of methods in Cargo to support overriding dependencies and otherwise controlling the dependency graph. These options are typically, though, @@ -194,8 +194,8 @@ stable and will be released on 2017-08-31. Historically some of these scenarios have been solved with [the `[replace]` section][replace-section], but we'll document the `[patch]` section here. -[patch-section]: manifest.html#the-patch-section -[replace-section]: manifest.html#the-replace-section +[patch-section]: 03-02-manifest.html#the-patch-section +[replace-section]: 03-02-manifest.html#the-replace-section ### Testing a bugfix @@ -410,7 +410,7 @@ Note: using a local configuration to override paths will only work for crates that have been published to [crates.io]. You cannot use this feature to tell Cargo how to find local unpublished crates. -# Platform specific dependencies +### Platform specific dependencies Platform-specific dependencies take the same format, but are listed under a @@ -462,7 +462,7 @@ openssl = "1.0.1" native = { path = "native/x86_64" } ``` -# Development dependencies +### Development dependencies You can add a `[dev-dependencies]` section to your `Cargo.toml` whose format is equivalent to `[dependencies]`: @@ -490,7 +490,7 @@ mio = "0.0.1" [crates.io]: https://crates.io/ -# Build dependencies +### Build dependencies You can depend on other Cargo-based crates for use in your build scripts. Dependencies are declared through the `build-dependencies` section of the @@ -509,7 +509,7 @@ itself and its build script are built separately, so their dependencies need not coincide. Cargo is kept simpler and cleaner by using independent dependencies for independent purposes. -# Choosing features +### Choosing features If a package you depend on offers conditional features, you can specify which to use: @@ -523,4 +523,4 @@ features = ["secure-password", "civet"] ``` More information about features can be found in the -[manifest documentation](manifest.html#the-features-section). +[manifest documentation](03-02-manifest.html#the-features-section). diff --git a/src/doc/manifest.md b/src/doc/book/src/03-02-manifest.md similarity index 94% rename from src/doc/manifest.md rename to src/doc/book/src/03-02-manifest.md index 25bdf388ffe..6068bb5a534 100644 --- a/src/doc/manifest.md +++ b/src/doc/book/src/03-02-manifest.md @@ -1,6 +1,6 @@ -% The Manifest Format +## The Manifest Format -# The `[package]` section +### The `[package]` section The first section in a `Cargo.toml` is `[package]`. @@ -13,7 +13,7 @@ authors = ["you@example.com"] All three of these fields are mandatory. -## The `version` field +#### The `version` field Cargo bakes in the concept of [Semantic Versioning](http://semver.org/), so make sure you follow some basic rules: @@ -28,13 +28,13 @@ Versioning](http://semver.org/), so make sure you follow some basic rules: traits, fields, types, functions, methods or anything else. * Use version numbers with three numeric parts such as 1.0.0 rather than 1.0. -## The `build` field (optional) +#### The `build` field (optional) This field specifies a file in the repository which is a [build script][1] for building native code. More information can be found in the build script [guide][1]. -[1]: build-script.html +[1]: 03-05-build-scripts.html ```toml [package] @@ -42,15 +42,15 @@ building native code. More information can be found in the build script build = "build.rs" ``` -## The `documentation` field (optional) +#### The `documentation` field (optional) This field specifies a URL to a website hosting the crate's documentation. If no URL is specified in the manifest file, [crates.io][cratesio] will automatically link your crate to the corresponding [docs.rs][docsrs] page. -Documentation links from specific hosts are blacklisted. Hosts are added -to the blacklist if they are known to not be hosting documentation and are -possibly of malicious intent e.g. ad tracking networks. URLs from the +Documentation links from specific hosts are blacklisted. Hosts are added +to the blacklist if they are known to not be hosting documentation and are +possibly of malicious intent e.g. ad tracking networks. URLs from the following hosts are blacklisted: - rust-ci.org @@ -60,7 +60,7 @@ may be replaced by docs.rs links. [docsrs]: https://docs.rs/ [cratesio]: https://crates.io/ -## The `exclude` and `include` fields (optional) +#### The `exclude` and `include` fields (optional) You can explicitly specify to Cargo that a set of [globs][globs] should be ignored or included for the purposes of packaging and rebuilding a package. The @@ -90,7 +90,7 @@ necessary source files may not be included. [globs]: http://doc.rust-lang.org/glob/glob/struct.Pattern.html -### Migrating to `gitignore`-like pattern matching +#### Migrating to `gitignore`-like pattern matching The current interpretation of these configs is based on UNIX Globs, as implemented in the [`glob` crate](https://crates.io/crates/glob). We want @@ -104,7 +104,7 @@ line in a `gitignore` file. See [the tracking issue](https://github.com/rust-lang/cargo/issues/4268) for more details on the migration. -## The `publish` field (optional) +#### The `publish` field (optional) The `publish` field can be used to prevent a package from being published to a repository by mistake. @@ -115,7 +115,7 @@ repository by mistake. publish = false ``` -## The `workspace` field (optional) +#### The `workspace` field (optional) The `workspace` field can be used to configure the workspace that this package will be a member of. If not specified this will be inferred as the first @@ -129,7 +129,7 @@ workspace = "path/to/root" For more information, see the documentation for the workspace table below. -## Package metadata +#### Package metadata There are a number of optional metadata fields also accepted under the `[package]` section: @@ -187,7 +187,7 @@ travis-ci = { repository = "...", branch = "master" } appveyor = { repository = "...", branch = "master", service = "github" } # GitLab: `repository` is required. `branch` is optional; default is `master` gitlab = { repository = "...", branch = "master" } -# Circle CI: `repository` is required. `branch` is optiona; default is `master` +# Circle CI: `repository` is required. `branch` is optional; default is `master` circle-ci = { repository = "...", branch = "master" } # Is it maintained resolution time: `repository` is required. is-it-maintained-issue-resolution = { repository = "..." } @@ -208,7 +208,7 @@ provide useful information to users of the registry and also influence the search ranking of a crate. It is highly discouraged to omit everything in a published crate. -## The `metadata` table (optional) +#### The `metadata` table (optional) Cargo by default will warn about unused keys in `Cargo.toml` to assist in detecting typos and such. The `package.metadata` table, however, is completely @@ -227,13 +227,13 @@ package-name = "my-awesome-android-app" assets = "path/to/static" ``` -# Dependency sections +### Dependency sections -See the [specifying dependencies page](specifying-dependencies.html) for +See the [specifying dependencies page](03-01-specifying-dependencies.html) for information on the `[dependencies]`, `[dev-dependencies]`, `[build-dependencies]`, and target-specific `[target.*.dependencies]` sections. -# The `[profile.*]` sections +### The `[profile.*]` sections Cargo supports custom configuration of how rustc is invoked through profiles at the top level. Any manifest may declare a profile, but only the top level @@ -305,7 +305,7 @@ codegen-units = 1 panic = 'unwind' ``` -# The `[features]` section +### The `[features]` section Cargo supports features to allow expression of: @@ -366,7 +366,7 @@ default-features = false # do not include the default features, and optionally features = ["secure-password", "civet"] ``` -## Rules +#### Rules The usage of features is subject to a few rules: @@ -388,7 +388,7 @@ Note that it is explicitly allowed for features to not actually activate any optional dependencies. This allows packages to internally enable/disable features without requiring a new dependency. -## Usage in end products +#### Usage in end products One major use-case for this feature is specifying optional features in end-products. For example, the Servo project may want to include optional @@ -403,7 +403,7 @@ $ cargo build --release --features "shumway pdf" Default features could be excluded using `--no-default-features`. -## Usage in packages +#### Usage in packages In most cases, the concept of *optional dependency* in a library is best expressed as a separate package that the top-level application depends on. @@ -430,7 +430,7 @@ In almost all cases, it is an antipattern to use these features outside of high-level packages that are designed for curation. If a feature is optional, it can almost certainly be expressed as a separate package. -# The `[workspace]` section +### The `[workspace]` section Projects can define a workspace which is a set of crates that will all share the same `Cargo.lock` and output directory. The `[workspace]` table can be defined @@ -485,13 +485,14 @@ and also be a member crate of another workspace (contain `package.workspace`). Most of the time workspaces will not need to be dealt with as `cargo new` and `cargo init` will handle workspace configuration automatically. -# The project layout +#TODO: move this to a more appropriate place +### The project layout If your project is an executable, name the main source file `src/main.rs`. If it is a library, name the main source file `src/lib.rs`. Cargo will also treat any files located in `src/bin/*.rs` as executables. If your -executable consist of more than just one source file, you might also use a directory +executable consists of more than just one source file, you might also use a directory inside `src/bin` containing a `main.rs` file which will be treated as an executable with a name of the parent directory. Do note, however, once you add a `[[bin]]` section ([see @@ -519,15 +520,18 @@ integration tests, and benchmarks respectively. *.rs ``` -To structure your code after you've created the files and folders for your project, you should remember to use Rust's module system, which you can read about in [the book](https://doc.rust-lang.org/book/crates-and-modules.html). +To structure your code after you've created the files and folders for your +project, you should remember to use Rust's module system, which you can read +about in [the book](https://doc.rust-lang.org/book/crates-and-modules.html). -# Examples +### Examples Files located under `examples` are example uses of the functionality provided by the library. When compiled, they are placed in the `target/examples` directory. -They can compile either as executables (with a `main()` function) or libraries and pull in the library by using `extern crate `. They are compiled when you run -your tests to protect them from bitrotting. +They can compile either as executables (with a `main()` function) or libraries +and pull in the library by using `extern crate `. They are +compiled when you run your tests to protect them from bitrotting. You can run individual executable examples with the command `cargo run --example `. @@ -540,9 +544,10 @@ name = "foo" crate-type = ["staticlib"] ``` -You can build individual library examples with the command `cargo build --example `. +You can build individual library examples with the command `cargo build +--example `. -# Tests +### Tests When you run `cargo test`, Cargo will: @@ -554,7 +559,7 @@ When you run `cargo test`, Cargo will: * compile and run your library’s [integration tests](#integration-tests); and * compile your library’s examples. -## Integration tests +#### Integration tests Each file in `tests/*.rs` is an integration test. When you run `cargo test`, Cargo will compile each of these files as a separate crate. The crate can link @@ -567,7 +572,7 @@ example, if you want several integration tests to share some code, you can put the shared code in `tests/common/mod.rs` and then put `mod common;` in each of the test files. -# Configuring a target +### Configuring a target All of the `[[bin]]`, `[lib]`, `[[bench]]`, `[[test]]`, and `[[example]]` sections support similar configuration for specifying how a target should be @@ -621,7 +626,7 @@ proc-macro = false harness = true ``` -## The `required-features` field (optional) +#### The `required-features` field (optional) The `required-features` field specifies which features the target needs in order to be built. If any of the required features are not selected, the target will @@ -640,7 +645,7 @@ tools = [] required-features = ["postgres", "tools"] ``` -# Building dynamic or static libraries +#### Building dynamic or static libraries If your project produces a library, you can specify which kind of library to build by explicitly listing the library in your `Cargo.toml`: @@ -661,7 +666,7 @@ includes them. You can read more about the different crate types in the [Rust Reference Manual](https://doc.rust-lang.org/reference/linkage.html) -# The `[patch]` Section +### The `[patch]` Section This section of Cargo.toml can be used to [override dependencies][replace] with other copies. The syntax is similar to the `[dependencies]` section: @@ -695,9 +700,9 @@ technical specification of this feature. Note that the `[patch]` feature will first become available in Rust 1.20, set to be released on 2017-08-31. [RFC 1969]: https://github.com/rust-lang/rfcs/pull/1969 -[replace]: specifying-dependencies.html#overriding-dependencies +[replace]: 03-01-specifying-dependencies.html#overriding-dependencies -# The `[replace]` Section +### The `[replace]` Section This section of Cargo.toml can be used to [override dependencies][replace] with other copies. The syntax is similar to the `[dependencies]` section: @@ -709,7 +714,7 @@ other copies. The syntax is similar to the `[dependencies]` section: ``` Each key in the `[replace]` table is a [package id -specification](pkgid-spec.html) which allows arbitrarily choosing a node in the +specification](03-07-pkgid-spec.html) which allows arbitrarily choosing a node in the dependency graph to override. The value of each key is the same as the `[dependencies]` syntax for specifying dependencies, except that you can't specify features. Note that when a crate is overridden the copy it's overridden diff --git a/src/doc/config.md b/src/doc/book/src/03-03-config.md similarity index 86% rename from src/doc/config.md rename to src/doc/book/src/03-03-config.md index 679bc5f9bc9..03ed5b9f8e9 100644 --- a/src/doc/config.md +++ b/src/doc/book/src/03-03-config.md @@ -1,10 +1,10 @@ -% Configuration +## Configuration This document will explain how Cargo’s configuration system works, as well as available keys or configuration. For configuration of a project through its -manifest, see the [manifest format](manifest.html). +manifest, see the [manifest format](03-02-manifest.html). -# Hierarchical structure +### Hierarchical structure Cargo allows to have local configuration for a particular project or global configuration (like git). Cargo also extends this ability to a hierarchical @@ -21,7 +21,7 @@ With this structure you can specify local configuration per-project, and even possibly check it into version control. You can also specify personal default with a configuration file in your home directory. -# Configuration format +### Configuration format All configuration is currently in the [TOML format][toml] (like the manifest), with simple key-value pairs inside of sections (tables) which all get merged @@ -29,7 +29,7 @@ together. [toml]: https://github.com/toml-lang/toml -# Configuration keys +### Configuration keys All of the following keys are optional, and their defaults are listed as their value unless otherwise noted. @@ -58,19 +58,18 @@ vcs = "none" # For the following sections, $triple refers to any valid target triple, not the # literal string "$triple", and it will apply whenever that target triple is -# being compiled to. 'cfg(...)' refers to the Rust-like `#[cfg]` syntax for +# being compiled to. 'cfg(...)' refers to the Rust-like `#[cfg]` syntax for # conditional compilation. +[target] +# For Cargo builds which do not mention --target, this is the linker +# which is passed to rustc (via `-C linker=`). By default this flag is not +# passed to the compiler. +linker = ".." + [target.$triple] -# This is the linker which is passed to rustc (via `-C linker=`) when the `$triple` -# is being compiled for. By default this flag is not passed to the compiler. +# Similar to the above linker configuration, but this only applies to +# when the `$triple` is being compiled for. linker = ".." -# Same but for the library archiver which is passed to rustc via `-C ar=`. -ar = ".." -# If a runner is provided, compiled targets for the `$triple` will be executed -# by invoking the specified runner executable with actual target as first argument. -# This applies to `cargo run`, `cargo test` and `cargo bench` commands. -# By default compiled targets are executed directly. -runner = ".." # custom flags to pass to all compiler invocations that target $triple # this value overrides build.rustflags when both are present rustflags = ["..", ".."] @@ -120,7 +119,7 @@ rr = "run --release" space_example = ["run", "--release", "--", "\"command list\""] ``` -# Environment variables +### Environment variables Cargo can also be configured through environment variables in addition to the TOML syntax above. For each configuration key above of the form `foo.bar` the @@ -134,4 +133,4 @@ environment variables. In addition to the system above, Cargo recognizes a few other specific [environment variables][env]. -[env]: environment-variables.html +[env]: 03-04-environment-variables.html diff --git a/src/doc/environment-variables.md b/src/doc/book/src/03-04-environment-variables.md similarity index 84% rename from src/doc/environment-variables.md rename to src/doc/book/src/03-04-environment-variables.md index 21274f9f31a..aed2ca58673 100644 --- a/src/doc/environment-variables.md +++ b/src/doc/book/src/03-04-environment-variables.md @@ -1,10 +1,10 @@ -% Environment Variables +## Environment Variables Cargo sets and reads a number of environment variables which your code can detect or override. Here is a list of the variables Cargo sets, organized by when it interacts with them: -# Environment variables Cargo reads +### Environment variables Cargo reads You can override these environment variables to change Cargo's behavior on your system: @@ -29,13 +29,14 @@ system: Note that Cargo will also read environment variables for `.cargo/config` configuration values, as described in [that documentation][config-env] -[config-env]: config.html#environment-variables +[config-env]: 03-03-config.html#environment-variables -# Environment variables Cargo sets for crates +### Environment variables Cargo sets for crates Cargo exposes these environment variables to your crate when it is compiled. Note that this applies for test binaries as well. -To get the value of any of these variables in a Rust program, do this: +To get the value of any of these variables in a Rust program, you can use +the `env!` macro: ``` let version = env!("CARGO_PKG_VERSION"); @@ -57,7 +58,7 @@ let version = env!("CARGO_PKG_VERSION"); * `OUT_DIR` - If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. -# Environment variables Cargo sets for build scripts +### Environment variables Cargo sets for build scripts Cargo sets several environment variables when build scripts are run. Because these variables are not yet set when the build script is compiled, the above example using `env!` won't work @@ -97,14 +98,7 @@ let out_dir = env::var("OUT_DIR").unwrap(); triples can be found in [clang’s own documentation][clang]. * `HOST` - the host triple of the rust compiler. * `NUM_JOBS` - the parallelism specified as the top-level parallelism. This can - be useful to pass a `-j` parameter to a system like `make`. Note - that care should be taken when interpreting this environment - variable. For historical purposes this is still provided but - recent versions of Cargo, for example, do not need to run `make - -j` as it'll automatically happen. Cargo implements its own - [jobserver] and will allow build scripts to inherit this - information, so programs compatible with GNU make jobservers will - already have appropriately configured parallelism. + be useful to pass a `-j` parameter to a system like `make`. * `OPT_LEVEL`, `DEBUG` - values of the corresponding variables for the profile currently being built. * `PROFILE` - `release` for release builds, `debug` for other builds. @@ -114,13 +108,12 @@ let out_dir = env::var("OUT_DIR").unwrap(); resolved to use, passed to the build script so it might use it as well. -[links]: build-script.html#the-links-manifest-key -[profile]: manifest.html#the-profile-sections +[links]: 03-05-build-scripts.html#the-links-manifest-key +[profile]: 03-02-manifest.html#the-profile-sections [configuration]: https://doc.rust-lang.org/reference/attributes.html#conditional-compilation [clang]:http://clang.llvm.org/docs/CrossCompilation.html#target-triple -[jobserver]: http://make.mad-scientist.net/papers/jobserver-implementation/ -# Environment variables Cargo sets for 3rd party subcommands +### Environment variables Cargo sets for 3rd party subcommands Cargo exposes this environment variable to 3rd party subcommands (ie. programs named `cargo-foobar` placed in `$PATH`): diff --git a/src/doc/build-script.md b/src/doc/book/src/03-05-build-scripts.md similarity index 88% rename from src/doc/build-script.md rename to src/doc/book/src/03-05-build-scripts.md index a0bfe0fd669..39f66fbdf9a 100644 --- a/src/doc/build-script.md +++ b/src/doc/book/src/03-05-build-scripts.md @@ -1,4 +1,4 @@ -% Build Script Support +## Build Script Support Some packages need to compile third-party non-Rust code, for example C libraries. Other packages need to link to C libraries which can either be @@ -32,7 +32,7 @@ Some example use cases of the build command are: Each of these use cases will be detailed in full below to give examples of how the build command works. -## Inputs to the Build Script +### Inputs to the Build Script When the build script is run, there are a number of inputs to the build script, all passed in the form of [environment variables][env]. @@ -40,27 +40,27 @@ all passed in the form of [environment variables][env]. In addition to environment variables, the build script’s current directory is the source directory of the build script’s package. -[env]: environment-variables.html +[env]: 03-04-environment-variables.html -## Outputs of the Build Script +### Outputs of the Build Script -All the lines printed to stdout by a build script are written to a file like `target/debug/build//output` (the precise location may depend on your configuration). Any line that starts with `cargo:` is interpreted directly by Cargo. This line must be of the form `cargo:key=value`, like the examples below: +All the lines printed to stdout by a build script are written to a file like +`target/debug/build//output` (the precise location may depend on your +configuration). Any line that starts with `cargo:` is interpreted directly by +Cargo. This line must be of the form `cargo:key=value`, like the examples +below: ```notrust # specially recognized by Cargo cargo:rustc-link-lib=static=foo cargo:rustc-link-search=native=/path/to/foo cargo:rustc-cfg=foo -cargo:rustc-env=FOO=bar # arbitrary user-defined metadata cargo:root=/path/to/foo cargo:libdir=/path/to/foo/lib cargo:include=/path/to/foo/include ``` -On the other hand, lines printed to stderr are written to a file like -`target/debug/build//stderr` but are not interpreted by cargo. - There are a few special keys that Cargo recognizes, some affecting how the crate is built: @@ -77,12 +77,6 @@ crate is built: * `rustc-cfg=FEATURE` indicates that the specified feature will be passed as a `--cfg` flag to the compiler. This is often useful for performing compile-time detection of various features. -* `rustc-env=VAR=VALUE` indicates that the specified environment variable - will be added to the environment which the compiler is run within. - The value can be then retrieved by the `env!` macro in the compiled crate. - This is useful for embedding additional metadata in crate's code, - such as the hash of Git HEAD or the unique identifier of a continuous - integration server. * `rerun-if-changed=PATH` is a path to a file or directory which indicates that the build script should be re-run if it changes (detected by a more-recent last-modified timestamp on the file). Normally build scripts are re-run if @@ -92,21 +86,11 @@ crate is built: of the directory itself (which corresponds to some types of changes within the directory, depending on platform) will trigger a rebuild. To request a re-run on any changes within an entire directory, print a line for the directory and - another line for everything inside it, recursively.) + another line for everything inside it, recursively.) Note that if the build script itself (or one of its dependencies) changes, then it's rebuilt and rerun unconditionally, so `cargo:rerun-if-changed=build.rs` is almost always redundant (unless you want to ignore changes in all other files except for `build.rs`). -* `rerun-if-env-changed=VAR` is the name of an environment variable which - indicates that if the environment variable's value changes the build script - should be rerun. This basically behaves the same as `rerun-if-changed` except - that it works with environment variables instead. Note that the environment - variables here are intended for global environment variables like `CC` and - such, it's not necessary to use this for env vars like `TARGET` that Cargo - sets. Also note that if `rerun-if-env-changed` is printed out then Cargo will - *only* rerun the build script if those environment variables change or if - files printed out by `rerun-if-changed` change. - * `warning=MESSAGE` is a message that will be printed to the main console after a build script has finished running. Warnings are only shown for path dependencies (that is, those you're working on locally), so for example @@ -118,7 +102,7 @@ section. [links]: #the-links-manifest-key -## Build Dependencies +### Build Dependencies Build scripts are also allowed to have dependencies on other Cargo-based crates. Dependencies are declared through the `build-dependencies` section of the @@ -134,7 +118,7 @@ The build script **does not** have access to the dependencies listed in the dependencies will also not be available to the package itself unless explicitly stated as so. -## The `links` Manifest Key +### The `links` Manifest Key In addition to the manifest key `build`, Cargo also supports a `links` manifest key to declare the name of a native library that is being linked to: @@ -173,7 +157,7 @@ Note that metadata is only passed to immediate dependents, not transitive dependents. The motivation for this metadata passing is outlined in the linking to system libraries case study below. -## Overriding Build Scripts +### Overriding Build Scripts If a manifest contains a `links` key, then Cargo supports overriding the build script specified with a custom library. The purpose of this functionality is to @@ -181,7 +165,7 @@ prevent running the build script in question altogether and instead supply the metadata ahead of time. To override a build script, place the following configuration in any acceptable -Cargo [configuration location](config.html). +Cargo [configuration location](03-03-config.html). ```toml [target.x86_64-unknown-linux-gnu.foo] @@ -201,7 +185,7 @@ With this configuration, if a package declares that it links to `foo` then the build script will **not** be compiled or run, and the metadata specified will instead be used. -# Case study: Code generation +### Case study: Code generation Some Cargo packages need to have code generated just before they are compiled for various reasons. Here we’ll walk through a simple example which generates a @@ -286,7 +270,7 @@ the generated file (`hello.rs`) into the crate’s compilation. Using the structure shown here, crates can include any number of generated files from the build script itself. -# Case study: Building some native code +### Case study: Building some native code Sometimes it’s necessary to build some native C or C++ code as part of a package. This is another excellent use case of leveraging the build script to @@ -433,7 +417,7 @@ dependency can be crucial in many situations and even much more concise! We’ve also seen a brief example of how a build script can use a crate as a dependency purely for the build process and not for the crate itself at runtime. -# Case study: Linking to system libraries +### Case study: Linking to system libraries The final case study here will be investigating how a Cargo library links to a system library and how the build script is leveraged to support this use case. @@ -446,7 +430,7 @@ script is again to farm out as much of this as possible to make this as easy as possible for consumers. As an example to follow, let’s take a look at one of [Cargo’s own -dependencies][git2-rs], [libgit2][libgit2]. The C library has a number of +dependencies][git2-rs], [libgit2][libgit2]. This library has a number of constraints: [git2-rs]: https://github.com/alexcrichton/git2-rs/tree/master/libgit2-sys @@ -460,7 +444,7 @@ constraints: * It can be built from source using `cmake`. To visualize what’s going on here, let’s take a look at the manifest for the -relevant Cargo package that links to the native C library. +relevant Cargo package. ```toml [package] @@ -483,14 +467,13 @@ As the above manifests show, we’ve got a `build` script specified, but it’s worth noting that this example has a `links` entry which indicates that the crate (`libgit2-sys`) links to the `git2` native library. -Here we also see that we chose to have the Rust crate have an unconditional -dependency on `libssh2` via the `libssh2-sys` crate, as well as a -platform-specific dependency on `openssl-sys` for \*nix (other variants elided -for now). It may seem a little counterintuitive to express *C dependencies* in -the *Cargo manifest*, but this is actually using one of Cargo’s conventions in -this space. +Here we also see the unconditional dependency on `libssh2` via the +`libssh2-sys` crate, as well as a platform-specific dependency on `openssl-sys` +for \*nix (other variants elided for now). It may seem a little counterintuitive +to express *C dependencies* in the *Cargo manifest*, but this is actually using +one of Cargo’s conventions in this space. -## `*-sys` Packages +### `*-sys` Packages To alleviate linking to system libraries, Cargo has a *convention* of package naming and functionality. Any package named `foo-sys` will provide two major @@ -512,7 +495,7 @@ convention of native-library-related packages: (or building it from source). * These dependencies are easily overridable. -## Building libgit2 +### Building libgit2 Now that we’ve got libgit2’s dependencies sorted out, we need to actually write the build script. We’re not going to look at specific snippets of code here and @@ -549,5 +532,5 @@ doing so that we need to take into account, however: Most of the functionality of this build script is easily refactorable into common dependencies, so our build script isn’t quite as intimidating as this -descriptions! In reality it’s expected that build scripts are quite succinct by +description! In reality it’s expected that build scripts are quite succinct by farming logic such as above to build dependencies. diff --git a/src/doc/crates-io.md b/src/doc/book/src/03-06-crates-io.md similarity index 93% rename from src/doc/crates-io.md rename to src/doc/book/src/03-06-crates-io.md index 0b1cf7f4619..98ed4eef316 100644 --- a/src/doc/crates-io.md +++ b/src/doc/book/src/03-06-crates-io.md @@ -1,4 +1,4 @@ -% Publishing on crates.io +## Publishing on crates.io Once you've got a library that you'd like to share with the world, it's time to publish it on [crates.io]! Publishing a crate is when a specific @@ -8,7 +8,7 @@ Take care when publishing a crate, because a publish is **permanent**. The version can never be overwritten, and the code cannot be deleted. There is no limit to the number of versions which can be published, however. -# Before your first publish +### Before your first publish First thing’s first, you’ll need an account on [crates.io] to acquire an API token. To do so, [visit the home page][crates.io] and log in via a GitHub @@ -21,17 +21,16 @@ $ cargo login abcdefghijklmnopqrstuvwxyz012345 ``` This command will inform Cargo of your API token and store it locally in your -`~/.cargo/credentials` (previously it was `~/.cargo/config`). -Note that this token is a **secret** and should not be shared +`~/.cargo/config`. Note that this token is a **secret** and should not be shared with anyone else. If it leaks for any reason, you should regenerate it immediately. -# Before publishing a new crate +### Before publishing a new crate Keep in mind that crate names on [crates.io] are allocated on a first-come-first- serve basis. Once a crate name is taken, it cannot be used for another crate. -## Packaging a crate +#### Packaging a crate The next step is to package up your crate into a format that can be uploaded to [crates.io]. For this we’ll use the `cargo package` subcommand. This will take @@ -82,7 +81,7 @@ include = [ ] ``` -## Uploading the crate +### Uploading the crate Now that we’ve got a `*.crate` file ready to go, it can be uploaded to [crates.io] with the `cargo publish` command. And that’s it, you’ve now published @@ -96,24 +95,24 @@ If you’d like to skip the `cargo package` step, the `cargo publish` subcommand will automatically package up the local crate if a copy isn’t found already. Be sure to check out the [metadata you can -specify](manifest.html#package-metadata) to ensure your crate can be discovered -more easily! +specify](03-02-manifest.html#package-metadata) to ensure your crate can be +discovered more easily! -# Publishing a new version of an existing crate +### Publishing a new version of an existing crate In order to release a new version, change the `version` value specified in your `Cargo.toml` manifest. Keep in mind [the semver -rules](manifest.html#the-version-field). Then optionally run `cargo package` if +rules](03-02-manifest.html#the-version-field). Then optionally run `cargo package` if you want to inspect the `*.crate` file for the new version before publishing, and run `cargo publish` to upload the new version. -# Managing a crates.io-based crate +### Managing a crates.io-based crate Management of crates is primarily done through the command line `cargo` tool rather than the [crates.io] web interface. For this, there are a few subcommands to manage a crate. -## `cargo yank` +#### `cargo yank` Occasions may arise where you publish a version of a crate that actually ends up being broken for one reason or another (syntax error, forgot to include a file, @@ -137,7 +136,7 @@ goal. Essentially a yank means that all projects with a `Cargo.lock` will not break, while any future `Cargo.lock` files generated will not list the yanked version. -## `cargo owner` +#### `cargo owner` A crate is often developed by more than one person, or the primary maintainer may change over time! The owner of a crate is the only person allowed to publish @@ -169,7 +168,7 @@ The syntax for teams is currently `github:org:team` (see examples above). In order to add a team as an owner one must be a member of that team. No such restriction applies to removing a team as an owner. -## GitHub permissions +### GitHub permissions Team membership is not something GitHub provides simple public access to, and it is likely for you to encounter the following message when working with them: diff --git a/src/doc/pkgid-spec.md b/src/doc/book/src/03-07-pkgid-spec.md similarity index 91% rename from src/doc/pkgid-spec.md rename to src/doc/book/src/03-07-pkgid-spec.md index 11522f48921..6365c397c42 100644 --- a/src/doc/pkgid-spec.md +++ b/src/doc/book/src/03-07-pkgid-spec.md @@ -1,6 +1,6 @@ -% Package ID Specifications +## Package ID Specifications -# Package ID specifications +### Package ID specifications Subcommands of Cargo frequently need to refer to a particular package within a dependency graph for various operations like updating, cleaning, building, etc. @@ -8,7 +8,7 @@ To solve this problem, Cargo supports Package ID Specifications. A specification is a string which is used to uniquely refer to one package within a graph of packages. -## Specification grammar +#### Specification grammar The formal grammar for a Package Id Specification is: @@ -22,7 +22,7 @@ proto := "http" | "git" | ... Here, brackets indicate that the contents are optional. -## Example specifications +#### Example specifications These could all be references to a package `foo` version `1.2.3` from the registry at `crates.io` @@ -36,7 +36,7 @@ registry at `crates.io` | `crates.io/bar#foo:1.2.3` | foo | 1.2.3 | *://crates.io/bar | | `http://crates.io/foo#1.2.3` | foo | 1.2.3 | http://crates.io/foo | -## Brevity of specifications +#### Brevity of specifications The goal of this is to enable both succinct and exhaustive syntaxes for referring to packages in a dependency graph. Ambiguous references may refer to diff --git a/src/doc/source-replacement.md b/src/doc/book/src/03-08-source-replacement.md similarity index 96% rename from src/doc/source-replacement.md rename to src/doc/book/src/03-08-source-replacement.md index 5f5150aff4b..dcb88346d02 100644 --- a/src/doc/source-replacement.md +++ b/src/doc/book/src/03-08-source-replacement.md @@ -1,11 +1,11 @@ -% Replacing sources +## Replacing sources Cargo supports the ability to **replace one source with another** to express strategies along the lines of mirrors or vendoring dependencies. Configuration is currently done through the [`.cargo/config` configuration][config] mechanism, like so: -[config]: config.html +[config]: 03-03-config.html ```toml # The `source` table is where all keys related to source-replacement @@ -49,9 +49,9 @@ patching a dependency or a private registry. Cargo supports patching dependencies through the usage of [the `[replace]` key][replace-section], and private registry support is planned for a future version of Cargo. -[replace-section]: manifest.html#the-replace-section +[replace-section]: 03-02-manifest.html#the-replace-section -## Configuration +### Configuration Configuration of replacement sources is done through [`.cargo/config`][config] and the full set of available keys are: @@ -78,7 +78,7 @@ crates) and can be replaced with: replace-with = 'another-source' ``` -## Registry Sources +### Registry Sources A "registry source" is one that is the same as crates.io itself. That is, it has an index served in a git repository which matches the format of the @@ -88,7 +88,7 @@ then has configuration indicating where to download crates from. Currently there is not an already-available project for setting up a mirror of crates.io. Stay tuned though! -## Local Registry Sources +### Local Registry Sources A "local registry source" is intended to be a subset of another registry source, but available on the local filesystem (aka vendoring). Local registries @@ -106,7 +106,7 @@ Local registries are contained within one directory and contain a number of the same format as the crates.io-index project (populated with just entries for the crates that are present). -## Directory Sources +### Directory Sources A "directory source" is similar to a local registry source where it contains a number of crates available on the local filesystem, suitable for vendoring diff --git a/src/doc/external-tools.md b/src/doc/book/src/03-09-external-tools.md similarity index 93% rename from src/doc/external-tools.md rename to src/doc/book/src/03-09-external-tools.md index 99f9fde6ab2..125016d01b1 100644 --- a/src/doc/external-tools.md +++ b/src/doc/book/src/03-09-external-tools.md @@ -1,4 +1,4 @@ -% External tools +## External tools One of the goals of Cargo is simple integration with third-party tools, like IDEs and other build systems. To make integration easier, Cargo has several @@ -12,8 +12,7 @@ facilities: * support for custom subcommands. -# Information about project structure - +### Information about project structure You can use `cargo metadata` command to get information about project structure and dependencies. The output of the command looks like this: @@ -68,9 +67,9 @@ If you are using Rust, there is [cargo_metadata] crate. [cargo_metadata]: https://crates.io/crates/cargo_metadata -# Information about build +### Information about build -When passing `--message-format=json`, Cargo will output the following +When passing `--message=format=json`, Cargo will output the following information during the build: * compiler errors and warnings, @@ -86,7 +85,7 @@ Information about dependencies in the Makefile-compatible format is stored in the `.d` files alongside the artifacts. -# Custom subcommands. +### Custom subcommands. Cargo is designed to be extensible with new subcommands without having to modify Cargo itself. This is achieved by translating a cargo invocation of the form diff --git a/src/doc/policies.md b/src/doc/book/src/03-10-policies.md similarity index 72% rename from src/doc/policies.md rename to src/doc/book/src/03-10-policies.md index c8b3c1c281b..db71c083ad6 100644 --- a/src/doc/policies.md +++ b/src/doc/book/src/03-10-policies.md @@ -1,11 +1,11 @@ -% Crates.io package policies +## Crates.io package policies In general, these policies are guidelines. Problems are often contextual, and exceptional circumstances sometimes require exceptional measures. We plan to continue to clarify and expand these rules over time as new circumstances arise. If your problem is not described below, consider [sending us an email]. -# Package Ownership +### Package Ownership We have a first-come, first-served policy on crate names. Upon publishing a package, the publisher will be made owner of the package on Crates.io. @@ -15,7 +15,7 @@ existing maintainer can add them as an owner, and the new maintainer can remove them. If necessary, the team may reach out to inactive maintainers and help mediate the process of ownership transfer. -# Removal +### Removal Many questions are specialized instances of a more general form: “Under what circumstances can a package be removed from Crates.io?” @@ -25,30 +25,22 @@ attempt to get into policing what exactly makes a legitimate package. We will do what the law requires us to do, and address flagrant violations of the Rust Code of Conduct. -## Squatting +### Squatting We do not have any policies to define 'squatting', and so will not hand over ownership of a package for that reason. - -## The Law +### The Law For issues such as DMCA violations, trademark and copyright infringement, Crates.io will respect Mozilla Legal’s decisions with regards to content that is hosted. -## Code of Conduct +### Code of Conduct The Rust project has a [Code of Conduct] which governs appropriate conduct for the Rust community. In general, any content on Crates.io that violates the Code -of Conduct may be removed. Here, content can refer to but is not limited to: - -- Package Name -- Package Metadata -- Documentation -- Code - -There are two important, related aspects: +of Conduct may be removed. There are two important, related aspects: - We will not be pro-actively monitoring the site for these kinds of violations, but relying on the community to draw them to our attention. @@ -56,16 +48,5 @@ There are two important, related aspects: cannot be directly answered in the hypothetical sense. All of the details must be taken into consideration in these kinds of situations. -# Security - -Cargo and crates.io are projects that are governed by the Rust Programming -Language Team. Safety is one of the core principles of Rust, and to that end, -we would like to ensure that cargo and crates.io have secure implementations. -To learn more about disclosing security vulnerabilities, please reference the -[Rust Security policy] for more details. - -Thank you for taking the time to responsibly disclose any issues you find. - -[Rust Security policy]: https://www.rust-lang.org/security.html [Code of Conduct]: https://www.rust-lang.org/conduct.html [sending us an email]: mailto:help@crates.io diff --git a/src/doc/book/src/SUMMARY.md b/src/doc/book/src/SUMMARY.md new file mode 100644 index 00000000000..8b2e4cfbe72 --- /dev/null +++ b/src/doc/book/src/SUMMARY.md @@ -0,0 +1,25 @@ +# Summary + +* [Getting Started](getting-started.md) + * [Installation](01-01-installation.md) + * [First steps with Cargo](01-02-first-steps.md) +* [Guide](guide.md) + * [Why Cargo exists](02-01-why-cargo-exists.md) + * [Creating a new project](02-02-creating-a-new-project.md) + * [Working on an existing Cargo project](02-03-working-on-an-existing-project.md) + * [Dependencies](02-04-dependencies.md) + * [Project layout](02-05-project-layout.md) + * [Tests](02-06-tests.md) + * [Continuous Integration](02-07-continuous-integration.md) +* [Cargo In Depth](cargo-in-depth.md) + * [Specifying Dependencies](03-01-specifying-dependencies.md) + * [Cargo.toml Format](03-02-manifest.md) + * [Configuration](03-03-config.md) + * [Environment Variables](03-04-environment-variables.md) + * [Build Scripts](03-05-build-scripts.md) + * [Publishing on crates.io](03-06-crates-io.md) + * [Package ID specs](03-07-pkgid-spec.md) + * [Source Replacement](03-08-source-replacement.md) + * [External Tools](03-09-external-tools.md) + * [Policies](03-10-policies.md) +* [FAQ](faq.md) diff --git a/src/doc/book/src/cargo-in-depth.md b/src/doc/book/src/cargo-in-depth.md new file mode 100644 index 00000000000..bdaee585120 --- /dev/null +++ b/src/doc/book/src/cargo-in-depth.md @@ -0,0 +1,4 @@ +## Cargo In Depth + +* [Specifying Dependencies](03-01-specifying-dependencies.html) +* [Cargo.toml Format](03-02-manifest.html) diff --git a/src/doc/faq.md b/src/doc/book/src/faq.md similarity index 90% rename from src/doc/faq.md rename to src/doc/book/src/faq.md index cf92bbe2cc4..f2da9f39717 100644 --- a/src/doc/faq.md +++ b/src/doc/book/src/faq.md @@ -1,6 +1,6 @@ -% Frequently Asked Questions +## Frequently Asked Questions -# Is the plan to use GitHub as a package repository? +### Is the plan to use GitHub as a package repository? No. The plan for Cargo is to use [crates.io], like npm or Rubygems do with npmjs.org and rubygems.org. @@ -9,7 +9,7 @@ We plan to support git repositories as a source of packages forever, because they can be used for early development and temporary patches, even when people use the registry as the primary source of packages. -# Why build crates.io rather than use GitHub as a registry? +### Why build crates.io rather than use GitHub as a registry? We think that it’s very important to support multiple ways to download packages, including downloading from GitHub and copying packages into @@ -42,7 +42,7 @@ languages include: down fast. Also remember that not everybody has a high-speed, low-latency Internet connection. -# Will Cargo work with C code (or other languages)? +### Will Cargo work with C code (or other languages)? Yes! @@ -50,12 +50,12 @@ Cargo handles compiling Rust code, but we know that many Rust projects link against C code. We also know that there are decades of tooling built up around compiling languages other than Rust. -Our solution: Cargo allows a package to [specify a script](build-script.html) +Our solution: Cargo allows a package to [specify a script](03-05-build-scripts.html) (written in Rust) to run before invoking `rustc`. Rust is leveraged to implement platform-specific configuration and refactor out common build functionality among packages. -# Can Cargo be used inside of `make` (or `ninja`, or ...) +### Can Cargo be used inside of `make` (or `ninja`, or ...) Indeed. While we intend Cargo to be useful as a standalone way to compile Rust projects at the top-level, we know that some people will @@ -67,23 +67,23 @@ have some work to do on those fronts, but using Cargo in the context of conventional scripts is something we designed for from the beginning and will continue to prioritize. -# Does Cargo handle multi-platform projects or cross-compilation? +### Does Cargo handle multi-platform projects or cross-compilation? Rust itself provides facilities for configuring sections of code based on the platform. Cargo also supports [platform-specific dependencies][target-deps], and we plan to support more per-platform configuration in `Cargo.toml` in the future. -[target-deps]: manifest.html#the-dependencies-section +[target-deps]: 03-02-manifest.html#the-dependencies-section In the longer-term, we’re looking at ways to conveniently cross-compile projects using Cargo. -# Does Cargo support environments, like `production` or `test`? +### Does Cargo support environments, like `production` or `test`? We support environments through the use of [profiles][profile] to support: -[profile]: manifest.html#the-profile-sections +[profile]: 03-02-manifest.html#the-profile-sections * environment-specific flags (like `-g --opt-level=0` for development and `--opt-level=3` for production). @@ -91,7 +91,7 @@ We support environments through the use of [profiles][profile] to support: * environment-specific `#[cfg]` * a `cargo test` command -# Does Cargo work on Windows? +### Does Cargo work on Windows? Yes! @@ -101,7 +101,7 @@ issue][3]. [3]: https://github.com/rust-lang/cargo/issues -# Why do binaries have `Cargo.lock` in version control, but not libraries? +### Why do binaries have `Cargo.lock` in version control, but not libraries? The purpose of a `Cargo.lock` is to describe the state of the world at the time of a successful build. It is then used to provide deterministic builds across @@ -128,7 +128,7 @@ In other words, libraries specify semver requirements for their dependencies but cannot see the full picture. Only end products like binaries have a full picture to decide what versions of dependencies should be used. -# Can libraries use `*` as a version for their dependencies? +### Can libraries use `*` as a version for their dependencies? **As of January 22nd, 2016, [crates.io] rejects all packages (not just libraries) with wildcard dependency constraints.** @@ -138,7 +138,7 @@ of `*` says “This will work with every version ever,” which is never going to be true. Libraries should always specify the range that they do work with, even if it’s something as general as “every 1.x.y version.” -# Why `Cargo.toml`? +### Why `Cargo.toml`? As one of the most frequent interactions with Cargo, the question of why the configuration file is named `Cargo.toml` arises from time to time. The leading @@ -156,7 +156,7 @@ but others were accidentally forgotten. [crates.io]: https://crates.io/ -# How can Cargo work offline? +### How can Cargo work offline? Cargo is often used in situations with limited or no network access such as airplanes, CI environments, or embedded in large production deployments. Users @@ -190,4 +190,4 @@ shouldn't be necessary. For more information about vendoring, see documentation on [source replacement][replace]. -[replace]: source-replacement.html +[replace]: 03-08-source-replacement.html diff --git a/src/doc/favicon.ico b/src/doc/book/src/favicon.ico similarity index 100% rename from src/doc/favicon.ico rename to src/doc/book/src/favicon.ico diff --git a/src/doc/book/src/getting-started.md b/src/doc/book/src/getting-started.md new file mode 100644 index 00000000000..042f374b3bb --- /dev/null +++ b/src/doc/book/src/getting-started.md @@ -0,0 +1,4 @@ +## Getting started + +* [Installation](01-01-installation.html) +* [First steps with Cargo](01-02-first-steps.html) diff --git a/src/doc/book/src/guide.md b/src/doc/book/src/guide.md new file mode 100644 index 00000000000..1bf6af2c477 --- /dev/null +++ b/src/doc/book/src/guide.md @@ -0,0 +1,21 @@ +## Cargo Guide + +Welcome to the Cargo guide. This guide will give you all that you need to know +about how to use Cargo to develop Rust projects. + +* [Why Cargo exists](02-01-why-cargo-exists.html) +* [Creating a new project](02-02-creating-a-new-project.html) +* [Working on an existing Cargo project](02-03-working-on-an-existing-project.html) +* [Dependencies](02-04-dependencies.html) +* [Project layout](02-05-project-layout.html) +* [Tests](02-06-tests.html) +* [Continuous Integration](02-07-continuous-integration.html) + +### Further reading + +Now that you have an overview of how to use cargo and have created your first crate, +you may be interested in: + +* [Publishing your crate on crates.io](03-06-crates-io.html) +* [Reading about all the possible ways of specifying dependencies](03-01-specifying-dependencies.html) +* [Learning more details about what you can specify in your `Cargo.toml` manifest](03-02-manifest.html) diff --git a/src/doc/images/Cargo-Logo-Small.png b/src/doc/book/src/images/Cargo-Logo-Small.png similarity index 100% rename from src/doc/images/Cargo-Logo-Small.png rename to src/doc/book/src/images/Cargo-Logo-Small.png diff --git a/src/doc/images/auth-level-acl.png b/src/doc/book/src/images/auth-level-acl.png similarity index 100% rename from src/doc/images/auth-level-acl.png rename to src/doc/book/src/images/auth-level-acl.png diff --git a/src/doc/images/forkme.png b/src/doc/book/src/images/forkme.png similarity index 100% rename from src/doc/images/forkme.png rename to src/doc/book/src/images/forkme.png diff --git a/src/doc/images/org-level-acl.png b/src/doc/book/src/images/org-level-acl.png similarity index 100% rename from src/doc/images/org-level-acl.png rename to src/doc/book/src/images/org-level-acl.png diff --git a/src/doc/footer.html b/src/doc/footer.html deleted file mode 100644 index c2eff8f40dc..00000000000 --- a/src/doc/footer.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/src/doc/guide.md b/src/doc/guide.md deleted file mode 100644 index f6437ab50fe..00000000000 --- a/src/doc/guide.md +++ /dev/null @@ -1,419 +0,0 @@ -% Cargo Guide - -Welcome to the Cargo guide. This guide will give you all that you need to know -about how to use Cargo to develop Rust projects. - -# Why Cargo exists - -Cargo is a tool that allows Rust projects to declare their various -dependencies and ensure that you’ll always get a repeatable build. - -To accomplish this goal, Cargo does four things: - -* Introduces two metadata files with various bits of project information. -* Fetches and builds your project’s dependencies. -* Invokes `rustc` or another build tool with the correct parameters to build your project. -* Introduces conventions to make working with Rust projects easier. - -# Creating a new project - -To start a new project with Cargo, use `cargo new`: - -```shell -$ cargo new hello_world --bin -``` - -We’re passing `--bin` because we’re making a binary program: if we -were making a library, we’d leave it off. This also initializes a new `git` -repository by default. If you don't want it to do that, pass `--vcs none`. - -Let’s check out what Cargo has generated for us: - -```shell -$ cd hello_world -$ tree . -. -├── Cargo.toml -└── src - └── main.rs - -1 directory, 2 files -``` - -If we had just used `cargo new hello_world` without the `--bin` flag, then -we would have a `lib.rs` instead of a `main.rs`. For now, however, this is all -we need to get started. First, let’s check out `Cargo.toml`: - -```toml -[package] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] -``` - -This is called a **manifest**, and it contains all of the metadata that Cargo -needs to compile your project. - -Here’s what’s in `src/main.rs`: - -``` -fn main() { - println!("Hello, world!"); -} -``` - -Cargo generated a “hello world” for us. Let’s compile it: - -
$ cargo build
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
- -And then run it: - -```shell -$ ./target/debug/hello_world -Hello, world! -``` - -We can also use `cargo run` to compile and then run it, all in one step (You -won't see the `Compiling` line if you have not made any changes since you last -compiled): - -
$ cargo run
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
-   Running `target/debug/hello_world`
-Hello, world!
- -You’ll now notice a new file, `Cargo.lock`. It contains information about our -dependencies. Since we don’t have any yet, it’s not very interesting. - -Once you’re ready for release, you can use `cargo build --release` to compile your files with optimizations turned on: - -
$ cargo build --release
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
- -`cargo build --release` puts the resulting binary in -`target/release` instead of `target/debug`. - -Compiling in debug mode is the default for development-- compilation time is -shorter since the compiler doesn't do optimizations, but the code will run -slower. Release mode takes longer to compile, but the code will run faster. - -# Working on an existing Cargo project - -If you download an existing project that uses Cargo, it’s really easy -to get going. - -First, get the project from somewhere. In this example, we’ll use `rand` -cloned from its repository on GitHub: - -```sh -$ git clone https://github.com/rust-lang-nursery/rand.git -$ cd rand -``` - -To build, use `cargo build`: - -
$ cargo build
-   Compiling rand v0.1.0 (file:///path/to/project/rand)
- -This will fetch all of the dependencies and then build them, along with the -project. - -# Adding dependencies from crates.io - -[crates.io] is the Rust community's central repository that serves -as a location to discover and download packages. `cargo` is configured to use -it by default to find requested packages. - -To depend on a library hosted on [crates.io], add it to your `Cargo.toml`. - -[crates.io]: https://crates.io/ - -## Adding a dependency - -If your `Cargo.toml` doesn't already have a `[dependencies]` section, add that, -then list the crate name and version that you would like to use. This example -adds a dependency of the `time` crate: - -```toml -[dependencies] -time = "0.1.12" -``` - -The version string is a [semver] version requirement. The [specifying -dependencies](specifying-dependencies.html) docs have more information about -the options you have here. - -[semver]: https://github.com/steveklabnik/semver#requirements - -If we also wanted to add a dependency on the `regex` crate, we would not need -to add `[dependencies]` for each crate listed. Here's what your whole -`Cargo.toml` file would look like with dependencies on the `time` and `regex` -crates: - -```toml -[package] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] - -[dependencies] -time = "0.1.12" -regex = "0.1.41" -``` - -Re-run `cargo build`, and Cargo will fetch the new dependencies and all of -their dependencies, compile them all, and update the `Cargo.lock`: - -
$ cargo build
-    Updating registry `https://github.com/rust-lang/crates.io-index`
- Downloading memchr v0.1.5
- Downloading libc v0.1.10
- Downloading regex-syntax v0.2.1
- Downloading memchr v0.1.5
- Downloading aho-corasick v0.3.0
- Downloading regex v0.1.41
-   Compiling memchr v0.1.5
-   Compiling libc v0.1.10
-   Compiling regex-syntax v0.2.1
-   Compiling memchr v0.1.5
-   Compiling aho-corasick v0.3.0
-   Compiling regex v0.1.41
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
- -Our `Cargo.lock` contains the exact information about which revision of all of -these dependencies we used. - -Now, if `regex` gets updated, we will still build with the same revision until -we choose to `cargo update`. - -You can now use the `regex` library using `extern crate` in `main.rs`. - -``` -extern crate regex; - -use regex::Regex; - -fn main() { - let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); - println!("Did our date match? {}", re.is_match("2014-01-01")); -} -``` - -Running it will show: - -
$ cargo run
-     Running `target/hello_world`
-Did our date match? true
- -# Project layout - -Cargo uses conventions for file placement to make it easy to dive into a new -Cargo project: - -```shell -. -├── Cargo.lock -├── Cargo.toml -├── benches -│   └── large-input.rs -├── examples -│   └── simple.rs -├── src -│   ├── bin -│   │   └── another_executable.rs -│   ├── lib.rs -│   └── main.rs -└── tests - └── some-integration-tests.rs -``` - -* `Cargo.toml` and `Cargo.lock` are stored in the root of your project. -* Source code goes in the `src` directory. -* The default library file is `src/lib.rs`. -* The default executable file is `src/main.rs`. -* Other executables can be placed in `src/bin/*.rs`. -* Integration tests go in the `tests` directory (unit tests go in each file they're testing). -* Examples go in the `examples` directory. -* Benchmarks go in the `benches` directory. - -These are explained in more detail in the [manifest -description](manifest.html#the-project-layout). - -# Cargo.toml vs Cargo.lock - -`Cargo.toml` and `Cargo.lock` serve two different purposes. Before we talk -about them, here’s a summary: - -* `Cargo.toml` is about describing your dependencies in a broad sense, and is written by you. -* `Cargo.lock` contains exact information about your dependencies. It is maintained by Cargo and should not be manually edited. - -If you’re building a library that other projects will depend on, put -`Cargo.lock` in your `.gitignore`. If you’re building an executable like a -command-line tool or an application, check `Cargo.lock` into `git`. If you're -curious about why that is, see ["Why do binaries have `Cargo.lock` in version -control, but not libraries?" in the -FAQ](faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries). - -Let’s dig in a little bit more. - -`Cargo.toml` is a **manifest** file in which we can specify a bunch of -different metadata about our project. For example, we can say that we depend -on another project: - -```toml -[package] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] - -[dependencies] -rand = { git = "https://github.com/rust-lang-nursery/rand.git" } -``` - -This project has a single dependency, on the `rand` library. We’ve stated in -this case that we’re relying on a particular Git repository that lives on -GitHub. Since we haven’t specified any other information, Cargo assumes that -we intend to use the latest commit on the `master` branch to build our project. - -Sound good? Well, there’s one problem: If you build this project today, and -then you send a copy to me, and I build this project tomorrow, something bad -could happen. There could be more commits to `rand` in the meantime, and my -build would include new commits while yours would not. Therefore, we would -get different builds. This would be bad because we want reproducible builds. - -We could fix this problem by putting a `rev` line in our `Cargo.toml`: - -```toml -[dependencies] -rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" } -``` - -Now our builds will be the same. But there’s a big drawback: now we have to -manually think about SHA-1s every time we want to update our library. This is -both tedious and error prone. - -Enter the `Cargo.lock`. Because of its existence, we don’t need to manually -keep track of the exact revisions: Cargo will do it for us. When we have a -manifest like this: - -```toml -[package] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] - -[dependencies] -rand = { git = "https://github.com/rust-lang-nursery/rand.git" } -``` - -Cargo will take the latest commit and write that information out into our -`Cargo.lock` when we build for the first time. That file will look like this: - -```toml -[root] -name = "hello_world" -version = "0.1.0" -dependencies = [ - "rand 0.1.0 (git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9)", -] - -[[package]] -name = "rand" -version = "0.1.0" -source = "git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9" - -``` - -You can see that there’s a lot more information here, including the exact -revision we used to build. Now when you give your project to someone else, -they’ll use the exact same SHA, even though we didn’t specify it in our -`Cargo.toml`. - -When we’re ready to opt in to a new version of the library, Cargo can -re-calculate the dependencies and update things for us: - -```shell -$ cargo update # updates all dependencies -$ cargo update -p rand # updates just “rand” -``` - -This will write out a new `Cargo.lock` with the new version information. Note -that the argument to `cargo update` is actually a -[Package ID Specification](pkgid-spec.html) and `rand` is just a short -specification. - -# Tests - -Cargo can run your tests with the `cargo test` command. Cargo looks for tests -to run in two places: in each of your `src` files and any tests in `tests/`. -Tests in your `src` files should be unit tests, and tests in `tests/` should be -integration-style tests. As such, you’ll need to import your crates into -the files in `tests`. - -Here's an example of running `cargo test` in our project, which currently has -no tests: - -
$ cargo test
-   Compiling rand v0.1.0 (https://github.com/rust-lang-nursery/rand.git#9f35b8e)
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
-     Running target/test/hello_world-9c2b65bbb79eabce
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
-
- -If our project had tests, we would see more output with the correct number of -tests. - -You can also run a specific test by passing a filter: - -
$ cargo test foo
-
- -This will run any test with `foo` in its name. - -`cargo test` runs additional checks as well. For example, it will compile any -examples you’ve included and will also test the examples in your -documentation. Please see the [testing guide][testing] in the Rust -documentation for more details. - -[testing]: https://doc.rust-lang.org/book/testing.html - -## Travis CI - -To test your project on Travis CI, here is a sample `.travis.yml` file: - -``` -language: rust -rust: - - stable - - beta - - nightly -matrix: - allow_failures: - - rust: nightly -``` - -This will test all three release channels, but any breakage in nightly -will not fail your overall build. Please see the [Travis CI Rust -documentation](https://docs.travis-ci.com/user/languages/rust/) for more -information. - -# Further reading - -Now that you have an overview of how to use cargo and have created your first crate, you may be interested in: - -* [Publishing your crate on crates.io](crates-io.html) -* [Reading about all the possible ways of specifying dependencies](specifying-dependencies.html) -* [Learning more details about what you can specify in your `Cargo.toml` manifest](manifest.html) - -Even more topics are available in the Docs menu at the top! diff --git a/src/doc/header.html b/src/doc/header.html deleted file mode 100644 index 23395f47336..00000000000 --- a/src/doc/header.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - -
diff --git a/src/doc/html-headers.html b/src/doc/html-headers.html deleted file mode 100644 index 80ad896f3f0..00000000000 --- a/src/doc/html-headers.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/doc/images/circle-with-i.png b/src/doc/images/circle-with-i.png deleted file mode 100644 index ef105af8667..00000000000 Binary files a/src/doc/images/circle-with-i.png and /dev/null differ diff --git a/src/doc/images/noise.png b/src/doc/images/noise.png deleted file mode 100644 index 6b748b5db3f..00000000000 Binary files a/src/doc/images/noise.png and /dev/null differ diff --git a/src/doc/images/search.png b/src/doc/images/search.png deleted file mode 100644 index 6cb18672adc..00000000000 Binary files a/src/doc/images/search.png and /dev/null differ diff --git a/src/doc/index.md b/src/doc/index.md deleted file mode 100644 index d17249d00f7..00000000000 --- a/src/doc/index.md +++ /dev/null @@ -1,88 +0,0 @@ -% Cargo, Rust’s Package Manager - -# Installing - -The easiest way to get Cargo is to get the current stable release of Rust by -using the `rustup` script: - -```shell -$ curl -sSf https://static.rust-lang.org/rustup.sh | sh -``` - -This will get you the current stable release of Rust for your platform along -with the latest Cargo. - -If you are on Windows, you can directly download the latest 32bit ([Rust](https://static.rust-lang.org/dist/rust-1.0.0-i686-pc-windows-gnu.msi) -and [Cargo](https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-windows-gnu.tar.gz)) or 64bit ([Rust](https://static.rust-lang.org/dist/rust-1.0.0-x86_64-pc-windows-gnu.msi) and [Cargo](https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-pc-windows-gnu.tar.gz)) Rust stable releases or Cargo nightlies. - -Alternatively, you can build Cargo from source. - -# Let’s get started - -To start a new project with Cargo, use `cargo new`: - -```shell -$ cargo new hello_world --bin -``` - -We’re passing `--bin` because we’re making a binary program: if we -were making a library, we’d leave it off. - -Let’s check out what Cargo has generated for us: - -```shell -$ cd hello_world -$ tree . -. -├── Cargo.toml -└── src - └── main.rs - -1 directory, 2 files -``` - -This is all we need to get started. First, let’s check out `Cargo.toml`: - -```toml -[package] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] -``` - -This is called a **manifest**, and it contains all of the metadata that Cargo -needs to compile your project. - -Here’s what’s in `src/main.rs`: - -``` -fn main() { - println!("Hello, world!"); -} -``` - -Cargo generated a “hello world” for us. Let’s compile it: - -
$ cargo build
-   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
- -And then run it: - -```shell -$ ./target/debug/hello_world -Hello, world! -``` - -We can also use `cargo run` to compile and then run it, all in one step: - -
$ cargo run
-     Fresh hello_world v0.1.0 (file:///path/to/project/hello_world)
-   Running `target/hello_world`
-Hello, world!
- -# Going further - -For more details on using Cargo, check out the [Cargo Guide](guide.html) diff --git a/src/doc/javascripts/all.js b/src/doc/javascripts/all.js deleted file mode 100644 index 3fb0eef24c6..00000000000 --- a/src/doc/javascripts/all.js +++ /dev/null @@ -1,40 +0,0 @@ -//= require_tree . - -Prism.languages.toml = { - // https://github.com/LeaVerou/prism/issues/307 - 'comment': [{ - pattern: /(^[^"]*?("[^"]*?"[^"]*?)*?[^"\\]*?)(\/\*[\w\W]*?\*\/|(^|[^:])#.*?(\r?\n|$))/g, - lookbehind: true - }], - 'string': /("|')(\\?.)*?\1/g, - 'number': /\d+/, - 'boolean': /true|false/, - 'toml-section': /\[.*\]/, - 'toml-key': /[\w-]+/ -}; - -$(function() { - var pres = document.querySelectorAll('pre.rust'); - for (var i = 0; i < pres.length; i++) { - pres[i].className += ' language-rust'; - } - - // Toggles docs menu - $('button.dropdown, a.dropdown').click(function(el, e) { - $(this).toggleClass('active').siblings('ul').toggleClass('open'); - - return false; - }); - - // A click in the page anywhere but in the menu will turn the menu off - $(document).on('click', function(e) { - // Checks to make sure the click did not come from inside dropdown menu - // if it doesn't we close the menu - // else, we do nothing and just follow the link - if (!$(e.target).closest('ul.dropdown').length) { - var toggles = $('button.dropdown.active, a.dropdown.active'); - toggles.toggleClass('active').siblings('ul').toggleClass('open'); - - } - }); -}); diff --git a/src/doc/javascripts/prism.js b/src/doc/javascripts/prism.js deleted file mode 100644 index 13c24078300..00000000000 --- a/src/doc/javascripts/prism.js +++ /dev/null @@ -1,6 +0,0 @@ -/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript */ -self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{};var Prism=function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{encode:function(e){return e instanceof n?new n(e.type,t.util.encode(e.content),e.alias):"Array"===t.util.type(e)?e.map(t.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(d instanceof a)){c.lastIndex=0;var m=c.exec(d);if(m){u&&(f=m[1].length);var y=m.index-1+f,m=m[0].slice(f),v=m.length,k=y+v,b=d.slice(0,y+1),w=d.slice(k+1),N=[p,1];b&&N.push(b);var O=new a(l,g?t.tokenize(m,g):m,h);N.push(O),w&&N.push(w),Array.prototype.splice.apply(r,N)}}}}}return r},hooks:{all:{},add:function(e,n){var a=t.hooks.all;a[e]=a[e]||[],a[e].push(n)},run:function(e,n){var a=t.hooks.all[e];if(a&&a.length)for(var r,i=0;r=a[i++];)r(n)}}},n=t.Token=function(e,t,n){this.type=e,this.content=t,this.alias=n};if(n.stringify=function(e,a,r){if("string"==typeof e)return e;if("[object Array]"==Object.prototype.toString.call(e))return e.map(function(t){return n.stringify(t,a,e)}).join("");var i={type:e.type,content:n.stringify(e.content,a,r),tag:"span",classes:["token",e.type],attributes:{},language:a,parent:r};if("comment"==i.type&&(i.attributes.spellcheck="true"),e.alias){var l="Array"===t.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(i.classes,l)}t.hooks.run("wrap",i);var o="";for(var s in i.attributes)o+=s+'="'+(i.attributes[s]||"")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'" '+o+">"+i.content+""},!self.document)return self.addEventListener?(self.addEventListener("message",function(e){var n=JSON.parse(e.data),a=n.language,r=n.code;self.postMessage(JSON.stringify(t.util.encode(t.tokenize(r,t.languages[a])))),self.close()},!1),self.Prism):self.Prism;var a=document.getElementsByTagName("script");return a=a[a.length-1],a&&(t.filename=a.src,document.addEventListener&&!a.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)),self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism);; -Prism.languages.markup={comment://g,prolog:/<\?.+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/\&#?[\da-z]{1,8};/gi},Prism.hooks.add("wrap",function(t){"entity"===t.type&&(t.attributes.title=t.content.replace(/&/,"&"))});; -Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*{))/gi,inside:{punctuation:/[;:]/g}},url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\};]*(?=\s*\{)/g,property:/(\b|\B)[\w-]+(?=\s*:)/gi,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,punctuation:/[\{\};:]/g,"function":/[-a-z0-9]+(?=\()/gi},Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/[\w\W]*?<\/style>/gi,inside:{tag:{pattern:/|<\/style>/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});; -Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//g,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*?(\r?\n|$)/g,lookbehind:!0}],string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/gi,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,"function":{pattern:/[a-z0-9_]+\(/gi,inside:{punctuation:/\(/}},number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};; -Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/g,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g}),Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:!0}}),Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/[\w\W]*?<\/script>/gi,inside:{tag:{pattern:/|<\/script>/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}});; diff --git a/src/doc/stylesheets/all.css b/src/doc/stylesheets/all.css deleted file mode 100644 index 46b0343ea8a..00000000000 --- a/src/doc/stylesheets/all.css +++ /dev/null @@ -1,291 +0,0 @@ -html { - background: url("../images/noise.png"); - background-color: #3b6837; -} - -main, #header { width: 900px; } - -* { - box-sizing: border-box; -} - -body { - display: -webkit-flex; - display: flex; - -webkit-flex-direction: column; - flex-direction: column; - -webkit-align-items: center; - align-items: center; - font-family: sans-serif; - font-size: 16px; -} - -a { color: #00ac5b; text-decoration: none; } -a:hover { color: #00793f; } - -h1 { - font-size: 24px; - margin: 20px 0 10px 0; - font-weight: bold; - color: #b64790; -} - -h1 code:not(.highlight) { - color: #d9a700; - vertical-align: bottom; -} -h1 a, h2 a { color: #b64790; text-decoration: none; } -h1:hover a, h2:hover a { color: #A03D7E; } -h1:hover a:after, -h2:hover a:after { content: '\2002\00a7\2002'; } -:target { background: rgba(239, 242, 178, 1); padding: 5px; } - -h1.title { /* style rustdoc-generated title */ - width: 100%; - padding: 40px 20px 40px 60px; - background-color: #edebdd; - margin-bottom: 20px; - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - -ms-border-radius: 5px; - border-radius: 5px; - margin: 0; - color: #383838; - font-size: 2em; - background-image: url(../images/circle-with-i.png); - background-repeat: no-repeat; - background-position: 20px center; -} - -h2 { - font-size: 18px; - margin: 15px 0 5px 0; - color: #b64790; - font-weight: bold; -} - -h2 code:not(.highlight) { color: #d9a700; } - -code:not(.highlight) { - font-family: monospace; - color: #b64790; -} - -main { - display: -webkit-flex; - display: flex; - -webkit-flex-direction: column; - flex-direction: column; - - width: 100%; - max-width: 900px; - margin-bottom: 10px; - - background-color: #f9f7ec; - padding: 15px; - - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - -ms-border-radius: 10px; - border-radius: 10px; - box-shadow: 0px 0px 5px 2px #3b6837; - border: 5px solid #62865f; - color: #383838; -} - -main > p:first-child { - font-weight: 500; - margin-top: 3px; - padding-bottom: 15px; - border-bottom: 1px solid #62865f; - text-align: center; -} - -main p:first-child a { color: #3b6837; } -main p:first-child a:hover { color: #62865f; } - -main p, main ul { - /* color: #3b6837; */ - margin: 10px 0; - line-height: 150%; -} - -main ul { margin-left: 20px; } -main li { list-style-type: disc; } -main strong { font-weight: bold; } - -img.logo { - align-self: center; - margin-bottom: 10px; -} - -pre { - padding: 10px; - margin: 10px 0; - /* border: 1px solid #cad0d0; */ - border-radius: 4px; - max-width: calc(100vw - 45px); - overflow-x: auto; - - background: #383838 !important; - color: white; - padding: 20px; - - /* override prism.js styles */ - font-size: 1em !important; - border: none !important; - box-shadow: none !important; - text-shadow: none !important; -} - -pre code { - text-shadow: none !important; -} - -footer { - padding: 40px; - width: 900px; -} -footer a { - color: white; -} -footer a:hover { - color: #e6e6e6; -} -footer .sep, #header .sep { color: #284725; } -footer .sep { margin: 0 10px; } -#header .sep { margin-left: 10px; } - -.headerlink { - display: none; - text-decoration: none; -} -.fork-me { - position:absolute; - top:0; - right:0; -} - -.token.toml-section { color: #CB4B16; } -.token.toml-key { color: #268BD2; } - -/* Rust code highlighting */ -pre.rust .kw { color: #8959A8; } -pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; } -pre.rust .number, pre.rust .string { color: #718C00; } -pre.rust .self, pre.rust .boolval, pre.rust .prelude-val, -pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; } -pre.rust .comment { color: #8E908C; } -pre.rust .doccomment { color: #4D4D4C; } -pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; } -pre.rust .lifetime { color: #B76514; } -code span.s1 { color: #2AA198; } - -table th { border-bottom: 1px solid black; } -table td, table th { padding: 5px 10px; } - -#header { - color: white; - position: relative; - height: 100px; - display: -webkit-flex; - display: flex; - -webkit-align-items: center; - align-items: center; -} -#header h1 { font-size: 2em; } -#header a, #header h1 { color: white; text-decoration: none; } -#header a:hover { color: #d9d9d9; } - -#header input.search { - border: none; - color: black; - outline: 0; - margin-left: 30px; - padding: 5px 5px 5px 25px; - background-image: url(../images/search.png); - background-repeat: no-repeat; - background-position: 6px 6px; - -webkit-border-radius: 15px; - -moz-border-radius: 15px; - -ms-border-radius: 15px; - border-radius: 15px; -} - -#header .nav { - -webkit-flex-grow: 2; - flex-grow: 2; - text-align: right; -} - -button.dropdown, a.dropdown { cursor: pointer; } -button.dropdown .arrow, a.dropdown .arrow { - font-size: 50%; display: inline-block; vertical-align: middle; -} -button.dropdown .arrow::after, a.dropdown .arrow::after { content: "▼"; } -button.active.dropdown .arrow::after, a.active.dropdown .arrow::after { - content: "▲"; -} - -button { - background: none; - outline: 0; - border: 0; - padding: 10px; - color: white; -} - -button.active { - background:#2a4f27; - box-shadow:inset -2px 2px 4px 0 #243d26 -} - -ul.dropdown { - display: none; - visibility: none; - position: absolute; - top: 100%; - right: 0; - width: 100%; - min-width: 150px; - opacity: 0; - margin: 0; - text-align: left; - padding: 0; - background: white; - border: 1px solid #d5d3cb; - list-style: none; - z-index: 10; - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - -ms-border-radius: 5px; - border-radius: 5px; -} - -ul.dropdown li a { - font-size: 90%; - width: 100%; - display: inline-block; - padding: 8px 10px; - text-decoration: none; - color: #383838 !important; -} - -ul.dropdown li a:hover { - background: #5e5e5e; - color: white !important; -} -ul.dropdown li.last { border-top: 1px solid #d5d3cb; } -ul.dropdown.open { - display: block; - visibility: visible; - opacity: 1; -} -.dropdown-container { - display: inline-block; - position: relative; -} - -p > img { - max-width: 100%; -} diff --git a/src/doc/stylesheets/normalize.css b/src/doc/stylesheets/normalize.css deleted file mode 100644 index 73abb76fa41..00000000000 --- a/src/doc/stylesheets/normalize.css +++ /dev/null @@ -1,375 +0,0 @@ -/*! normalize.css v2.0.1 | MIT License | git.io/normalize */ - -/* ========================================================================== - HTML5 display definitions - ========================================================================== */ - -/* - * Corrects `block` display not defined in IE 8/9. - */ - -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -nav, -section, -summary { - display: block; -} - -/* - * Corrects `inline-block` display not defined in IE 8/9. - */ - -audio, -canvas, -video { - display: inline-block; -} - -/* - * Prevents modern browsers from displaying `audio` without controls. - * Remove excess height in iOS 5 devices. - */ - -audio:not([controls]) { - display: none; - height: 0; -} - -/* - * Addresses styling for `hidden` attribute not present in IE 8/9. - */ - -[hidden] { - display: none; -} - -/* ========================================================================== - Base - ========================================================================== */ - -/* - * 1. Sets default font family to sans-serif. - * 2. Prevents iOS text size adjust after orientation change, without disabling - * user zoom. - */ - -html { - font-family: sans-serif; /* 1 */ - -webkit-text-size-adjust: 100%; /* 2 */ - -ms-text-size-adjust: 100%; /* 2 */ -} - -/* - * Removes default margin. - */ - -body { - margin: 0; -} - -/* ========================================================================== - Links - ========================================================================== */ - -/* - * Addresses `outline` inconsistency between Chrome and other browsers. - */ - -a:focus { - outline: thin dotted; -} - -/* - * Improves readability when focused and also mouse hovered in all browsers. - */ - -a:active, -a:hover { - outline: 0; -} - -/* ========================================================================== - Typography - ========================================================================== */ - -/* - * Addresses `h1` font sizes within `section` and `article` in Firefox 4+, - * Safari 5, and Chrome. - */ - -h1 { - font-size: 2em; -} - -/* - * Addresses styling not present in IE 8/9, Safari 5, and Chrome. - */ - -abbr[title] { - border-bottom: 1px dotted; -} - -/* - * Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome. - */ - -b, -strong { - font-weight: bold; -} - -/* - * Addresses styling not present in Safari 5 and Chrome. - */ - -dfn { - font-style: italic; -} - -/* - * Addresses styling not present in IE 8/9. - */ - -mark { - background: #ff0; - color: #000; -} - - -/* - * Corrects font family set oddly in Safari 5 and Chrome. - */ - -code, -kbd, -pre, -samp { - font-family: monospace, serif; - font-size: 1em; -} - -/* - * Improves readability of pre-formatted text in all browsers. - */ - -pre { - white-space: pre; - white-space: pre-wrap; - word-wrap: break-word; -} - -/* - * Sets consistent quote types. - */ - -q { - quotes: "\201C" "\201D" "\2018" "\2019"; -} - -/* - * Addresses inconsistent and variable font size in all browsers. - */ - -small { - font-size: 80%; -} - -/* - * Prevents `sub` and `sup` affecting `line-height` in all browsers. - */ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sup { - top: -0.5em; -} - -sub { - bottom: -0.25em; -} - -/* ========================================================================== - Embedded content - ========================================================================== */ - -/* - * Removes border when inside `a` element in IE 8/9. - */ - -img { - border: 0; -} - -/* - * Corrects overflow displayed oddly in IE 9. - */ - -svg:not(:root) { - overflow: hidden; -} - -/* ========================================================================== - Figures - ========================================================================== */ - -/* - * Addresses margin not present in IE 8/9 and Safari 5. - */ - -figure { - margin: 0; -} - -/* ========================================================================== - Forms - ========================================================================== */ - -/* - * Define consistent border, margin, and padding. - */ - -fieldset { - border: 1px solid #c0c0c0; - margin: 0 2px; - padding: 0.35em 0.625em 0.75em; -} - -/* - * 1. Corrects color not being inherited in IE 8/9. - * 2. Remove padding so people aren't caught out if they zero out fieldsets. - */ - -legend { - border: 0; /* 1 */ - padding: 0; /* 2 */ -} - -/* - * 1. Corrects font family not being inherited in all browsers. - * 2. Corrects font size not being inherited in all browsers. - * 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome - */ - -button, -input, -select, -textarea { - font-family: inherit; /* 1 */ - font-size: 100%; /* 2 */ - margin: 0; /* 3 */ -} - -/* - * Addresses Firefox 4+ setting `line-height` on `input` using `!important` in - * the UA stylesheet. - */ - -button, -input { - line-height: normal; -} - -/* - * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` - * and `video` controls. - * 2. Corrects inability to style clickable `input` types in iOS. - * 3. Improves usability and consistency of cursor style between image-type - * `input` and others. - */ - -button, -html input[type="button"], /* 1 */ -input[type="reset"], -input[type="submit"] { - -webkit-appearance: button; /* 2 */ - cursor: pointer; /* 3 */ -} - -/* - * Re-set default cursor for disabled elements. - */ - -button[disabled], -input[disabled] { - cursor: default; -} - -/* - * 1. Addresses box sizing set to `content-box` in IE 8/9. - * 2. Removes excess padding in IE 8/9. - */ - -input[type="checkbox"], -input[type="radio"] { - box-sizing: border-box; /* 1 */ - padding: 0; /* 2 */ -} - -/* - * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome. - * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome - * (include `-moz` to future-proof). - */ - -input[type="search"] { - -webkit-appearance: textfield; /* 1 */ - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; /* 2 */ - box-sizing: content-box; -} - -/* - * Removes inner padding and search cancel button in Safari 5 and Chrome - * on OS X. - */ - -input[type="search"]::-webkit-search-cancel-button, -input[type="search"]::-webkit-search-decoration { - -webkit-appearance: none; -} - -/* - * Removes inner padding and border in Firefox 4+. - */ - -button::-moz-focus-inner, -input::-moz-focus-inner { - border: 0; - padding: 0; -} - -/* - * 1. Removes default vertical scrollbar in IE 8/9. - * 2. Improves readability and alignment in all browsers. - */ - -textarea { - overflow: auto; /* 1 */ - vertical-align: top; /* 2 */ -} - -/* ========================================================================== - Tables - ========================================================================== */ - -/* - * Remove most spacing between table cells. - */ - -table { - border-collapse: collapse; - border-spacing: 0; -} \ No newline at end of file diff --git a/src/doc/stylesheets/prism.css b/src/doc/stylesheets/prism.css deleted file mode 100644 index d80a9410284..00000000000 --- a/src/doc/stylesheets/prism.css +++ /dev/null @@ -1,197 +0,0 @@ -/* http://prismjs.com/download.html?themes=prism-twilight&languages=markup+css+clike+javascript */ -/** - * prism.js Twilight theme - * Based (more or less) on the Twilight theme originally of Textmate fame. - * @author Remy Bach - */ -code[class*="language-"], -pre[class*="language-"] { - color: white; - direction: ltr; - font-family: Consolas, Monaco, 'Andale Mono', monospace; - text-align: left; - text-shadow: 0 -.1em .2em black; - white-space: pre; - word-spacing: normal; - word-break: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; -} - -pre[class*="language-"], -:not(pre) > code[class*="language-"] { - background: hsl(0, 0%, 8%); /* #141414 */ -} - -/* Code blocks */ -pre[class*="language-"] { - border-radius: .5em; - border: .3em solid hsl(0, 0%, 33%); /* #282A2B */ - box-shadow: 1px 1px .5em black inset; - margin: .5em 0; - overflow: auto; - padding: 1em; -} - -pre[class*="language-"]::selection { - /* Safari */ - background: hsl(200, 4%, 16%); /* #282A2B */ -} - -pre[class*="language-"]::selection { - /* Firefox */ - background: hsl(200, 4%, 16%); /* #282A2B */ -} - -/* Text Selection colour */ -pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, -code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { - text-shadow: none; - background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */ -} - -pre[class*="language-"]::selection, pre[class*="language-"] ::selection, -code[class*="language-"]::selection, code[class*="language-"] ::selection { - text-shadow: none; - background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */ -} - -/* Inline code */ -:not(pre) > code[class*="language-"] { - border-radius: .3em; - border: .13em solid hsl(0, 0%, 33%); /* #545454 */ - box-shadow: 1px 1px .3em -.1em black inset; - padding: .15em .2em .05em; -} - -.token.comment, -.token.prolog, -.token.doctype, -.token.cdata { - color: hsl(0, 0%, 47%); /* #777777 */ -} - -.token.punctuation { - opacity: .7; -} - -.namespace { - opacity: .7; -} - -.token.tag, -.token.boolean, -.token.number, -.token.deleted { - color: hsl(14, 58%, 55%); /* #CF6A4C */ -} - -.token.keyword, -.token.property, -.token.selector, -.token.constant, -.token.symbol, -.token.builtin { - color: hsl(53, 89%, 79%); /* #F9EE98 */ -} - -.token.attr-name, -.token.attr-value, -.token.string, -.token.char, -.token.operator, -.token.entity, -.token.url, -.language-css .token.string, -.style .token.string, -.token.variable, -.token.inserted { - color: hsl(76, 21%, 52%); /* #8F9D6A */ -} - -.token.atrule { - color: hsl(218, 22%, 55%); /* #7587A6 */ -} - -.token.regex, -.token.important { - color: hsl(42, 75%, 65%); /* #E9C062 */ -} - -.token.important { - font-weight: bold; -} - -.token.entity { - cursor: help; -} - -pre[data-line] { - padding: 1em 0 1em 3em; - position: relative; -} - -/* Markup */ -.language-markup .token.tag, -.language-markup .token.attr-name, -.language-markup .token.punctuation { - color: hsl(33, 33%, 52%); /* #AC885B */ -} - -/* Make the tokens sit above the line highlight so the colours don't look faded. */ -.token { - position: relative; - z-index: 1; -} - -.line-highlight { - background: -moz-linear-gradient(left, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */ - background: -o-linear-gradient(left, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */ - background: -webkit-linear-gradient(left, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */ - background: hsla(0, 0%, 33%, 0.25); /* #545454 */ - background: linear-gradient(left, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */ - border-bottom: 1px dashed hsl(0, 0%, 33%); /* #545454 */ - border-top: 1px dashed hsl(0, 0%, 33%); /* #545454 */ - left: 0; - line-height: inherit; - margin-top: 0.75em; /* Same as .prism’s padding-top */ - padding: inherit 0; - pointer-events: none; - position: absolute; - right: 0; - white-space: pre; - z-index: 0; -} - -.line-highlight:before, -.line-highlight[data-end]:after { - background-color: hsl(215, 15%, 59%); /* #8794A6 */ - border-radius: 999px; - box-shadow: 0 1px white; - color: hsl(24, 20%, 95%); /* #F5F2F0 */ - content: attr(data-start); - font: bold 65%/1.5 sans-serif; - left: .6em; - min-width: 1em; - padding: 0 .5em; - position: absolute; - text-align: center; - text-shadow: none; - top: .4em; - vertical-align: .3em; -} - -.line-highlight[data-end]:after { - bottom: .4em; - content: attr(data-end); - top: auto; -} -