Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

Fix iOS compilation error #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions snappy-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ use cmake::Config;
fn main() {
let src = env::current_dir().unwrap().join("snappy");

let out = Config::new("snappy")
let mut cfg = Config::new("snappy");
cfg
.define("CMAKE_VERBOSE_MAKEFILE", "ON")
.build_target("snappy")
.build();

let mut build = out.join("build");
.build_target("snappy");

// 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("ios") {
cfg
.define("CMAKE_OSX_SYSROOT", "");
}
let out = cfg.build();

let mut build = out.join("build");

if target_os.contains("windows") && target_env.contains("msvc") {
let stub = build.join("snappy-stubs-public.h");

Expand All @@ -38,7 +44,7 @@ fn main() {
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") {
if target_os.contains("macos") || target_os.contains("ios") || 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++");
Expand Down