Skip to content

Commit 25f6928

Browse files
authored
Merge pull request #463 from kakserpom/feat_cargo_php_features
feat(cargo-php): --features, --all-features, --no-default-features
2 parents 444dec9 + 8ccf845 commit 25f6928

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

crates/cli/src/lib.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ struct Install {
111111
/// the directory the command is called.
112112
#[arg(long)]
113113
manifest: Option<PathBuf>,
114+
#[arg(short = 'F', long, num_args = 1..)]
115+
features: Option<Vec<String>>,
116+
#[arg(long)]
117+
all_features: bool,
118+
#[arg(long)]
119+
no_default_features: bool,
114120
/// Whether to bypass the install prompt.
115121
#[clap(long)]
116122
yes: bool,
@@ -156,6 +162,12 @@ struct Stubs {
156162
/// provides a direct path to the extension shared library.
157163
#[arg(long, conflicts_with = "ext")]
158164
manifest: Option<PathBuf>,
165+
#[arg(short = 'F', long, num_args = 1..)]
166+
features: Option<Vec<String>>,
167+
#[arg(long)]
168+
all_features: bool,
169+
#[arg(long)]
170+
no_default_features: bool,
159171
}
160172

161173
impl Args {
@@ -172,7 +184,13 @@ impl Args {
172184
impl Install {
173185
pub fn handle(self) -> CrateResult {
174186
let artifact = find_ext(self.manifest.as_ref())?;
175-
let ext_path = build_ext(&artifact, self.release)?;
187+
let ext_path = build_ext(
188+
&artifact,
189+
self.release,
190+
self.features,
191+
self.all_features,
192+
self.no_default_features,
193+
)?;
176194

177195
let (mut ext_dir, mut php_ini) = if let Some(install_dir) = self.install_dir {
178196
(install_dir, None)
@@ -371,7 +389,14 @@ impl Stubs {
371389
ext_path
372390
} else {
373391
let target = find_ext(self.manifest.as_ref())?;
374-
build_ext(&target, false)?.into()
392+
build_ext(
393+
&target,
394+
false,
395+
self.features,
396+
self.all_features,
397+
self.no_default_features,
398+
)?
399+
.into()
375400
};
376401

377402
if !ext_path.is_file() {
@@ -469,17 +494,38 @@ fn find_ext(manifest: Option<&PathBuf>) -> AResult<cargo_metadata::Target> {
469494
///
470495
/// * `target` - The target to compile.
471496
/// * `release` - Whether to compile the target in release mode.
497+
/// * `features` - Optional list of features.
472498
///
473499
/// # Returns
474500
///
475501
/// The path to the target artifact.
476-
fn build_ext(target: &Target, release: bool) -> AResult<Utf8PathBuf> {
502+
fn build_ext(
503+
target: &Target,
504+
release: bool,
505+
features: Option<Vec<String>>,
506+
all_features: bool,
507+
no_default_features: bool,
508+
) -> AResult<Utf8PathBuf> {
477509
let mut cmd = Command::new("cargo");
478510
cmd.arg("build")
479511
.arg("--message-format=json-render-diagnostics");
480512
if release {
481513
cmd.arg("--release");
482514
}
515+
if let Some(features) = features {
516+
cmd.arg("--features");
517+
for feature in features {
518+
cmd.arg(feature);
519+
}
520+
}
521+
522+
if all_features {
523+
cmd.arg("--all-features");
524+
}
525+
526+
if no_default_features {
527+
cmd.arg("--no-default-features");
528+
}
483529

484530
let mut spawn = cmd
485531
.stdout(Stdio::piped())

0 commit comments

Comments
 (0)