Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ libc = "0.2"
bitflags = "2"

[build-dependencies]
cc = "1"
bindgen = "0.70.0"
103 changes: 38 additions & 65 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cc::Build;

use std::{fs, process::Command};
use std::{ fs::OpenOptions, io::Write, path::PathBuf, process::Command};

fn get_llvm_output(arg: &str) -> String {
let llvm_config = std::env::var("LLVM_CONFIG").unwrap_or_else(|_| "llvm-config".into());
Expand All @@ -15,71 +13,46 @@ fn get_llvm_output(arg: &str) -> String {
String::from_utf8(res.stdout).unwrap().trim().to_string()
}

fn match_libname(name: &str) -> Option<String> {
if name.starts_with("liblldb.so") || name.starts_with("liblldb-") {
if let Some(pos) = name.rfind(".so") {
return Some(name["lib".len()..pos].into());
}
}
if name.starts_with("liblldb") && name.ends_with(".dylib") {
// Trim the leading "lib" and trailing ".dylib"
return Some(name[3..name.len() - 6].into());
}
if name.starts_with("liblldb") && name.ends_with(".lib") {
// windows will have liblldb.lib
// Trim the trailing ".lib"
return Some(name[0..name.len() - 4].into());
}
None
}

#[cfg(test)]
#[test]
fn test_match_libname() {
assert_eq!(match_libname("liblldb.so"), Some("lldb"));
assert_eq!(match_libname("liblldb-3.8.so"), Some("lldb-3.8"));
assert_eq!(match_libname("liblldbIntelFeatures.so"), None);
assert_eq!(match_libname("liblldb.lib"), Some("liblldb"));
}

fn get_compiler_config() -> Build {
// We use the `llvm-config` utility to get the include and library paths
// as well as the name of the shared library.
fn main() {
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
println!("cargo:rerun-if-env-changed=LLDB_ADDITIONAL_INCLUDE_DIRS");
println!("cargo:rerun-if-changed=src/lib.rs");
println!("cargo:rerun-if-changed=src/debugger.cpp");
println!("cargo:rerun-if-changed=include/debuger.h");
println!("cargo:rustc-link-lib=lldb");
println!("cargo:rustc-link-lib=stdc++");

let llvm_headers_path = get_llvm_output("--includedir");
let llvm_lib_path = get_llvm_output("--libdir");
let lib_name = fs::read_dir(&llvm_lib_path)
.expect("failed to stat libdir from llvm-config")
.filter_map(|entry| match_libname(entry.unwrap().file_name().to_str().unwrap()))
.next()
.expect("unable to locate shared library of liblldb");
println!("cargo:rustc-link-search={llvm_lib_path}");
println!("cargo:rustc-link-lib={lib_name}");
let mut res = cc::Build::new();
res.include(llvm_headers_path);
// if llvm is in the development tree, (in other words, just after build)
// we may need to add several other directories to include lldb
// those directories are not constant (might depend on build system) so
// we allow user to specify with PATH
if let Some(dirs) = std::env::var_os("LLDB_ADDITIONAL_INCLUDE_DIRS") {
for path in std::env::split_paths(&dirs) {
res.include(path);
}
}
res
}

fn main() {
println!("cargo:rerun-if-env-changed=DOCS_RS");
if std::env::var("DOCS_RS").is_ok() {
return;
}
get_compiler_config()
.cpp(true)
.flag("-std=c++14")
.warnings(false)
.include("src")
.file("src/lldb/UnityBuild.cpp")
.compile("liblldb-c.a");
println!("cargo:rustc-link-search={}", llvm_lib_path);

let bindings = bindgen::Builder::default()
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.header(format!("{}/lldb/API/LLDB.h", llvm_headers_path))
.layout_tests(false)
.allowlist_item("lldb::.*")
.opaque_type(".*")
.no_copy("lldb::.*")
.enable_cxx_namespaces()
.generate_cstr(true)
.clang_arg("-xc++")
.generate()
.expect("Unable to generate bindings");

let bindings = bindings.to_string().replace(
"pub _bindgen_opaque_blob",
"pub _bindgen_phantom: [u64; 3usize], pub _bindgen_opaque_blob",
);

let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(PathBuf::from("./src/").join("bindings.rs"))
.expect("could not open bindings file");

file.write(bindings.as_bytes())
.expect("could not write bindings file");

}
28,078 changes: 28,078 additions & 0 deletions src/bindings.rs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
//! It is primarily for use by a higher level crate, such as
//! [lldb.rs](https://crates.io/crates/lldb/).

mod lldb_sys;
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(improper_ctypes)]

pub use crate::lldb_sys::*;

#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
}
mod bindings;
pub use bindings::root::lldb::*;
70 changes: 0 additions & 70 deletions src/lldb/Bindings/LICENSE.TXT

This file was deleted.

78 changes: 0 additions & 78 deletions src/lldb/Bindings/LLDBBinding.h

This file was deleted.

Loading
Loading