Skip to content

Commit 149ab5c

Browse files
committed
Merge branch 'master' of https://github.com/denzp/rustc-llvm-proxy into ir_reader_impl
2 parents 477a67c + 20815b5 commit 149ab5c

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc-llvm-proxy"
3-
version = "0.1.6"
3+
version = "0.1.8"
44
authors = ["Denys Zariaiev <[email protected]>"]
55
license = "MIT"
66

@@ -20,7 +20,7 @@ libloading = "0.5"
2020
lazy_static = "1.0"
2121
failure = "0.1"
2222
libc = "0.2"
23-
llvm-sys = { version = "70", features = ["no-llvm-linking"] }
23+
llvm-sys = { version = "70", features = ["no-llvm-linking", "disable-alltargets-init"] }
2424

2525
[build-dependencies]
2626
cargo_metadata = "0.6"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In case you are using `llvm-sys`, this can be achieved with a special feature:
2121
``` toml
2222
[dependencies.llvm-sys]
2323
version = "60"
24-
features = ["no-llvm-linking"]
24+
features = ["no-llvm-linking", "disable-alltargets-init"]
2525
```
2626

2727
Then all you need to do is to include the crate into your project:

build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ use std::env;
1212
fn main() {
1313
let out_dir = env::var("OUT_DIR").unwrap();
1414

15+
// Dummy declarations for RLS.
16+
if std::env::var("CARGO").unwrap_or_default().ends_with("rls") {
17+
llvm::Generator::default()
18+
.write_declarations(&format!("{}/llvm_gen.rs", out_dir))
19+
.expect("Unable to write generated LLVM declarations");
20+
21+
return;
22+
}
23+
1524
println!("cargo:rerun-if-changed=build.rs");
16-
println!("cargo:rerun-if-changed={}/llvm_gen.rs", out_dir);
1725

1826
llvm::Generator::default()
1927
.parse_llvm_sys_crate()

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![deny(warnings)]
2-
#![allow(non_snake_case)]
2+
#![allow(non_snake_case, unused_imports, unused_macros)]
33

44
//! Dynamically proxy LLVM calls into Rust own shared library! 🎉
55
//!

src/path.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use failure::Error;
77
pub fn find_lib_path() -> Result<PathBuf, Error> {
88
let paths = collect_possible_paths()?;
99

10-
if paths.len() == 0 {
10+
if paths.is_empty() {
1111
bail!("Unable to find possible LLVM shared lib locations.");
1212
}
1313

@@ -40,7 +40,7 @@ fn collect_possible_paths() -> Result<Vec<PathBuf>, Error> {
4040

4141
// Special case: find the location for Rust built from sources.
4242
if let Ok(env_path) = env::var("PATH") {
43-
for item in env_path.split(":") {
43+
for item in env_path.split(':') {
4444
let mut rustc_path = PathBuf::from(item);
4545

4646
rustc_path.pop();
@@ -65,7 +65,7 @@ fn collect_possible_paths() -> Result<Vec<PathBuf>, Error> {
6565
}
6666

6767
if let Ok(lib_paths) = env::var("LD_LIBRARY_PATH") {
68-
for item in lib_paths.split(":") {
68+
for item in lib_paths.split(':') {
6969
let mut possible_path = PathBuf::from(item);
7070
possible_path.pop();
7171

@@ -140,7 +140,17 @@ fn collect_possible_paths() -> Result<Vec<PathBuf>, Error> {
140140
// Fails if using nightly build from a specific date
141141
// e.g. nightly-2018-11-30-x86_64-unknown-linux-gnu
142142
fn extract_arch(toolchain: &str) -> String {
143-
toolchain.split('-').skip(1).collect::<Vec<_>>().join("-")
143+
toolchain
144+
.split('-')
145+
// Skip `nightly` rust version prefix.
146+
.skip(1)
147+
// Also skip rust version specification if exists.
148+
.skip_while(|item| match item.chars().next() {
149+
None | Some('0'...'9') => true,
150+
_ => false,
151+
})
152+
.collect::<Vec<_>>()
153+
.join("-")
144154
}
145155

146156
fn find_rustc() -> Option<PathBuf> {

tests/llvm-api.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ use std::ffi::{CStr, CString};
77
#[test]
88
fn module_creation() {
99
unsafe {
10-
let module = LLVMModuleCreateWithName(CString::new("test module").unwrap().as_ptr());
10+
let module_name = CString::new("test module").unwrap();
11+
let module = LLVMModuleCreateWithName(module_name.as_ptr());
1112

12-
LLVMSetDataLayout(
13-
module,
14-
CString::new("e-i64:64-v16:16-v32:32-n16:32:64")
15-
.unwrap()
16-
.as_ptr(),
17-
);
13+
let data_layout = CString::new("e-i64:64-v16:16-v32:32-n16:32:64").unwrap();
14+
LLVMSetDataLayout(module, data_layout.as_ptr());
1815

1916
let module_contents_raw = LLVMPrintModuleToString(module);
2017
let module_contents = CStr::from_ptr(module_contents_raw);

0 commit comments

Comments
 (0)