Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Tighten up the example for a build script #894

Merged
merged 1 commit into from
Nov 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/doc/build-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ are interpreted by Cargo and must be of the form `key=value`.

Example output:

```
```notrust
cargo:rustc-flags=-l foo:static -L /path/to/foo
cargo:root=/path/to/foo
cargo:libdir=/path/to/foo/lib
Expand Down Expand Up @@ -205,7 +205,7 @@ build = "build.rs"
Here we can se we've got a build script specified which we'll use to generate
some code. Let's see what's inside the build script:

```
```rust,no_run
// build.rs

use std::os;
Expand Down Expand Up @@ -235,7 +235,7 @@ There's a couple of points of note here:

Next, let's peek at the library itself:

```
```rust,ignore
// src/main.rs

include!(concat!(env!("OUT_DIR"), "/hello.rs"))
Expand Down Expand Up @@ -290,7 +290,7 @@ build = "build.rs"
For now we're not going to use any build dependencies, so let's take a look at
the build script now:

```rust
```rust,no_run
// build.rs

use std::io::Command;
Expand All @@ -301,18 +301,12 @@ fn main() {

// note that there are a number of downsides to this approach, the comments
// below detail how to improve the portability of these commands.
Command::new("gcc").arg("src/hello.c")
.arg("-c")
.arg("-o")
Command::new("gcc").args(&["src/hello.c", "-c", "-o"])
.arg(format!("{}/hello.o", out_dir))
.status()
.unwrap();
Command::new("ar").arg("crus")
.arg("libhello.a")
.arg("hello.o")
.cwd(&out_dir)
.status()
.unwrap();
.status().unwrap();
Command::new("ar").args(&["crus", "libhello.a", "hello.o"])
.cwd(&Path::new(&out_dir))
.status().unwrap();

println!("cargo:rustc-flags=-L {} -l hello:static", out_dir);
}
Expand All @@ -337,7 +331,7 @@ Not to fear, though, this is where a `build-dependencies` entry would help! The
Cargo ecosystem has a number of packages to make this sort of task much easier,
portable, and standardized. For example, the build script could be written as:

```rust
```rust,ignore
// build.rs

// Bring in a dependency on an externally maintained `cc` package which manages
Expand Down Expand Up @@ -378,7 +372,7 @@ void hello() {
}
```

```rust
```rust,ignore
// src/main.rs

// Note the lack of the `#[link]` attribute. We're delegating the responsibility
Expand Down