This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.rs
54 lines (41 loc) · 1.83 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2020 Parity Technologies
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate cmake;
use std::env;
use std::fs;
use cmake::Config;
fn main() {
let src = env::current_dir().unwrap().join("snappy");
let out = Config::new("snappy")
.define("CMAKE_VERBOSE_MAKEFILE", "ON")
.build_target("snappy")
.build();
let mut build = out.join("build");
// NOTE: the cfg! macro doesn't work when cross-compiling, it would return values for the host
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS is set by cargo.");
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV is set by cargo.");
if target_os.contains("windows") && target_env.contains("msvc") {
let stub = build.join("snappy-stubs-public.h");
let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) {
"bench" | "release" => "Release",
_ => "Debug",
};
build = build.join(profile);
fs::copy(stub, build.join("snappy-stubs-public.h")).unwrap();
}
fs::copy(src.join("snappy.h"), build.join("snappy.h")).unwrap();
println!("cargo:rustc-link-search=native={}", build.display());
println!("cargo:rustc-link-lib=static=snappy");
println!("cargo:include={}", build.display());
// https://github.com/alexcrichton/cc-rs/blob/ca70fd32c10f8cea805700e944f3a8d1f97d96d4/src/lib.rs#L891
if target_os.contains("macos") || target_os.contains("freebsd") || target_os.contains("openbsd") {
println!("cargo:rustc-link-lib=c++");
} else if !target_env.contains("msvc") && !target_os.contains("android") {
println!("cargo:rustc-link-lib=stdc++");
}
}