Implement build script

This commit is contained in:
David Tolnay 2020-01-24 14:41:39 -08:00
parent d4e0bcec2c
commit 9601a516d7
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 42 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/Cargo.lock
/target

14
Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "link-cplusplus"
version = "0.0.0"
authors = ["David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
[build-dependencies]
cc = "1.0"
[features]
default = [] # automatic
libstdcxx = [] # force libstdc++
libcxx = [] # force libc++
nothing = [] # link nothing, determined somewhere else

25
build.rs Normal file
View File

@ -0,0 +1,25 @@
fn main() {
let libstdcxx = cfg!(feature = "libstdcxx");
let libcxx = cfg!(feature = "libcxx");
let nothing = cfg!(feature = "nothing");
if nothing {
return;
}
if libstdcxx && libcxx {
println!(
"cargo:warning=-lstdc++ and -lc++ are both requested, \
using the platform's default"
);
}
match (libstdcxx, libcxx) {
(true, false) => println!("cargo:rustc-link-lib=stdc++"),
(false, true) => println!("cargo:rustc-link-lib=c++"),
(false, false) | (true, true) => {
// The platform's default.
cc::Build::new().cpp(true).compile("link-cplusplus");
}
}
}

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
// woohoo