From d03fd7e332ed8615895f73fdaa36905657742c91 Mon Sep 17 00:00:00 2001
From: Ian Douglas Scott <ian@iandouglasscott.com>
Date: Thu, 29 Jun 2017 16:17:14 -0700
Subject: [PATCH] Determine default target based on LLVM triple at build

---
 Cargo.toml     | 1 +
 build.rs       | 5 +++++
 src/bin/pkg.rs | 5 +----
 3 files changed, 7 insertions(+), 4 deletions(-)
 create mode 100644 build.rs

diff --git a/Cargo.toml b/Cargo.toml
index 8f56ddc..52658fa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,7 @@
 [package]
 name = "pkgutils"
 version = "0.1.1"
+build = "build.rs"
 
 [lib]
 name = "pkgutils"
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..97131b9
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,5 @@
+use std::env;
+
+fn main() {
+    println!("cargo:rustc-env=PKG_DEFAULT_TARGET={}", env::var("TARGET").unwrap());
+}
diff --git a/src/bin/pkg.rs b/src/bin/pkg.rs
index 65ea06e..c19c109 100644
--- a/src/bin/pkg.rs
+++ b/src/bin/pkg.rs
@@ -129,10 +129,7 @@ fn main() {
         ).subcommand(SubCommand::with_name("upgrade")
         ).get_matches();
 
-    let target = matches.value_of("target")
-        .or(option_env!("TARGET"))
-        .expect(concat!("pkg was not compiled with a target, ",
-                        "and --target was not specified"));
+    let target = matches.value_of("target").unwrap_or(env!("PKG_DEFAULT_TARGET"));
 
     let repo = Repo::new(target);
 
-- 
GitLab