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

Implement target-features flag #1556

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
23 changes: 13 additions & 10 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Options {
flag_bench: Option<String>,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_target_features: Vec<String>,
flag_manifest_path: Option<String>,
flag_verbose: bool,
arg_args: Vec<String>,
Expand All @@ -23,16 +24,17 @@ Usage:
cargo bench [options] [--] [<args>...]

Options:
-h, --help Print this message
--bench NAME Name of the bench to run
--no-run Compile, but don't run benchmarks
-p SPEC, --package SPEC Package to run benchmarks for
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose Use verbose output
-h, --help Print this message
--bench NAME Name of the bench to run
--no-run Compile, but don't run benchmarks
-p SPEC, --package SPEC Package to run benchmarks for
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--target-features FEATURES Build with the target features
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose Use verbose output

All of the trailing arguments are passed to the benchmark binaries generated
for filtering benchmarks and generally providing options configuring how they
Expand Down Expand Up @@ -61,6 +63,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
target_features: &options.flag_target_features,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
Expand Down
23 changes: 13 additions & 10 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct Options {
flag_features: Vec<String>,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_target_features: Vec<String>,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_release: bool,
Expand All @@ -25,16 +26,17 @@ Usage:
cargo build [options]

Options:
-h, --help Print this message
-p SPEC, --package SPEC Package to build
-j N, --jobs N The number of jobs to run in parallel
--lib Build only lib (if present in package)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
-h, --help Print this message
-p SPEC, --package SPEC Package to build
-j N, --jobs N The number of jobs to run in parallel
--lib Build only lib (if present in package)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--target-features FEATURES Build with the target features
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output

If the --package argument is given, then SPEC is a package id specification
which indicates which package should be built. If it is not given, then the
Expand All @@ -57,6 +59,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
target_features: &options.flag_target_features,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
Expand Down
23 changes: 13 additions & 10 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cargo::util::important_paths::{find_root_manifest_for_cwd};
#[derive(RustcDecodable)]
struct Options {
flag_target: Option<String>,
flag_target_features: Vec<String>,
flag_features: Vec<String>,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
Expand All @@ -22,16 +23,17 @@ Usage:
cargo doc [options]

Options:
-h, --help Print this message
--open Opens the docs in a browser after the operation
-p SPEC, --package SPEC Package to document
--no-deps Don't build documentation for dependencies
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
-v, --verbose Use verbose output
-h, --help Print this message
--open Opens the docs in a browser after the operation
-p SPEC, --package SPEC Package to document
--no-deps Don't build documentation for dependencies
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--target-features FEATURES Build with the target features
--manifest-path PATH Path to the manifest to document
-v, --verbose Use verbose output

By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
Expand All @@ -53,6 +55,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
target_features: &options.flag_target_features,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
Expand Down
23 changes: 13 additions & 10 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct Options {
flag_features: Vec<String>,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_target_features: Vec<String>,
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_release: bool,
Expand All @@ -23,16 +24,17 @@ Usage:
cargo run [options] [--] [<args>...]

Options:
-h, --help Print this message
--bin NAME Name of the bin target to run
--example NAME Name of the example target to run
-j N, --jobs N The number of jobs to run in parallel
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to execute
-v, --verbose Use verbose output
-h, --help Print this message
--bin NAME Name of the bin target to run
--example NAME Name of the example target to run
-j N, --jobs N The number of jobs to run in parallel
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--target-features FEATURES Build for the target triple
--manifest-path PATH Path to the manifest to execute
-v, --verbose Use verbose output

If neither `--bin` or `--example` are given, then if the project only has one
bin target it will be run. Otherwise `--bin` specifies the bin target to run,
Expand All @@ -58,6 +60,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
target_features: &options.flag_target_features,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: None,
Expand Down
25 changes: 14 additions & 11 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Options {
flag_no_run: bool,
flag_package: Option<String>,
flag_target: Option<String>,
flag_target_features: Vec<String>,
flag_verbose: bool,
}

Expand All @@ -24,17 +25,18 @@ Usage:
cargo test [options] [--] [<args>...]

Options:
-h, --help Print this message
--test NAME Name of the integration test to run
--bin NAME Name of the binary to run tests for
--no-run Compile, but don't run tests
-p SPEC, --package SPEC Package to run tests for
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build tests for
-v, --verbose Use verbose output
-h, --help Print this message
--test NAME Name of the integration test to run
--bin NAME Name of the binary to run tests for
--no-run Compile, but don't run tests
-p SPEC, --package SPEC Package to run tests for
-j N, --jobs N The number of jobs to run in parallel
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--target-features FEATURES Build with the the target features
--manifest-path PATH Path to the manifest to build tests for
-v, --verbose Use verbose output

All of the trailing arguments are passed to the test binaries generated for
filtering tests and generally providing options configuring how they run. For
Expand Down Expand Up @@ -68,6 +70,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
target_features: &options.flag_target_features,
features: &options.flag_features,
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| &s[..]),
Expand Down
15 changes: 11 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct CompileOptions<'a, 'b: 'a> {
pub jobs: Option<u32>,
/// The target platform to compile for (example: `i686-unknown-linux-gnu`).
pub target: Option<&'a str>,
pub target_features: &'a [String],
/// Extra features to build for the root package
pub features: &'a [String],
/// Flag if the default feature should be built for the root package
Expand Down Expand Up @@ -100,11 +101,14 @@ pub fn compile(manifest_path: &Path,

pub fn compile_pkg(package: &Package, options: &CompileOptions)
-> CargoResult<ops::Compilation> {
let CompileOptions { config, jobs, target, spec, features,
no_default_features, release, mode,
let CompileOptions { config, jobs, target, target_features, spec,
features, no_default_features, release, mode,
ref filter, ref exec_engine } = *options;

let target = target.map(|s| s.to_string());
let target_features = target_features.iter().flat_map(|s| {
s.split(' ')
}).map(|s| s.to_string()).collect::<Vec<String>>();
let features = features.iter().flat_map(|s| {
s.split(' ')
}).map(|s| s.to_string()).collect::<Vec<String>>();
Expand Down Expand Up @@ -165,7 +169,7 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)

let ret = {
let _p = profile::start("compiling");
let mut build_config = try!(scrape_build_config(config, jobs, target));
let mut build_config = try!(scrape_build_config(config, jobs, target, target_features));
build_config.exec_engine = exec_engine.clone();
build_config.release = release;
if let CompileMode::Doc { deps } = mode {
Expand Down Expand Up @@ -327,7 +331,8 @@ fn source_ids_from_config(config: &Config, cur_path: &Path)
/// * target.$target.libfoo.metadata
fn scrape_build_config(config: &Config,
jobs: Option<u32>,
target: Option<String>)
target: Option<String>,
target_features: Vec<String>)
-> CargoResult<ops::BuildConfig> {
let cfg_jobs = match try!(config.get_i64("build.jobs")) {
Some((n, p)) => {
Expand All @@ -354,6 +359,7 @@ fn scrape_build_config(config: &Config,
Some(triple) => try!(scrape_target_config(config, &triple)),
None => base.host.clone(),
};
base.target.features = target_features;
Ok(base)
}

Expand All @@ -367,6 +373,7 @@ fn scrape_target_config(config: &Config, triple: &str)
let mut ret = ops::TargetConfig {
ar: ar.map(|p| p.0),
linker: linker.map(|p| p.0),
features: Vec::new(),
overrides: HashMap::new(),
};
let table = match try!(config.get_table(&key)) {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path)
config: config,
jobs: None,
target: None,
target_features: &[],
features: &[],
no_default_features: false,
spec: None,
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct BuildConfig {
pub struct TargetConfig {
pub ar: Option<String>,
pub linker: Option<String>,
pub features: Vec<String>,
pub overrides: HashMap<String, BuildOutput>,
}

Expand Down Expand Up @@ -631,6 +632,10 @@ fn build_base_args(cx: &Context,
cmd.arg("--crate-type").arg(crate_type);
}

for target_feature in cx.build_config.target.features.iter() {
cmd.arg("-C").arg("target-feature=".to_string()+target_feature);
}

let prefer_dynamic = target.for_host() ||
(crate_types.contains(&"dylib") &&
pkg.package_id() != cx.resolve.root());
Expand Down