From c1b99c18ea3e2ddfb6ee3372012be70e6accfb2e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 12 Mar 2014 13:03:36 -0700 Subject: [PATCH] Add missing files --- .gitignore | 2 +- MANIFEST.md | 141 ++++++++++++++++++++++++++++++++++++++++++++++ libcargo/Makefile | 14 +++++ libcargo/cargo.rs | 35 ++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 MANIFEST.md create mode 100644 libcargo/Makefile create mode 100644 libcargo/cargo.rs diff --git a/.gitignore b/.gitignore index 66cc71077a7..d913617bcdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target/ +target diff --git a/MANIFEST.md b/MANIFEST.md new file mode 100644 index 00000000000..e331a629b2b --- /dev/null +++ b/MANIFEST.md @@ -0,0 +1,141 @@ +The manifest file (`Cargo.toml`) is still under active development. This document captures the current thinking on the design. + +## Sections + +The `Cargo.toml` file contains several top-level sections: + +* `[project]`: project-specific details, such as name, version and author +* `[[lib]]`: information about the main library file, if one exists. By + default, the main library file is `src/.rs` +* `[[executable]]`: optionally repeated information about executables + that the project is generating. This can both be used for projects + that primarily build executables, as well as projects that contain + utility executables (such as an HTTP library that comes with a web + server executable). + +## Extensibility + +In general, any unknown attributes are ignored for future extensibility. +Future plugins may also use this capability. + +The project uses the `Decoder` in `rust-toml` to decode the manifest +into Rust structs that are used throughout the built-in commands. + +## The `[project]` Section + +* `name`: the name of the project (`~str`) +* `version`: the version of the project, (`~str` that can be parsed + via `semver::parse`) +* `readme`: a Markdown-formatted file in the project that can be used as + a description of the document in indexes (`Option`, relative to + the project root, defaults to "./README.md", if found). +* `tags`: an array of tags that can be used in indexes (`~[~str]`) +* `authors`: a list of authors in `name ` format (`~[~str]`). At + least one `author` with email will probably be required to submit to + the Cargo repository. +* `src`: the root directory containing source files (`Option`, + relative to the project root, defaults to `src`) + +## The `[[lib]]` Section + +At the moment, Cargo only supports a single lib per package. We use the +array format for future extensibility. + +We only plan to support a single lib at the moment because if you have +multiple libs, you would want projects to be able to depend on them +separately. If you don't care about that, why do you have separate libs? + +* `name`: the name of the library (`~str`, `hammer` would create a `libhammer`) +* `path`: the location of the main crate file (`Option`, defaults to + `src/.rs`) + +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 +library. + +## The `[[executable]]` Section + +The `executable` section is optionally repeated. It is designed for +projects whose main raison d'ĂȘtre is a single executable, or for projects +that want to provide utility executables alongside a primary library. + +If an executable has a different set of flags or dependencies from the +main library, it should be shipped as a separate package with a +dependency on the main library to keep the usage requirements of the +standalone library limited to the bare minimum requirements. + +* `name`: the name of the executable (`~str`, `hammer` would create a + `hammer` executable) +* `path`: the location of the main crate file for the executable + (`Option`, defaults to `src/.rs` if the project has only + an executable, `src/bin/.rs` if the project has both a lib and + executable, see below) + +## Projects Containing Both `lib` and `executable` + +Most projects will primarily produce either a library or an executable. +Such projects should name the main crate file `.rs` and +omit the optional `path` from the `lib` or `executable` sections. + +Projects that contain both a library and one or more executables should +generally use `.rs` for their library, and `bin/*.rs` +for the executables. + +These rules are also the default behavior if `path` is left off of `lib` +or `executable` sections. + +## Example Manifests + +Simple `lib`: + +```toml +[project] + +name = "hammer" +version = "0.1.0" +readme = "README.md" +authors = ["Yehuda Katz "] + +[[lib]] + +name = "hammer" +``` + +Simple `executable`: + +```toml +[project] + +name = "skylight" +version = "0.5.0" +authors = ["Tom Dale ", "Carl Lerche "] +tags = ["performance", "profiling"] + +[[executable]] + +name = "skylight" +path = "bin/skylight.rs" # supports existing project structures +``` + +A project with both a lib and an `executable`: + +```toml +[project] + +name = "skylight" +version = "0.5.0" +authors = ["Tom Dale ", "Carl Lerche "] +tags = ["performance", "profiling"] + +[[lib]] + +name = "skylight" # path defaults to src/skylight.rs + +[[executable]] + +name = "skylight" # path defaults to src/bin/skylight.rs + +[[executable]] + +name = "skylight-setup" # path defaults to src/bin/skylight-setup.rs +``` diff --git a/libcargo/Makefile b/libcargo/Makefile new file mode 100644 index 00000000000..03546636a45 --- /dev/null +++ b/libcargo/Makefile @@ -0,0 +1,14 @@ +LIBCARGO_LIB := $(shell rustc --crate-file-name cargo.rs) + +default: target/$(LIBCARGO_LIB) + +target: + mkdir -p target + +clean: + rm -rf target + +target/$(LIBCARGO_LIB): target cargo.rs + rustc cargo.rs --out-dir target + +.PHONY: default clean diff --git a/libcargo/cargo.rs b/libcargo/cargo.rs new file mode 100644 index 00000000000..7c94661c074 --- /dev/null +++ b/libcargo/cargo.rs @@ -0,0 +1,35 @@ +#[crate_type="rlib"]; + +extern crate serialize; +use serialize::{Decoder}; + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +pub struct Manifest { + project: ~Project, + root: ~str, + lib: ~[LibTarget], + bin: ~[ExecTarget] +} + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +pub struct ExecTarget { + name: ~str, + path: ~str +} + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +pub struct LibTarget { + name: ~str, + path: ~str +} + +//pub type LibTarget = Target; +//pub type ExecTarget = Target; + +#[deriving(Decodable,Encodable,Eq,Clone,Ord)] +pub struct Project { + name: ~str, + version: ~str, + authors: ~[~str] +} +