Skip to content

Cargo CLI parameters added #3677

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn call_main_without_stdin<Flags: Decodable>(
{
let docopt = Docopt::new(usage).unwrap()
.options_first(options_first)
.argv(args.iter().map(|s| &s[..]))
.argv(args.iter().take_while(|x| *x != "--").map(|s| &s[..]))
.help(true);

let flags = docopt.decode().map_err(|e| {
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{HashMap, BTreeSet, HashSet};
use std::env;
use std::fs;
use std::path::{PathBuf, Path};
use std::str;
Expand Down Expand Up @@ -114,6 +115,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
.env("RUSTC", &cx.config.rustc()?.path)
.env("RUSTDOC", &*cx.config.rustdoc()?);

for arg in env::args_os().skip_while(|x| x != "--").skip(1) {
cmd.arg(arg);
}

if let Some(links) = unit.pkg.manifest().links() {
cmd.env("CARGO_MANIFEST_LINKS", links);
}
Expand Down
9 changes: 8 additions & 1 deletion src/doc/build-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ the build command works.
## Inputs to the Build Script

When the build script is run, there are a number of inputs to the build script,
all passed in the form of [environment variables][env].
all passed in the form of [environment variables][env] or as a CLI command prameters.

CLI parameters for the build script can be passed after '--' flag, eg.:
```bash
cargo build --release -- --source-dir=/tmp/data -a
```

Parameters after '--' (--source-dir and -a) will be ignored by cargo and passed to build script. Parameters can be read via std::env::args().

In addition to environment variables, the build script’s current directory is
the source directory of the build script’s package.
Expand Down