Skip to content

Commit

Permalink
Adding feature-flags to cargo publish and cargo package
Browse files Browse the repository at this point in the history
This change adds the `--features` and `--all-features` flags to the
above mentioned commands. This is to allow publishing of crates that
have certain feature requirements for compilation, without having to
rely on `--no-verify` which isn't good practise.

This PR adds two new fields `features` and `all_features` to both the
`PackageOpts` and `PublishOpts` and also adds the argument options
to the CLI commands.

Merging this feature will allow people to publish crates on crates.io
that require some feature flag to compile (or all?) without needing
to rely on not checking the package before uploading, potentially
resulting in less packaging errors and broken packages.
  • Loading branch information
spacekookie committed Dec 26, 2018
1 parent fef7802 commit 256fc39
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn cli() -> App {
))
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_features()
.arg_manifest_path()
.arg_jobs()
}
Expand All @@ -42,6 +43,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
allow_dirty: args.is_present("allow-dirty"),
target: args.target(),
jobs: args.jobs()?,
registry: None,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
},
)?;
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn cli() -> App {
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_manifest_path()
.arg_features()
.arg_jobs()
.arg_dry_run("Perform all checks without uploading")
.arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
Expand All @@ -40,6 +41,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
jobs: args.jobs()?,
dry_run: args.is_present("dry-run"),
registry,
features: args._values_of("features"),
all_features: args.is_present("all-features"),
},
)?;
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct PackageOpts<'cfg> {
pub verify: bool,
pub jobs: Option<u32>,
pub target: Option<String>,
pub registry: Option<String>,
pub features: Vec<String>,
pub all_features: bool,
}

static VCS_INFO_FILE: &'static str = ".cargo_vcs_info.json";
Expand Down Expand Up @@ -447,9 +450,9 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
&ops::CompileOptions {
config,
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
features: Vec::new(),
features: opts.features.clone(),
no_default_features: false,
all_features: false,
all_features: opts.all_features,
spec: ops::Packages::Packages(Vec::new()),
filter: ops::CompileFilter::Default {
required_features_filterable: true,
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct PublishOpts<'cfg> {
pub target: Option<String>,
pub dry_run: bool,
pub registry: Option<String>,
pub features: Vec<String>,
pub all_features: bool
}

pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
Expand Down Expand Up @@ -82,6 +84,9 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
allow_dirty: opts.allow_dirty,
target: opts.target.clone(),
jobs: opts.jobs,
registry: opts.registry.clone(),
features: opts.features.clone(),
all_features: opts.all_features,
},
)?
.unwrap();
Expand Down

0 comments on commit 256fc39

Please sign in to comment.