[WIP] Try using GnuBuilder

This commit is contained in:
bjorn3 2019-04-16 19:07:30 +02:00
parent 472b591f90
commit 103f2faa1a
3 changed files with 38 additions and 10 deletions

6
Cargo.lock generated
View File

@ -19,7 +19,7 @@ dependencies = [
[[package]]
name = "ar"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "git+https://github.com/mdsteele/rust-ar.git#1cfa68dcecaa063510758e8bdced7115a3393616"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -582,7 +582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "rustc_codegen_cranelift"
version = "0.1.0"
dependencies = [
"ar 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ar 0.6.2 (git+https://github.com/mdsteele/rust-ar.git)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift 0.30.0 (git+https://github.com/CraneStation/cranelift.git)",
@ -843,7 +843,7 @@ dependencies = [
[metadata]
"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum ar 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "579681b3fecd1e9d6b5ce6969e05f9feb913f296eddaf595be1166a5ca597bc4"
"checksum ar 0.6.2 (git+https://github.com/mdsteele/rust-ar.git)" = "<none>"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"

View File

@ -38,5 +38,8 @@ indexmap = "1.0.2"
#[patch."https://github.com/gimli-rs/gimli.git"]
#gimli = { path = "../" }
[patch.crates-io]
ar = { git = "https://github.com/mdsteele/rust-ar.git" }
[profile.dev.overrides."*"]
opt-level = 3

View File

@ -8,12 +8,14 @@ use rustc_codegen_ssa::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION};
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, find_library};
struct ArchiveConfig<'a> {
pub sess: &'a Session,
pub dst: PathBuf,
pub src: Option<PathBuf>,
pub lib_search_paths: Vec<PathBuf>,
sess: &'a Session,
dst: PathBuf,
src: Option<PathBuf>,
lib_search_paths: Vec<PathBuf>,
is_like_osx: bool,
}
#[derive(Debug)]
enum ArchiveEntry {
FromArchive { archive_index: usize, entry_index: usize },
File(File),
@ -34,6 +36,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
dst: output.to_path_buf(),
src: input.map(|p| p.to_path_buf()),
lib_search_paths: archive_search_paths(sess),
is_like_osx: sess.target.target.options.is_like_osx,
};
let (src_archives, entries) = if let Some(src) = &config.src {
@ -119,7 +122,23 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
}
fn build(mut self) {
let mut builder = ar::Builder::new(File::create(&self.config.dst).unwrap());
println!("{:?}", self.src_archives.len());
println!("{:?}", self.entries);
enum BuilderKind {
Bsd(ar::Builder<File>),
Gnu(ar::GnuBuilder<File>),
}
let archive_file = File::create(&self.config.dst).unwrap();
let mut builder = if self.config.is_like_osx {
BuilderKind::Bsd(ar::Builder::new(archive_file))
} else {
BuilderKind::Gnu(ar::GnuBuilder::new(
archive_file,
self.entries.keys().map(|key| key.as_bytes().to_vec()).collect(),
))
};
// Add all files
for (entry_name, entry) in self.entries.into_iter() {
@ -133,10 +152,16 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
header.set_uid(orig_header.uid());
header.set_gid(orig_header.gid());
header.set_mode(orig_header.mode());
builder.append(&header, entry).unwrap();
match builder {
BuilderKind::Bsd(ref mut builder) => builder.append(&header, entry).unwrap(),
BuilderKind::Gnu(ref mut builder) => builder.append(&header, entry).unwrap(),
}
}
ArchiveEntry::File(mut file) => {
builder.append_file(entry_name.as_bytes(), &mut file).unwrap();
match builder {
BuilderKind::Bsd(ref mut builder) => builder.append_file(entry_name.as_bytes(), &mut file).unwrap(),
BuilderKind::Gnu(ref mut builder) => builder.append_file(entry_name.as_bytes(), &mut file).unwrap(),
}
}
}
}