diff --git a/Cargo.lock b/Cargo.lock index 6a588b512e200..fc4e3bcd83afc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3672,6 +3672,7 @@ version = "0.0.0" dependencies = [ "build_helper", "cc", + "libc", ] [[package]] diff --git a/src/librustc_codegen_llvm/llvm/mod.rs b/src/librustc_codegen_llvm/llvm/mod.rs index d2d4187623981..975756753d6ad 100644 --- a/src/librustc_codegen_llvm/llvm/mod.rs +++ b/src/librustc_codegen_llvm/llvm/mod.rs @@ -10,11 +10,11 @@ pub use self::Linkage::*; use std::str::FromStr; use std::string::FromUtf8Error; -use std::slice; use std::ffi::CStr; use std::cell::RefCell; -use libc::{c_uint, c_char, size_t}; +use libc::c_uint; use rustc_data_structures::small_c_str::SmallCStr; +use rustc_llvm::RustString; pub mod archive_ro; pub mod diagnostic; @@ -81,21 +81,6 @@ impl FromStr for ArchiveKind { } } -#[repr(C)] -pub struct RustString { - bytes: RefCell>, -} - -/// Appending to a Rust string -- used by RawRustStringOstream. -#[no_mangle] -pub unsafe extern "C" fn LLVMRustStringWriteImpl(sr: &RustString, - ptr: *const c_char, - size: size_t) { - let slice = slice::from_raw_parts(ptr as *const u8, size as usize); - - sr.bytes.borrow_mut().extend_from_slice(slice); -} - pub fn SetInstructionCallConv(instr: &'a Value, cc: CallConv) { unsafe { LLVMSetInstructionCallConv(instr, cc as c_uint); diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml index 0fe327d5deeeb..4fc02e348f646 100644 --- a/src/librustc_llvm/Cargo.toml +++ b/src/librustc_llvm/Cargo.toml @@ -13,6 +13,9 @@ path = "lib.rs" static-libstdcpp = [] emscripten = [] +[dependencies] +libc = "0.2" + [build-dependencies] build_helper = { path = "../build_helper" } cc = "1.0.1" diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 647d473f01572..9c8943a9559a3 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -5,6 +5,26 @@ // NOTE: This crate only exists to allow linking on mingw targets. +use std::cell::RefCell; +use std::slice; +use libc::{c_char, size_t}; + + +#[repr(C)] +pub struct RustString { + pub bytes: RefCell>, +} + +/// Appending to a Rust string -- used by RawRustStringOstream. +#[no_mangle] +pub unsafe extern "C" fn LLVMRustStringWriteImpl(sr: &RustString, + ptr: *const c_char, + size: size_t) { + let slice = slice::from_raw_parts(ptr as *const u8, size as usize); + + sr.bytes.borrow_mut().extend_from_slice(slice); +} + /// Initialize targets enabled by the build script via `cfg(llvm_component = "...")`. /// N.B., this function can't be moved to `rustc_codegen_llvm` because of the `cfg`s. pub fn initialize_available_targets() {