mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
executable
->bin
and initial impl
This commit is contained in:
parent
8bc5b96a55
commit
ebf2929147
@ -7,7 +7,7 @@ The `Cargo.toml` file contains several top-level sections:
|
|||||||
* `[project]`: project-specific details, such as name, version and author
|
* `[project]`: project-specific details, such as name, version and author
|
||||||
* `[[lib]]`: information about the main library file, if one exists. By
|
* `[[lib]]`: information about the main library file, if one exists. By
|
||||||
default, the main library file is `src/<package-name>.rs`
|
default, the main library file is `src/<package-name>.rs`
|
||||||
* `[[executable]]`: optionally repeated information about executables
|
* `[[bin]]`: optionally repeated information about executables
|
||||||
that the project is generating. This can both be used for projects
|
that the project is generating. This can both be used for projects
|
||||||
that primarily build executables, as well as projects that contain
|
that primarily build executables, as well as projects that contain
|
||||||
utility executables (such as an HTTP library that comes with a web
|
utility executables (such as an HTTP library that comes with a web
|
||||||
@ -53,9 +53,9 @@ Note that we plan to support multiple `Cargo.toml` files in Cargo's git
|
|||||||
support, so you don't have to have a separate git repository per
|
support, so you don't have to have a separate git repository per
|
||||||
library.
|
library.
|
||||||
|
|
||||||
## The `[[executable]]` Section
|
## The `[[bin]]` Section
|
||||||
|
|
||||||
The `executable` section is optionally repeated. It is designed for
|
The `bin` section is optionally repeated. It is designed for
|
||||||
projects whose main raison d'être is a single executable, or for projects
|
projects whose main raison d'être is a single executable, or for projects
|
||||||
that want to provide utility executables alongside a primary library.
|
that want to provide utility executables alongside a primary library.
|
||||||
|
|
||||||
@ -71,18 +71,18 @@ standalone library limited to the bare minimum requirements.
|
|||||||
an executable, `src/bin/<name>.rs` if the project has both a lib and
|
an executable, `src/bin/<name>.rs` if the project has both a lib and
|
||||||
executable, see below)
|
executable, see below)
|
||||||
|
|
||||||
## Projects Containing Both `lib` and `executable`
|
## Projects Containing Both `lib` and `bin`
|
||||||
|
|
||||||
Most projects will primarily produce either a library or an executable.
|
Most projects will primarily produce either a library or an executable.
|
||||||
Such projects should name the main crate file `<projectname>.rs` and
|
Such projects should name the main crate file `<projectname>.rs` and
|
||||||
omit the optional `path` from the `lib` or `executable` sections.
|
omit the optional `path` from the `lib` or `bin` sections.
|
||||||
|
|
||||||
Projects that contain both a library and one or more executables should
|
Projects that contain both a library and one or more executables should
|
||||||
generally use `<projectname>.rs` for their library, and `bin/*.rs`
|
generally use `<projectname>.rs` for their library, and `bin/*.rs`
|
||||||
for the executables.
|
for the executables.
|
||||||
|
|
||||||
These rules are also the default behavior if `path` is left off of `lib`
|
These rules are also the default behavior if `path` is left off of `lib`
|
||||||
or `executable` sections.
|
or `bin` sections.
|
||||||
|
|
||||||
## Example Manifests
|
## Example Manifests
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ authors = ["Yehuda Katz <wycats@gmail.com>"]
|
|||||||
name = "hammer"
|
name = "hammer"
|
||||||
```
|
```
|
||||||
|
|
||||||
Simple `executable`:
|
Simple `bin`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
@ -111,13 +111,13 @@ version = "0.5.0"
|
|||||||
authors = ["Tom Dale <tom@tomdale.net>", "Carl Lerche <me@carllerche.com>"]
|
authors = ["Tom Dale <tom@tomdale.net>", "Carl Lerche <me@carllerche.com>"]
|
||||||
tags = ["performance", "profiling"]
|
tags = ["performance", "profiling"]
|
||||||
|
|
||||||
[[executable]]
|
[[bin]]
|
||||||
|
|
||||||
name = "skylight"
|
name = "skylight"
|
||||||
path = "bin/skylight.rs" # supports existing project structures
|
path = "bin/skylight.rs" # supports existing project structures
|
||||||
```
|
```
|
||||||
|
|
||||||
A project with both a lib and an `executable`:
|
A project with both a `lib` and an `bin`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
@ -131,11 +131,11 @@ tags = ["performance", "profiling"]
|
|||||||
|
|
||||||
name = "skylight" # path defaults to src/skylight.rs
|
name = "skylight" # path defaults to src/skylight.rs
|
||||||
|
|
||||||
[[executable]]
|
[[bin]]
|
||||||
|
|
||||||
name = "skylight" # path defaults to src/bin/skylight.rs
|
name = "skylight" # path defaults to src/bin/skylight.rs
|
||||||
|
|
||||||
[[executable]]
|
[[bin]]
|
||||||
|
|
||||||
name = "skylight-setup" # path defaults to src/bin/skylight-setup.rs
|
name = "skylight-setup" # path defaults to src/bin/skylight-setup.rs
|
||||||
```
|
```
|
||||||
|
@ -11,19 +11,37 @@ use serialize::json::Encoder;
|
|||||||
use toml::from_toml;
|
use toml::from_toml;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
#[deriving(Decodable,Encodable)]
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
struct Manifest {
|
struct SerializedManifest {
|
||||||
project: ~Project
|
project: ~Project,
|
||||||
|
lib: Option<~[LibTarget]>,
|
||||||
|
bin: Option<~[ExecTarget]>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Decodable,Encodable)]
|
#[deriving(Encodable,Eq,Clone,Ord)]
|
||||||
|
struct Manifest {
|
||||||
|
project: ~Project,
|
||||||
|
lib: ~[LibTarget],
|
||||||
|
bin: ~[ExecTarget]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
|
struct Target {
|
||||||
|
name: ~str,
|
||||||
|
path: Option<~str>
|
||||||
|
}
|
||||||
|
|
||||||
|
type LibTarget = Target;
|
||||||
|
type ExecTarget = Target;
|
||||||
|
|
||||||
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
struct Project {
|
struct Project {
|
||||||
name: ~str,
|
name: ~str,
|
||||||
version: ~str,
|
version: ~str,
|
||||||
authors: ~[~str]
|
authors: ~[~str]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Decodable)]
|
#[deriving(Decodable,Eq,Clone,Ord)]
|
||||||
struct ReadManifestFlags {
|
struct ReadManifestFlags {
|
||||||
manifest_path: ~str
|
manifest_path: ~str
|
||||||
}
|
}
|
||||||
@ -44,8 +62,40 @@ fn main() {
|
|||||||
|
|
||||||
let root = toml::parse_from_file(flags.manifest_path).unwrap();
|
let root = toml::parse_from_file(flags.manifest_path).unwrap();
|
||||||
|
|
||||||
let manifest = from_toml::<Manifest>(root.clone());
|
let toml_manifest = from_toml::<SerializedManifest>(root.clone());
|
||||||
|
|
||||||
|
let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin);
|
||||||
|
|
||||||
|
let manifest = Manifest{
|
||||||
|
project: toml_manifest.project,
|
||||||
|
lib: lib,
|
||||||
|
bin: bin
|
||||||
|
};
|
||||||
|
|
||||||
let encoded: ~str = Encoder::str_encode(&manifest);
|
let encoded: ~str = Encoder::str_encode(&manifest);
|
||||||
|
|
||||||
println!("{}", encoded);
|
println!("{}", encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn normalize(lib: &Option<~[LibTarget]>, bin: &Option<~[ExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
|
||||||
|
if lib.is_some() && bin.is_some() {
|
||||||
|
(~[], ~[])
|
||||||
|
} else if lib.is_some() {
|
||||||
|
let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file
|
||||||
|
if l.path.is_none() {
|
||||||
|
l.path = Some(format!("{}.rs", l.name));
|
||||||
|
}
|
||||||
|
(~[l.clone()], ~[])
|
||||||
|
} else if bin.is_some() {
|
||||||
|
let b = bin.get_ref().map(|b_ref| {
|
||||||
|
let mut b = b_ref.clone();
|
||||||
|
if b.path.is_none() {
|
||||||
|
b.path = Some(format!("{}.rs", b.name));
|
||||||
|
}
|
||||||
|
b
|
||||||
|
});
|
||||||
|
(~[], b)
|
||||||
|
} else {
|
||||||
|
(~[], ~[])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user