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

cargo rustc subcommand #595

Closed
alexcrichton opened this issue Sep 18, 2014 · 13 comments
Closed

cargo rustc subcommand #595

alexcrichton opened this issue Sep 18, 2014 · 13 comments
Labels
A-new-subcommand Area: new subcommand

Comments

@alexcrichton
Copy link
Member

Thoughts?

Compile a package and all of its dependencies

Usage:
    cargo rustc [options] [<pkgid>] [--] [<opts>...]

Options:
    -h, --help              Print this message
    -j N, --jobs N          The number of jobs to run in parallel
    --features FEATURES     Features to compile for the package
    --no-default-features   Do not compile default features for the package
    -p, --profile PROFILE   The profile to compile for
    --target TRIPLE         Target triple which compiles will be for
    --manifest-path PATH    Path to the manifest to fetch depednencies for
    -v, --verbose           Use verbose output

The <pkgid> specified (defaults to the current package) will have all of its
dependencies compiled, and then the package itself will be compiled. This
command requires that a lockfile is available and dependencies have been
fetched.

All of the trailing arguments are passed through to the *final* rustc
invocation, not any of the dependencies.

Dependencies will not be recompiled if they do not need to be, but the package
specified will always be compiled. The compiler will receive a number of
arguments unconditionally such as --extern, -L, etc. Note that dependencies are
recompiled when the flags they're compiled with change, so it is not allowed to
manually compile a package's dependencies and then compile the package against
the artifacts just generated.
@alexcrichton
Copy link
Member Author

I'm not totally sold on the utility of this command due to the recompiling dependencies restriction, but I'm curious what others think about this.

@DanielKeep
Copy link

A pain point for me is debugging macros. Generally, I need to do a cargo build (which fails), then manually invoke rustc in order to pass --no-analysis --pretty=expanded to get the expanded AST output.

Having a "build deps and pre-fill the command line" command would be lovely.

@zeonin
Copy link

zeonin commented Feb 6, 2015

I think this or something like it should happen.

Personally, I'm still waiting on a way to pass a linker script to the linker without writing a custom Makefile (and defeating a lot of the things that make cargo so nice to use). I'm still fairly new to rust/cargo, so I may be overlooking something. The problem I'm running into is that cargo is almost too high level for such a low level language.

@Manishearth
Copy link
Member

This seems like what we want. So, cargo rustc --foo will internally call rustc -lbar -lbaz --extern quux=.... -L target/foobar ....... --foo?

As long as the usual link args are available I think we can make this work :)

@larsbergstrom
Copy link

We have worked around this for now by instead setting the linker to be a shell script that manually invokes everything we need.

@nwin
Copy link

nwin commented Mar 4, 2015

Such a function would be really helpful. Otherwise it is almost impossible to use any rustc flag that is not exposed by cargo. It could be also usefull for IDEs to be able to run a simple cargo rustc -Z no-trans.

@RalfJung
Copy link
Member

I've already found myself using the verbose flag of cargo to obtain the rustc call, and then alter its flags to obtain, e.g., the LLVM bytecode or similar. A command like this would make that much easier.

@larsbergstrom
Copy link

@RalfJung Rust team members have told me that they replace the rustc binary with a shell script that calls out to the binary itself in order to add extra arguments, as a workaround for this lack of functionality when debugging.

@RalfJung
Copy link
Member

RalfJung commented Mar 11, 2015 via email

@strega-nil
Copy link

Attempting to get better rust support into Emacs's Flycheck has really shown me the usefulness of this -- this would make my life much, much easier.

@mkpankov
Copy link

I concur with @GBGamer - this is something really useful for editors and IDE's, as well as some refactoring and analysis tools.

I'd like to see this implemented as it would enable Emacs' Flycheck to use cargo and properly handle dependencies.

@gsingh93
Copy link

gsingh93 commented May 1, 2015

+1, the sooner this gets implemented the better.

bors added a commit that referenced this issue May 7, 2015
## Work in progress
I have followed issue #595 for a while now. I hope that this PR can solve it, after it's done of course.

@alexcrichton: on IRC the other day, you suggested adding a `Vec<String>` to the `CompileOptions`. I have done this, but wasn't sure what the best way to identify the correct `Target` would be, so currently everything gets compiled with the additional arguments. 
I considered adding a `Target` structure to the `CompileOptions` as well, and then in `cargo_rustc::build_base_args` only append the arguments if the `Target` matches. What do you think about this? Is there an easier way of figuring out the correct `Target`?

r? @alexcrichton
@alexcrichton
Copy link
Member Author

Added in #1568, thanks @sondrele!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-new-subcommand Area: new subcommand
Projects
None yet
Development

No branches or pull requests

10 participants