summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-06-01 14:21:11 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-06-01 14:21:11 +0200
commit5444bab8ecd2c702442e412012f5fb7c415b92b4 (patch)
treed44e72cd858442128b0db54802e0be5d5e21645b /src
parentdaf1935534de9cd09a8d3f4384af20eaa4fe0f01 (diff)
Add a way to get the target triple, and do our best guess at it until we have proper clang support.
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index c5807d2b..a70425c7 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -139,6 +139,9 @@ pub struct BindgenContext<'ctx> {
/// The active replacements collected from replaces="xxx" annotations.
replacements: HashMap<Vec<String>, ItemId>,
+ /// The target string bindgen was able to deduce from the input.
+ effective_target: String,
+
collected_typerefs: bool,
/// Dummy structures for code generation.
@@ -232,6 +235,32 @@ impl<'ctx> BindgenContext<'ctx> {
parse_options)
.expect("TranslationUnit::parse failed");
+ // TODO(emilio): Use the CXTargetInfo here when available.
+ //
+ // see: https://reviews.llvm.org/D32389
+ let mut effective_target = None;
+ for opt in &options.clang_args {
+ if opt.starts_with("--target=") {
+ let mut split = opt.split('=');
+ split.next();
+ effective_target = Some(split.next().unwrap().to_owned());
+ break;
+ }
+ }
+
+ if effective_target.is_none() {
+ use std::env;
+ // If we're running from a build script, try to find the cargo
+ // target.
+ effective_target = env::var("TARGET").ok();
+ }
+
+ if effective_target.is_none() {
+ const HOST_TARGET: &'static str =
+ include_str!(concat!(env!("OUT_DIR"), "/host-target.txt"));
+ effective_target = Some(HOST_TARGET.to_owned());
+ }
+
let root_module = Self::build_root_module(ItemId(0));
let mut me = BindgenContext {
items: Default::default(),
@@ -244,6 +273,7 @@ impl<'ctx> BindgenContext<'ctx> {
currently_parsed_types: vec![],
parsed_macros: Default::default(),
replacements: Default::default(),
+ effective_target: effective_target.unwrap(),
collected_typerefs: false,
gen_ctx: None,
span: DUMMY_SP,
@@ -764,6 +794,11 @@ impl<'ctx> BindgenContext<'ctx> {
Item::new(id, None, None, id, ItemKind::Module(module))
}
+ /// Returns the target triple bindgen is running over.
+ pub fn target(&self) -> &str {
+ &self.effective_target
+ }
+
/// Get the root module.
pub fn root_module(&self) -> ItemId {
self.root_module