Skip to content

Commit 324a803

Browse files
committed
Add a cargo_metadata option to disable printing
Enable it by default, however
1 parent ccb7c88 commit 324a803

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/lib.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub struct Config {
8181
statik: Option<bool>,
8282
atleast_version: Option<String>,
8383
extra_args: Vec<OsString>,
84+
cargo_metadata: bool,
8485
}
8586

8687
#[derive(Debug)]
@@ -253,6 +254,7 @@ impl Config {
253254
statik: None,
254255
atleast_version: None,
255256
extra_args: vec![],
257+
cargo_metadata: true,
256258
}
257259
}
258260

@@ -279,6 +281,13 @@ impl Config {
279281
self
280282
}
281283

284+
/// Define whether metadata should be emitted for cargo allowing it to
285+
/// automatically link the binary. Defaults to `true`.
286+
pub fn cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Config {
287+
self.cargo_metadata = cargo_metadata;
288+
self
289+
}
290+
282291
/// Deprecated in favor fo the `probe` function
283292
#[doc(hidden)]
284293
pub fn find(&self, name: &str) -> Result<Library, String> {
@@ -333,6 +342,12 @@ impl Config {
333342
}
334343
cmd
335344
}
345+
346+
fn print_metadata(&self, s: &str) {
347+
if self.cargo_metadata {
348+
println!("cargo:{}", s);
349+
}
350+
}
336351
}
337352

338353
impl Library {
@@ -359,12 +374,14 @@ impl Library {
359374
for &(flag, val) in parts.iter() {
360375
match flag {
361376
"-L" => {
362-
println!("cargo:rustc-link-search=native={}", val);
377+
let meta = format!("rustc-link-search=native={}", val);
378+
config.print_metadata(&meta);
363379
dirs.push(PathBuf::from(val));
364380
self.link_paths.push(PathBuf::from(val));
365381
}
366382
"-F" => {
367-
println!("cargo:rustc-link-search=framework={}", val);
383+
let meta = format!("rustc-link-search=framework={}", val);
384+
config.print_metadata(&meta);
368385
self.framework_paths.push(PathBuf::from(val));
369386
}
370387
"-I" => {
@@ -373,9 +390,11 @@ impl Library {
373390
"-l" => {
374391
self.libs.push(val.to_string());
375392
if statik && !is_system(val, &dirs) {
376-
println!("cargo:rustc-link-lib=static={}", val);
393+
let meta = format!("rustc-link-lib=static={}", val);
394+
config.print_metadata(&meta);
377395
} else {
378-
println!("cargo:rustc-link-lib={}", val);
396+
let meta = format!("rustc-link-lib={}", val);
397+
config.print_metadata(&meta);
379398
}
380399
}
381400
_ => {}
@@ -384,9 +403,12 @@ impl Library {
384403

385404
let mut iter = output.split(' ');
386405
while let Some(part) = iter.next() {
387-
if part != "-framework" { continue }
406+
if part != "-framework" {
407+
continue
408+
}
388409
if let Some(lib) = iter.next() {
389-
println!("cargo:rustc-link-lib=framework={}", lib);
410+
let meta = format!("cargo:rustc-link-lib=framework={}", lib);
411+
config.print_metadata(&meta);
390412
self.frameworks.push(lib.to_string());
391413
}
392414
}

0 commit comments

Comments
 (0)