Skip to content

Commit 70e084a

Browse files
committed
Inline ArchiveConfig struct into LlvmArchiveBuilder
1 parent 4e02a92 commit 70e084a

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

+21-28
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
1515
use rustc_session::cstore::{DllCallingConvention, DllImport};
1616
use rustc_session::Session;
1717

18-
struct ArchiveConfig<'a> {
19-
pub sess: &'a Session,
20-
pub dst: PathBuf,
21-
pub src: Option<PathBuf>,
22-
}
23-
2418
/// Helper for adding many files to an archive.
2519
#[must_use = "must call build() to finish building the archive"]
2620
pub struct LlvmArchiveBuilder<'a> {
27-
config: ArchiveConfig<'a>,
21+
sess: &'a Session,
22+
dst: PathBuf,
23+
src: Option<PathBuf>,
2824
removals: Vec<String>,
2925
additions: Vec<Addition>,
3026
src_archive: Option<Option<ArchiveRO>>,
@@ -50,10 +46,6 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
5046
}
5147
}
5248

53-
fn archive_config<'a>(sess: &'a Session, output: &Path, input: Option<&Path>) -> ArchiveConfig<'a> {
54-
ArchiveConfig { sess, dst: output.to_path_buf(), src: input.map(|p| p.to_path_buf()) }
55-
}
56-
5749
/// Map machine type strings to values of LLVM's MachineTypes enum.
5850
fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
5951
match cpu {
@@ -69,9 +61,10 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
6961
/// Creates a new static archive, ready for modifying the archive specified
7062
/// by `config`.
7163
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> LlvmArchiveBuilder<'a> {
72-
let config = archive_config(sess, output, input);
7364
LlvmArchiveBuilder {
74-
config,
65+
sess,
66+
dst: output.to_path_buf(),
67+
src: input.map(|p| p.to_path_buf()),
7568
removals: Vec::new(),
7669
additions: Vec::new(),
7770
src_archive: None,
@@ -131,11 +124,11 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
131124
/// `Archive`.
132125
fn build(mut self) {
133126
let kind = self.llvm_archive_kind().unwrap_or_else(|kind| {
134-
self.config.sess.fatal(&format!("Don't know how to build archive of type: {}", kind))
127+
self.sess.fatal(&format!("Don't know how to build archive of type: {}", kind))
135128
});
136129

137130
if let Err(e) = self.build_with_llvm(kind) {
138-
self.config.sess.fatal(&format!("failed to build archive: {}", e));
131+
self.sess.fatal(&format!("failed to build archive: {}", e));
139132
}
140133
}
141134

@@ -151,7 +144,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
151144
output_path.with_extension("lib")
152145
};
153146

154-
let target = &self.config.sess.target;
147+
let target = &self.sess.target;
155148
let mingw_gnu_toolchain = target.vendor == "pc"
156149
&& target.os == "windows"
157150
&& target.env == "gnu"
@@ -160,7 +153,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
160153
let import_name_and_ordinal_vector: Vec<(String, Option<u16>)> = dll_imports
161154
.iter()
162155
.map(|import: &DllImport| {
163-
if self.config.sess.target.arch == "x86" {
156+
if self.sess.target.arch == "x86" {
164157
(
165158
LlvmArchiveBuilder::i686_decorated_name(import, mingw_gnu_toolchain),
166159
import.ordinal,
@@ -197,11 +190,11 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
197190
match std::fs::write(&def_file_path, def_file_content) {
198191
Ok(_) => {}
199192
Err(e) => {
200-
self.config.sess.fatal(&format!("Error writing .DEF file: {}", e));
193+
self.sess.fatal(&format!("Error writing .DEF file: {}", e));
201194
}
202195
};
203196

204-
let dlltool = find_binutils_dlltool(self.config.sess);
197+
let dlltool = find_binutils_dlltool(self.sess);
205198
let result = std::process::Command::new(dlltool)
206199
.args([
207200
"-d",
@@ -215,9 +208,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
215208

216209
match result {
217210
Err(e) => {
218-
self.config.sess.fatal(&format!("Error calling dlltool: {}", e));
211+
self.sess.fatal(&format!("Error calling dlltool: {}", e));
219212
}
220-
Ok(output) if !output.status.success() => self.config.sess.fatal(&format!(
213+
Ok(output) if !output.status.success() => self.sess.fatal(&format!(
221214
"Dlltool could not create import library: {}\n{}",
222215
String::from_utf8_lossy(&output.stdout),
223216
String::from_utf8_lossy(&output.stderr)
@@ -263,13 +256,13 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
263256
output_path_z.as_ptr(),
264257
ffi_exports.as_ptr(),
265258
ffi_exports.len(),
266-
llvm_machine_type(&self.config.sess.target.arch) as u16,
267-
!self.config.sess.target.is_like_msvc,
259+
llvm_machine_type(&self.sess.target.arch) as u16,
260+
!self.sess.target.is_like_msvc,
268261
)
269262
};
270263

271264
if result == crate::llvm::LLVMRustResult::Failure {
272-
self.config.sess.fatal(&format!(
265+
self.sess.fatal(&format!(
273266
"Error creating import library for {}: {}",
274267
lib_name,
275268
llvm::last_error().unwrap_or("unknown LLVM error".to_string())
@@ -278,7 +271,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
278271
};
279272

280273
self.add_archive(&output_path, |_| false).unwrap_or_else(|e| {
281-
self.config.sess.fatal(&format!(
274+
self.sess.fatal(&format!(
282275
"failed to add native library {}: {}",
283276
output_path.display(),
284277
e
@@ -292,13 +285,13 @@ impl<'a> LlvmArchiveBuilder<'a> {
292285
if let Some(ref a) = self.src_archive {
293286
return a.as_ref();
294287
}
295-
let src = self.config.src.as_ref()?;
288+
let src = self.src.as_ref()?;
296289
self.src_archive = Some(ArchiveRO::open(src).ok());
297290
self.src_archive.as_ref().unwrap().as_ref()
298291
}
299292

300293
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
301-
let kind = &*self.config.sess.target.archive_format;
294+
let kind = &*self.sess.target.archive_format;
302295
kind.parse().map_err(|_| kind)
303296
}
304297

@@ -308,7 +301,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
308301
let mut strings = Vec::new();
309302
let mut members = Vec::new();
310303

311-
let dst = CString::new(self.config.dst.to_str().unwrap())?;
304+
let dst = CString::new(self.dst.to_str().unwrap())?;
312305

313306
unsafe {
314307
if let Some(archive) = self.src_archive() {

0 commit comments

Comments
 (0)