From 1508a0cc16b1fd5186d22639121c8e6b627af2bd Mon Sep 17 00:00:00 2001 From: VZout Date: Mon, 24 Aug 2020 11:27:11 +0200 Subject: [PATCH] Splitting the linking now in chunks to remove the need for argument files --- src/lib.rs | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index caf4f13e..e44442c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -929,7 +929,10 @@ impl Build { objects.push(Object::new(file.to_path_buf(), obj)); } self.compile_objects(&objects)?; - self.assemble(lib_name, &dst.join(gnu_lib_name), &objects)?; + + for chunk in objects.chunks(8191) { + self.assemble(lib_name, &dst.join(gnu_lib_name.clone()), &chunk)?; + } if self.get_target()?.contains("msvc") { let compiler = self.get_base_compiler()?; @@ -1710,47 +1713,8 @@ impl Build { for flag in self.ar_flags.iter() { cmd.arg(flag); } + cmd.args(&objects).args(&self.objects); - // Similar to https://github.com/rust-lang/rust/pull/47507 - // and https://github.com/rust-lang/rust/pull/48548 - let estimated_command_line_len = objects - .iter() - .chain(&self.objects) - .map(|a| a.as_os_str().len()) - .sum::(); - if estimated_command_line_len > 1024 * 6 { - let mut args = String::from("\u{FEFF}"); // BOM - for arg in objects.iter().chain(&self.objects) { - args.push('"'); - for c in arg.to_str().unwrap().chars() { - if c == '"' { - args.push('\\') - } - args.push(c) - } - args.push('"'); - args.push('\n'); - } - - let mut utf16le = Vec::new(); - for code_unit in args.encode_utf16() { - utf16le.push(code_unit as u8); - utf16le.push((code_unit >> 8) as u8); - } - - let mut args_file = OsString::from(dst); - args_file.push(".args"); - fs::File::create(&args_file) - .unwrap() - .write_all(&utf16le) - .unwrap(); - - let mut args_file_arg = OsString::from("@"); - args_file_arg.push(args_file); - cmd.arg(args_file_arg); - } else { - cmd.args(&objects).args(&self.objects); - } run(&mut cmd, &program)?; // The Rust compiler will look for libfoo.a and foo.lib, but the