Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Make the crate cross-compilation-friendly #4

Merged
merged 1 commit into from
Dec 12, 2018
Merged
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
14 changes: 9 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
extern crate cc;

use std::env::var;

fn main() {
let target_os = var("CARGO_CFG_TARGET_OS").unwrap();
let target_family = var("CARGO_CFG_TARGET_FAMILY").unwrap();

let mut base_config = cc::Build::new();
base_config.include(".");
base_config.include("libusb/libusb");

if cfg!(target_os = "macos") {
if target_os == "macos" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these always match or should we use contains instead for all checks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that CARGO_CFG_TARGET_OS contains the same value as cfg!(target_os), and right now it works by matching exactly, so I suppose it will still continue to work by matching exactly.

base_config.define("OS_DARWIN", Some("1"));
base_config.file("libusb/libusb/os/darwin_usb.c");
link_framework("CoreFoundation");
link_framework("IOKit");
link("objc", false);
}
if cfg!(target_os = "linux") {
if target_os == "linux" {
base_config.define("OS_LINUX", Some("1"));
base_config.define("HAVE_ASM_TYPES_H", Some("1"));
base_config.define("HAVE_LINUX_NETLINK_H", Some("1"));
Expand All @@ -24,7 +29,7 @@ fn main() {
base_config.define("_GNU_SOURCE", Some("1"));
}

if cfg!(unix) {
if target_family == "unix" {
base_config.define("HAVE_DLFCN_H", Some("1"));
base_config.define("HAVE_GETTIMEOFDAY", Some("1"));
base_config.define("HAVE_INTTYPES_H", Some("1"));
Expand All @@ -48,7 +53,7 @@ fn main() {
base_config.file("libusb/libusb/os/threads_posix.c");
}

if cfg!(windows) {
if target_os == "windows" {
base_config.define("OS_WINDOWS", Some("1"));
base_config.file("libusb/libusb/os/poll_windows.c");
base_config.file("libusb/libusb/os/threads_windows.c");
Expand All @@ -74,7 +79,6 @@ fn main() {
}

pub fn link(name: &str, bundled: bool) {
use std::env::var;
let target = var("TARGET").unwrap();
let target: Vec<_> = target.split('-').collect();
if target.get(2) == Some(&"windows") {
Expand Down