Skip to content

Build librustc_llvm as a dylib, and install it as part of the private rustc crates. #50404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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 src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@ dependencies = [
"graphviz 0.0.0",
"jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc_macro 0.0.0",
"rustc_apfloat 0.0.0",
Expand Down Expand Up @@ -2092,7 +2093,6 @@ dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"build_helper 0.1.0",
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_cratesio_shim 0.0.0",
]

Expand Down
46 changes: 29 additions & 17 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,11 @@ impl Step for CodegenBackend {
let mut files = files.into_iter()
.filter(|f| {
let filename = f.file_name().unwrap().to_str().unwrap();
is_dylib(filename) && filename.contains("rustc_codegen_llvm-")
is_dylib(filename) && (filename.contains("rustc_codegen_llvm-") ||
filename.contains("rustc_llvm-"))
});
let llvm_crate = files.next()
.unwrap_or_else(|| panic!("need the rustc_trans llvm dylib") );
let codegen_backend = match files.next() {
Some(f) => f,
None => panic!("no dylibs built for codegen backend?"),
Expand All @@ -668,8 +671,13 @@ impl Step for CodegenBackend {
f.display());
}
let stamp = codegen_backend_stamp(builder, compiler, target, backend);

let llvm_crate = llvm_crate.to_str().unwrap();
let codegen_backend = codegen_backend.to_str().unwrap();
t!(t!(File::create(&stamp)).write_all(codegen_backend.as_bytes()));
let mut stamp = t!(File::create(&stamp));
t!(stamp.write_all(codegen_backend.as_bytes()));
t!(stamp.write_all(&[0]));
t!(stamp.write_all(llvm_crate.as_bytes()));
}
}

Expand Down Expand Up @@ -750,28 +758,32 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
// Here we're looking for the output dylib of the `CodegenBackend` step and
// we're copying that into the `codegen-backends` folder.
let dst = builder.sysroot_codegen_backends(target_compiler);
let sysroot_dst = builder.sysroot_libdir(target_compiler, target);
t!(fs::create_dir_all(&dst));

t!(fs::create_dir_all(&sysroot_dst));
if builder.config.dry_run {
return;
}

for backend in builder.config.rust_codegen_backends.iter() {
let stamp = codegen_backend_stamp(builder, compiler, target, *backend);
let mut dylib = String::new();
t!(t!(File::open(&stamp)).read_to_string(&mut dylib));
let file = Path::new(&dylib);
let filename = file.file_name().unwrap().to_str().unwrap();
// change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so`
let target_filename = {
let dash = filename.find("-").unwrap();
let dot = filename.find(".").unwrap();
format!("{}-{}{}",
&filename[..dash],
backend,
&filename[dot..])
};
builder.copy(&file, &dst.join(target_filename));
for file in builder.read_stamp_file(&stamp) {
let filename = file.file_name().unwrap().to_str().unwrap();
if filename.contains("rustc_llvm") {
builder.copy(&file, &sysroot_dst.join(filename));
} else {
// change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so`
let target_filename = {
let dash = filename.find("-").unwrap();
let dot = filename.find(".").unwrap();
format!("{}-{}{}",
&filename[..dash],
backend,
&filename[dot..])
};
builder.copy(&file, &dst.join(target_filename));
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ chalk-engine = { version = "0.6.0", default-features=false }
# compiles, then please feel free to do so!
flate2 = "1.0"
tempdir = "0.3"

libc = "0.2"

7 changes: 4 additions & 3 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use std::sync::mpsc::{channel, Sender, Receiver};
use std::slice;
use std::time::Instant;
use std::thread;
use libc::{c_uint, c_void, c_char, size_t};
use libc::{c_uint, c_char, size_t};

pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
("pic", llvm::RelocMode::PIC),
Expand Down Expand Up @@ -436,7 +436,7 @@ unsafe extern "C" fn report_inline_asm<'a, 'b>(cgcx: &'a CodegenContext,
}

unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
user: *const c_void,
user: *const ::std::os::raw::c_void,
cookie: c_uint) {
if user.is_null() {
return
Expand All @@ -449,7 +449,8 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
report_inline_asm(cgcx, &msg, cookie);
}

unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_void) {
unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef,
user: *mut ::std::os::raw::c_void) {
if user.is_null() {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ build = "build.rs"
[lib]
name = "rustc_llvm"
path = "lib.rs"
crate-type = ["dylib"]

[features]
static-libstdcpp = []
emscripten = []

[dependencies]
bitflags = "1.0"
libc = "0.2"
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
pub use self::OptimizationDiagnosticKind::*;
pub use self::Diagnostic::*;

use libc::c_uint;
use std::os::raw::c_uint;
use std::ptr;

use {DiagnosticInfoRef, TwineRef, ValueRef};
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram
DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
DINameSpace, DIFlags};

use libc::{c_uint, c_int, size_t, c_char};
use libc::{c_longlong, c_ulonglong, c_void};
use std::os::raw::{c_uint, c_int, c_char};
use std::os::raw::{c_longlong, c_ulonglong, c_void};

use super::size_t;

use RustStringRef;

pub type Opcode = u32;
pub type Bool = c_uint;
pub type Bool = c_int;

pub const True: Bool = 1 as Bool;
pub const False: Bool = 0 as Bool;
Expand Down Expand Up @@ -482,7 +484,7 @@ pub mod debuginfo {
bitflags! {
#[repr(C)]
#[derive(Default)]
pub struct DIFlags: ::libc::uint32_t {
pub struct DIFlags: u32 {
const FlagZero = 0;
const FlagPrivate = 1;
const FlagProtected = 2;
Expand Down Expand Up @@ -1323,7 +1325,7 @@ extern "C" {

pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, Value: Bool);
pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, Value: c_uint);
pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef, Value: Bool);
pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: PassManagerBuilderRef,
threshold: c_uint);
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,17 @@ pub fn initialize_available_targets() {
}

pub fn last_error() -> Option<String> {
extern "C" {
fn free(ptr: *mut std::os::raw::c_void);
}
unsafe {
let cstr = LLVMRustGetLastError();
if cstr.is_null() {
None
} else {
let err = CStr::from_ptr(cstr).to_bytes();
let err = String::from_utf8_lossy(err).to_string();
libc::free(cstr as *mut _);
free(cstr as *mut _);
Some(err)
}
}
Expand Down