Skip to content

Commit a383401

Browse files
committed
Rename link() to cargo_metadata() and cover all the cargo:… flags.
1 parent 849423b commit a383401

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

gcc-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ fn main() {
7272

7373
// This tests whether we can build a library but not link it to the main crate.
7474
// The test module will do its own linking.
75-
gcc::Config::new().link(false).file("src/opt_linkage.c").compile("libOptLinkage.a");
75+
gcc::Config::new().cargo_metadata(false).file("src/opt_linkage.c").compile("libOptLinkage.a");
7676
}

src/lib.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct Config {
7575
env: Vec<(OsString, OsString)>,
7676
compiler: Option<PathBuf>,
7777
archiver: Option<PathBuf>,
78-
link: bool,
78+
cargo_metadata: bool,
7979
}
8080

8181
fn getenv(v: &str) -> Option<String> {
@@ -134,7 +134,7 @@ impl Config {
134134
env: Vec::new(),
135135
compiler: None,
136136
archiver: None,
137-
link: true
137+
cargo_metadata: true
138138
}
139139
}
140140

@@ -288,13 +288,10 @@ impl Config {
288288
self.archiver = Some(archiver.as_ref().to_owned());
289289
self
290290
}
291-
/// Define whether the compiled archive will automatically be linked.
292-
///
293-
/// If you don't want the compiled archive to be linked into the rust
294-
/// binary automatically, you can set this option to `false`. It can
295-
/// still be linked explicitly using the `#[cfg(link())]` directive.
296-
pub fn link(&mut self, link: bool) -> &mut Config {
297-
self.link = link;
291+
/// Define whether metadata should be emitted for cargo allowing it to
292+
/// automatically link the binary. Defaults to `true`.
293+
pub fn cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Config {
294+
self.cargo_metadata = cargo_metadata;
298295
self
299296
}
300297

@@ -324,16 +321,18 @@ impl Config {
324321
}
325322

326323
self.assemble(lib_name, &dst.join(output), &objects);
327-
println!("cargo:rustc-link-search=native={}", dst.display());
328-
if self.link {
324+
325+
if self.cargo_metadata {
329326
println!("cargo:rustc-link-lib=static={}",
330327
&output[3..output.len() - 2]);
331-
}
328+
println!("cargo:rustc-link-search=native={}", dst.display());
329+
330+
// Add specific C++ libraries, if enabled.
331+
if self.cpp {
332+
if let Some(stdlib) = self.get_cpp_link_stdlib() {
333+
println!("cargo:rustc-link-lib={}", stdlib);
334+
}
332335

333-
// Add specific C++ libraries, if enabled.
334-
if self.cpp {
335-
if let Some(stdlib) = self.get_cpp_link_stdlib() {
336-
println!("cargo:rustc-link-lib={}", stdlib);
337336
}
338337
}
339338
}

0 commit comments

Comments
 (0)