Git Product home page Git Product logo

cargo's Introduction

Cargo

Cargo downloads your Rust project’s dependencies and compiles your project.

To start using Cargo, learn more at The Cargo Book.

To start developing Cargo itself, read the Cargo Contributor Guide.

Code Status

CI

Code documentation: https://doc.rust-lang.org/nightly/nightly-rustc/cargo/

Installing Cargo

Cargo is distributed by default with Rust, so if you've got rustc installed locally you probably also have cargo installed locally.

Compiling from Source

Requirements

Cargo requires the following tools and packages to build:

Other requirements:

The following are optional based on your platform and needs.

  • pkg-config — This is used to help locate system packages, such as libssl headers/libraries. This may not be required in all cases, such as using vendored OpenSSL, or on Windows.

  • OpenSSL — Only needed on Unix-like systems and only if the vendored-openssl Cargo feature is not used.

    This requires the development headers, which can be obtained from the libssl-dev package on Ubuntu or openssl-devel with apk or yum or the openssl package from Homebrew on macOS.

    If using the vendored-openssl Cargo feature, then a static copy of OpenSSL will be built from source instead of using the system OpenSSL. This may require additional tools such as perl and make.

    On macOS, common installation directories from Homebrew, MacPorts, or pkgsrc will be checked. Otherwise it will fall back to pkg-config.

    On Windows, the system-provided Schannel will be used instead.

    LibreSSL is also supported.

Optional system libraries:

The build will automatically use vendored versions of the following libraries. However, if they are provided by the system and can be found with pkg-config, then the system libraries will be used instead:

  • libcurl — Used for network transfers.
  • libgit2 — Used for fetching git dependencies.
  • libssh2 — Used for SSH access to git repositories.
  • libz (aka zlib) — Used for data compression.

It is recommended to use the vendored versions as they are the versions that are tested to work with Cargo.

Compiling

First, you'll want to check out this repository

git clone https://github.com/rust-lang/cargo.git
cd cargo

With cargo already installed, you can simply run:

cargo build --release

Adding new subcommands to Cargo

Cargo is designed to be extensible with new subcommands without having to modify Cargo itself. See the Wiki page for more details and a list of known community-developed subcommands.

Releases

Cargo releases coincide with Rust releases. High level release notes are available as part of Rust's release notes. Detailed release notes are available in this repo at CHANGELOG.md.

Reporting issues

Found a bug? We'd love to know about it!

Please report all issues on the GitHub issue tracker.

Contributing

See the Cargo Contributor Guide for a complete introduction to contributing to Cargo.

License

Cargo is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Third party software

This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (https://www.openssl.org/).

In binary form, this product includes software that is licensed under the terms of the GNU General Public License, version 2, with a linking exception, which can be obtained from the upstream repository.

See LICENSE-THIRD-PARTY for details.

cargo's People

Contributors

aaron1011 avatar alexcrichton avatar arlosi avatar behnam avatar bors avatar brson avatar byron avatar carllerche avatar carols10cents avatar da-x avatar djc avatar dtolnay avatar dwijnand avatar eh2406 avatar ehuss avatar epage avatar hi-rustin avatar killercup avatar linyihai avatar matklad avatar matthiaskrgr avatar muscraft avatar oli-obk avatar steveklabnik avatar tesuji avatar volks73 avatar weihanglo avatar willcrichton avatar wycats avatar yaahc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cargo's Issues

Executing `git rev-parse master` failed

cargo build -u --verbose results in this error on the following step:

   Compiling graphics v0.0.0 (https://github.com/pistondevelopers/rust-graphics)
Executing `git rev-parse master` failed

Caused by:
  Executing `git rev-parse master` failed

Caused by:
  Could not execute process `git rev-parse master` (status=never executed)

Caused by:
  no such file or directory

I have also opened an issue for rust-graphics: PistonDevelopers/graphics#553

Support tests

Maybe add a [[test]] to the Cargo manifest format?

Otherwise provide some way for [[bin]] to flag itself as a test and parse the --test flag to rustc.

The first option would seem nicer imho.

Confusing error with missing dependencies

If .cargo/config is missing, or if the dependency has an ill-formatted Cargo.toml, one is met with this error message:

task '<main>' failed at 'invalid num of results 0', src/cargo/core/resolver.rs:31

A simple Cargo.toml with one dependency is enough to trigger the error. If the dependency is added via .cargo/config's path option, then if the dependency's Cargo.toml project name and lib name are not equal you are met with the same error.

`cargo build` doesn't work when in a directory with a non-UTF8 path

[package]

name = "test"
version = "0.0.0"
authors = []

[[lib]]

name = "test"

with src/test.rs empty.

If this is in a valid UTF-8 directory, then cargo build works flawlessly. If this is in an invalid UTF-8 directory (creatable by, e.g., mkdir $(echo -e '\xff') in Bash), then cargo build is rather upset:

  Compiling test v0.0.0 (file:/home/huon/projects/test-rust/�)
error: could not write output: Error opening output file '/home/huon/projects/test-rust/�/target/test.o': No such file or directory
Could not execute process `rustc src/test.rs --crate-type lib --out-dir /home/huon/projects/test-rust/�/target -L /home/huon/projects/test-rust/�/target -L /home/huon/projects/test-rust/�/target/deps` (status=101)

Windows paths need improved handling

Due to the \ character, windows paths are both invalid URLs as well as causing all the tests to fail on windows. This can be closed when we no longer jankily replace \ with / and also when the tests pass on windows.

cargo add <package>

This is probably a no brainer, but I thought I'd drop it in here as a yes-please feature request.

I just discovered that with bower and npm if you install a package into a local directory scope (eg. bower install moment) with a particular flag (in this case bower install moment -S) it not only installs the moment recent version of the package into the local folder; it updates the manifest file automatically:

{
  "name": "configtool",
  "version": "0.1.0",
  "dependencies": {
    "underscore": "1.5.2",
    "angular": "1.2.3",
    "angular-resource": "1.2.3",
    "angular-sanitize": "~1.2.3",
    "momentjs": "~2.5.1" // <---- This gets automatically added 
  }
}

This is a really lovely workflow to use, I thought I'd drop it in here as a feature request.

Build error on latest rust nightly

Following the install instructions on mac I get the following error on latest rust build:

rustc  -L libs/hammer.rs/target -L libs/rust-toml/lib --out-dir target src/cargo/lib.rs
src/cargo/core/version_req.rs:289:53: 289:63 error: cannot use `self.state` because it was mutably borrowed
src/cargo/core/version_req.rs:289                     _ => return self.flush(idx + 1, self.state)
                                                                                      ^~~~~~~~~~
src/cargo/core/version_req.rs:282:9: 293:20 note: in expansion of next!
src/cargo/core/version_req.rs:303:13: 303:21 note: expansion site
src/cargo/core/version_req.rs:289:33: 289:37 note: borrow of `*self` occurs here
src/cargo/core/version_req.rs:289                     _ => return self.flush(idx + 1, self.state)

Commands don't have a help mode

These commands all have no output

  • ./target/cargo --help
  • ./target/cargo help
  • ./target/cargo foobar
  • ./target/cargo-compile --help

The crates.io website doesn't link to the cargo source.

As it is the website gives a small tutorial but doesn't say where and how to get cargo, I think it should at least have a link to this github prominently somewhere.

It should also give simple build instructions (as long as binary versions are not available), say which versions of rust are needed etc...

Invalid manifest has no error

[project]

name = "glfw-rs"
version = "0.0.1"

[[lib]]

build = "build.sh"
name = "foo"

for example, will silently ignore the unused build key.

Single-Version Packages.

In Piston, we have a pattern where in order to decouple dependencies and achieve maximum independence, we split up a interface and it's implementation(s) into multiple projects.

The interface does not depend on the implementations, but the opposite is true. For example:

  • My App
    • piston
    • some_piston_backend
      • piston

What we would really like is a way to make sure that the two piston repositories in the tree are the exact same version. A user could theoretically pick piston-3.0 and some_piston_backend-1.0 (that depends on piston-1.0).

I'm not sure what resolution strategy Cargo is planning on using for this, but I would like the option as a maintainer of piston to be able to say "THERE CAN ONLY BE ONE" and fail at the cargo package fetching stage. Anything else would either run (and have terrible bugs) or fail at compile time with confusing error messages.

Edit: A more detailed example of what could go wrong: PistonDevelopers/piston#430

Example Cargo.toml

May be premature, but it would be useful to have a few example Cargo.tomls lying around. Or perhaps one full one with documentation as to what's going on.

For now, this can be found through tests/test_cargo_compile.rs

Proposal to do native deps using pkg-config

On Linux, the state-of-the-art mechanism for linking to native libraries is pkg-config, replacing decades of hard-coding. On other platforms, there is no solution easier than using pkg-config, although it is most likely not installed by default there.

pkg-config supports both static and dynamic linking, although there are a lot of in-the-wild .pc files that don't support static linking properly.

Here's an example of using pkg-config in a (currently non-Cargo) Rust project, including the "rpath" step for libraries installed in non-system directories: https://github.com/o11c/termkey-rs/blob/master/Makefile

"build" doesn't play nice with compound commands

I was trying to port https://github.com/csherratt/ovr-rs over to cargo, but I didn't want to break the current build as there are a bunch of dependencies. So I tried using this Cargo.toml script:

[package]

name = "ovr-rs"
version = "0.1.0"
authors = [
        "Colin Sherratt",
        "Erick Tryzelaar"
]

build = "sh -c './configure && make lib/libovr.a && mkdir target && cp lib/libovr.a target/'"

[[lib]]

name = "ovr-rs"
path = "src/oculus-vr/lib.rs"

[[bin]]
name = "oculus-info"
path = "src/oculus-info/main.rs"

[dependencies.cgmath-rs]

git = "https://github.com/bjz/cgmath-rs.git"

Unfortunately it didn't work. The reason is that ops::cargo_rustc::compile_custom is trying to split the string on spaces and pass them to the first argument, but this doesn't play well with sh -c. Instead, I'd suggest changing build from being a String to being a Vec<Vec<String>>. The outer vec allows you to run multiple commands, and the inner vec would allow you to have precise control over the arguments. So the prior example would be instead written as:

...
build = [
    ["./configure"],
    ["make", "lib/libovr.a"],
    ["/bin/mkdir", "target"],
    ["/bin/cp", "lib/libovr.a", "target/"]
]
...

The alternative would be to just have compile_custom shell out to /bin/sh, but the downside with that is then you have to deal with shell escaping, which can become a mess.

cc @csherratt.

Ensure no more binaries are checked in

Updated description

make test should ensure no binaries are checked in.

Original Description

repo contains a 4MB binary

https://github.com/rust-lang/cargo/blob/master/tests/tests

cargo is still young enough that this could possibly be rebased out, to keep the repository slim. (Just removing it in a normal commit will not remove it from the history, meaning it will hang around in .git forever: this would need some pickaxing/history modification.)

infinite recursion when a package depends on itself

[package]

name = "test"
version = "0.0.0"
authors = []

[dependencies.test]

path = "."

[[lib]]

name = "test"

with src/test.rs:

task '<main>' has overflowed its stack

(This fails with a nonrelative path too.)

Cargo should be self-hosting

After updating rust, building cargo by running make fails due to not rebuilding dependencies:

mkdir -p target
rustc  -L libs/hammer.rs/target -L libs/toml-rs/build --out-dir target src/cargo/lib.rs
src/cargo/lib.rs:14:1: 14:21 error: found possibly newer version of crate `std` which `hammer` depends on
src/cargo/lib.rs:14 extern crate hammer;
                    ^~~~~~~~~~~~~~~~~~~~
src/cargo/lib.rs:14:1: 14:21 note: perhaps this crate needs to be recompiled?
src/cargo/lib.rs:14 extern crate hammer;
                    ^~~~~~~~~~~~~~~~~~~~

This seems like a job for cargo!

Add MIT license

This is needed for packaging on some platforms, since MIT has a custom copyright line.

Cargo fails mysteriously when given an ssh url

I had [email protected]:Foo/bar.git as a git dependency and Cargo crashed with this error:

task '<main>' failed at 'called `Result::unwrap()` on an `Err` value: url: Invalid character in scheme.', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/result.rs:545

Obviously it should reject the url, but not in this manner.

cargo cult

Feature request/idea. Implement:

 $ cargo cult

Which would create a new project/module from a template.

version parse error

when writing version = "x.y" in stead of version = "x.y.z" in the toml file,cargo crashed with message:
task '<main>' failed at 'called``Option::unwrap()``on a``None``value', /build/rust-git/src/rust/src/libcore/option.rs:265

Ergonomics: errors could be better

Right now, if you make a Cargo.toml, and you mkdir src, and then you cargo build:

$ cargo build
  Compiling guessing_game v0.1.0 (file:/home/steve/tmp/guessing_game)
error: couldn't read src/guessing_game.rs: couldn't open file (no such file or directory (No such file or directory); path=src/guessing_game.rs; mode=open; access=read)

@wycats would like this to improve. 😄

Mailing list for Adept & Cargo discussion

Hello, I am new to Rust and was looking around for the rustpkg but found it was deprecated. Although the reason I looked around was unrelated to rustpkg/carge and dependency manager, I am working on a dependency manager called Adept you see so I posted on the rust-dev mailing list and got redirected to this project on Github.

I would love to learn more about your design, but I think you might be interested in Adept's design as well. :)

I was wondering if you had a mailing list where things like this could be discussed?

Best regards,
Fredrik

Cargo clean

Hi,

I use Maven every day, and one command I use a lot is mvn clean to do a general cleanup of my project, and remove the generated "binaries" and code in some cases, or any other specific cleanup that the current project needs.

I think it will be very useful to have one for cargo (for example, to use in CI) and for now it can just be rm -rf target as (AFAIK) cargo just deals with a single target directory.

Single result for a dependency error

I have a top level depencency on https://github.com/PistonDevelopers/rust-graphics.git and a transitive dependency on https://github.com/pistondevelopers/rust-graphics.

Note the different capitalization and lack of .git.

I get the error

An unknown error occurred                                            

Caused by:                                                           
  Temporarily, Cargo only supports a single result for a dependency  

This error had me scratching my head for a while, but I eventually managed to locate what was actually happening.

A better error message in this case would have helped me out a bunch. Something like:

For the crate rust-graphics there are two listed dependencies:
    https://github.com/PistonDevelopers/rust-graphics.git
    https://github.com/pistondevelopers/rust-graphics

Use Angular Versioning for the Minor number

This is a concern due to the lack of signaling reoccurring breaking phases after 1.0.0. Modern open source is done in continuous releases, while semantic versioning was designed for another use case. I suggest the rules should be modified in order to allow reoccurring breaking phases.

For example, a single change of an argument from &T to &mut T will require incrementing the major version after 1.0.0. This will not work well with Github where any commit might break the API.

One solution, which is mostly compatible, is to change the minor version to Angular Versioning.

This allows minor versions from [0, 360) to have breaking changes. For example 1.0.0 will be considered Alpha and 1.360.0 will be the release. In the range 1.360.0 and above the rules can be enforced.

Cargo doesn't download the latest version of a dependency

As I'm writing this, the latest version of cgmath-rs compiles without errors for me when built manually (git clone https://github.com/bjz/cgmath-rs.git etc.). Cargo however seems to download an older version that fails to compile. Since I have not specified a version of cgmath-rs in my project, I'm assuming this is a bug. A minimal Cargo.toml which replicates this bug:

[package]

name = "testproject"
version = "0.0.0"
authors = [ "bachm" ]

[[lib]]

name = "testproject"

[dependencies.cgmath-rs]

git = "https://github.com/bjz/cgmath-rs.git"

Some notion of sub-packages useful

Consider https://github.com/sfackler/rust-phf/. It ships two crates: the compiler plugin, and the runtime support. It needs to supply two libraries to projects that depend on it.

Consider https://github.com/bjz/gl-rs/. It has two components, the binding generator, and the generated bindings. It needs to supply a library and a binary to projects that depend on it.

cargo-lite solved all of these usecases with the concept of "subpackages". You gave it a list of directories, and it would look in those for a manifest, execute them, and then procede to finish executing the top-level manifest. It still didn't offer any way to depend on a sub-package directly; it's just a way of organizing a repo.

For cargo, I think it is more appropriate to specify multiple [[lib]] or [[bin]] sections. One useful extension might be:

[[lib.phf_mac]]
[[lib.phf]]

Another possibility:

[[lib]]
path = "src/phf.rs"
[[lib]]
path = "src/phf_mac.rs"

Add .vagrant to .gitignore

Add .vagrant to .gitignore as these files shouldn't be part of repository and remove unnecessary files

The `path` field should be documented

Updated Description

The path field should be documented for [[lib]] and [[bin]]

Original Description

Allow specifying the source file that should be built

Requiring a given source layout isn't the best, IMO. Rather than:

[[lib]]

name = "foo"

which would look in src/foo.rs, also allow:

[[lib]]

src = "src/foo/lib.rs"

Which can make sense when a repo is large or complex.

Can't build with 0.10 on OSX 10.9

Hi,
I'm having trouble building Cargo:

λ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C libs/hammer.rs
rustc src/hammer.rs --out-dir target --crate-type=rlib
src/usage.rs:7:12: 7:21 error: unknown `deriving` trait: `PartialEq`
src/usage.rs:7 #[deriving(PartialEq, Clone, Show)]
                          ^~~~~~~~~
src/hammer.rs:85:18: 85:27 error: unknown `deriving` trait: `PartialEq`
src/hammer.rs:85 #[deriving(Show, PartialEq)]
                                  ^~~~~~~~~
src/hammer.rs:125:18: 125:27 error: unknown `deriving` trait: `PartialEq`
src/hammer.rs:125 #[deriving(Show, PartialEq)]
                                   ^~~~~~~~~
src/hammer.rs:131:18: 131:27 error: unknown `deriving` trait: `PartialEq`
src/hammer.rs:131 #[deriving(Show, PartialEq)]
                                   ^~~~~~~~~
src/hammer.rs:196:30: 196:40 error: unknown `deriving` trait: `PartialOrd`
src/hammer.rs:196 #[deriving(Clone, PartialEq, PartialOrd, Hash, Show)]
                                               ^~~~~~~~~~
src/hammer.rs:196:19: 196:28 error: unknown `deriving` trait: `PartialEq`
src/hammer.rs:196 #[deriving(Clone, PartialEq, PartialOrd, Hash, Show)]
                                    ^~~~~~~~~
error: aborting due to 6 previous errors
make[1]: *** [target/libhammer-e1cb8171-0.0.rlib] Error 101
make: *** [libs/hammer.rs/target/libhammer-e1cb8171-0.0.rlib] Error 2

Rust is version 0.10 installed with home-brew on OSX 10.9.

cargo-init would be super nice

Something like cargo-init to bootstrap a new project would be very nice (mainly creating the toml file if it does not exist and maybe other flags in the future)

Folder for executable source in projects combining `lib` and `bin`

https://github.com/carlhuda/cargo/blob/master/DESIGN/MANIFEST.md

It says bin/*.rs should contain the source code of the executable.

Normally, a bin/ folder contains the executable and the required files to run.
The content of the bin/ folder is copyable to any other folder on the same machine.
It may be target specific and only work for that machine.

Example:

  1. Cloning repository.
  2. ./configure
  3. make
  4. Copying the content of the bin/ folder.

When I see bin/ I read 'binaries' and believes it will contain the binaries required to run the application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.