Don't specify +whole-archive before rust 1.61

add_libdifftastic
Wilfred Hughes 2022-08-27 17:51:54 +07:00
parent 734a638ca2
commit aca46af40f
3 changed files with 20 additions and 7 deletions

7
Cargo.lock generated

@ -212,6 +212,7 @@ dependencies = [
"tree_magic_mini",
"typed-arena",
"unicode-width",
"version_check",
"walkdir",
"wu-diff",
]
@ -686,6 +687,12 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.2"

@ -55,6 +55,7 @@ pretty_assertions = "1.2.1"
[build-dependencies]
cc = "1.0.73"
rayon = "1.5.2"
version_check = "0.9.4"
[profile.release]
# Release builds don't have debug symbols by default. We explicitly

@ -1,5 +1,6 @@
use rayon::prelude::*;
use std::path::PathBuf;
use version_check as rustc;
struct TreeSitterParser {
name: &'static str,
@ -11,7 +12,15 @@ struct TreeSitterParser {
///
/// This should be possible in the cc crate directly after
/// https://github.com/rust-lang/cc-rs/pull/671
fn emit_whole_archive_link_flags(lib_name: &str, is_cpp: bool) {
fn emit_whole_archive_link_flags(build: &mut cc::Build, lib_name: &str, is_cpp: bool) {
if rustc::is_min_version("1.60.0").unwrap_or(false) {
// whole-archive was only stabilised in 1.61, and we don't
// need it in earlier versions.
return;
}
build.cargo_metadata(false);
println!("cargo:rustc-link-lib=static:+whole-archive={}", lib_name);
println!(
"cargo:rustc-link-search=native={}",
@ -93,9 +102,7 @@ impl TreeSitterParser {
cpp_build.file(dir.join(file));
}
cpp_build.cargo_metadata(false);
emit_whole_archive_link_flags(&format!("{}-cpp", self.name), true);
emit_whole_archive_link_flags(&mut cpp_build, &format!("{}-cpp", self.name), true);
cpp_build.compile(&format!("{}-cpp", self.name));
}
@ -108,9 +115,7 @@ impl TreeSitterParser {
build.file(dir.join(file));
}
build.cargo_metadata(false);
emit_whole_archive_link_flags(self.name, false);
emit_whole_archive_link_flags(&mut build, self.name, false);
build.compile(self.name);
}
}