Skip to content

Commit 47e932b

Browse files
committed
Fix weird implicit dependency between rustllvm and rustc_codegen_llvm
rustllvm relies on the `LLVMRustStringWriteImpl` symbol existing, but this symbol was previously defined in a *downstream* crate (rustc_codegen_llvm, which depends on rustc_llvm. While this somehow worked under the old 'separate bootstrap step for codegen' scheme, it meant that rustc_llvm could not actually be built by itself, since it relied linking to the downstream rustc_codegen_llvm crate. Now that librustc_codegen_llvm is just a normal crate, we actually try to build a standalone rustc_llvm when we run tests. This commit moves `LLVMRustStringWriteImpl` into rustc_llvm (technically the rustllvm directory, which has its contents built by rustc_llvm). This ensures that we can build each crate in the graph by itself, without requiring that any downstream crates be linked in as well.
1 parent 150d328 commit 47e932b

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,7 @@ version = "0.0.0"
36723672
dependencies = [
36733673
"build_helper",
36743674
"cc",
3675+
"libc",
36753676
]
36763677

36773678
[[package]]

src/librustc_codegen_llvm/llvm/mod.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ pub use self::Linkage::*;
1010

1111
use std::str::FromStr;
1212
use std::string::FromUtf8Error;
13-
use std::slice;
1413
use std::ffi::CStr;
1514
use std::cell::RefCell;
16-
use libc::{c_uint, c_char, size_t};
15+
use libc::c_uint;
1716
use rustc_data_structures::small_c_str::SmallCStr;
17+
use rustc_llvm::RustString;
1818

1919
pub mod archive_ro;
2020
pub mod diagnostic;
@@ -81,21 +81,6 @@ impl FromStr for ArchiveKind {
8181
}
8282
}
8383

84-
#[repr(C)]
85-
pub struct RustString {
86-
bytes: RefCell<Vec<u8>>,
87-
}
88-
89-
/// Appending to a Rust string -- used by RawRustStringOstream.
90-
#[no_mangle]
91-
pub unsafe extern "C" fn LLVMRustStringWriteImpl(sr: &RustString,
92-
ptr: *const c_char,
93-
size: size_t) {
94-
let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
95-
96-
sr.bytes.borrow_mut().extend_from_slice(slice);
97-
}
98-
9984
pub fn SetInstructionCallConv(instr: &'a Value, cc: CallConv) {
10085
unsafe {
10186
LLVMSetInstructionCallConv(instr, cc as c_uint);

src/librustc_llvm/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ path = "lib.rs"
1313
static-libstdcpp = []
1414
emscripten = []
1515

16+
[dependencies]
17+
libc = "0.2"
18+
1619
[build-dependencies]
1720
build_helper = { path = "../build_helper" }
1821
cc = "1.0.1"

src/librustc_llvm/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55

66
// NOTE: This crate only exists to allow linking on mingw targets.
77

8+
use std::cell::RefCell;
9+
use std::slice;
10+
use libc::{c_char, size_t};
11+
12+
13+
#[repr(C)]
14+
pub struct RustString {
15+
pub bytes: RefCell<Vec<u8>>,
16+
}
17+
18+
/// Appending to a Rust string -- used by RawRustStringOstream.
19+
#[no_mangle]
20+
pub unsafe extern "C" fn LLVMRustStringWriteImpl(sr: &RustString,
21+
ptr: *const c_char,
22+
size: size_t) {
23+
let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
24+
25+
sr.bytes.borrow_mut().extend_from_slice(slice);
26+
}
27+
828
/// Initialize targets enabled by the build script via `cfg(llvm_component = "...")`.
929
/// N.B., this function can't be moved to `rustc_codegen_llvm` because of the `cfg`s.
1030
pub fn initialize_available_targets() {

0 commit comments

Comments
 (0)