fn link_rlib(sess: Session,
             trans: Option<&CrateTranslation>, // None == no metadata/bytecode
             obj_filename: &Path,
             out_filename: &Path) -> Archive {
    let mut a = Archive::create(sess, out_filename, obj_filename);

    let used_libraries = sess.cstore.get_used_libraries();
    let used_libraries = used_libraries.borrow();
    for &(ref l, kind) in used_libraries.get().iter() {
        match kind {
            cstore::NativeStatic => {
                a.add_native_library(l.as_slice());
            }
            cstore::NativeFramework | cstore::NativeUnknown => {}
        }
    }

    // Note that it is important that we add all of our non-object "magical
    // files" *after* all of the object files in the archive. The reason for
    // this is as follows:
    //
    // * When performing LTO, this archive will be modified to remove
    //   obj_filename from above. The reason for this is described below.
    //
    // * When the system linker looks at an archive, it will attempt to
    //   determine the architecture of the archive in order to see whether its
    //   linkable.
    //
    //   The algorithm for this detection is: iterate over the files in the
    //   archive. Skip magical SYMDEF names. Interpret the first file as an
    //   object file. Read architecture from the object file.
    //
    // * As one can probably see, if "metadata" and "foo.bc" were placed
    //   before all of the objects, then the architecture of this archive would
    //   not be correctly inferred once 'foo.o' is removed.
    //
    // Basically, all this means is that this code should not move above the
    // code above.
    match trans {
        Some(trans) => {
            // Instead of putting the metadata in an object file section, rlibs
            // contain the metadata in a separate file. We use a temp directory
            // here so concurrent builds in the same directory don't try to use
            // the same filename for metadata (stomping over one another)
            let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
            let metadata = tmpdir.path().join(METADATA_FILENAME);
            fs::File::create(&metadata).write(trans.metadata);
            a.add_file(&metadata, false);
            fs::unlink(&metadata);

            // For LTO purposes, the bytecode of this library is also inserted
            // into the archive.
            let bc = obj_filename.with_extension("bc");
            a.add_file(&bc, false);
            if !sess.opts.save_temps {
                fs::unlink(&bc);
            }

            // After adding all files to the archive, we need to update the
            // symbol table of the archive. This currently dies on OSX (see
            // #11162), and isn't necessary there anyway
            match sess.targ_cfg.os {
                abi::OsMacos => {}
                _ => { a.update_symbols(); }
            }
        }

        None => {}
    }
    return a;
}
// Create an 'rlib'
//
// An rlib in its current incarnation is essentially a renamed .a file. The
// rlib primarily contains the object file of the crate, but it also contains
// all of the object files from native libraries. This is done by unzipping
// native libraries and inserting all of the contents into this archive.
Create an 'rlib'
An rlib in its current incarnation is essentially a renamed .a file. The
rlib primarily contains the object file of the crate, but it also contains
all of the object files from native libraries. This is done by unzipping
native libraries and inserting all of the contents into this archive.
Create an ' rlib ' An rlib in its current incarnation is essentially a renamed . a file . The rlib primarily contains the object file of the crate but it also contains all of the object files from native libraries . This is done by unzipping native libraries and inserting all of the contents into this archive .
fn link_rlib(sess: Session,
             trans: Option<&CrateTranslation>, // None == no metadata/bytecode
             obj_filename: &Path,
             out_filename: &Path) -> Archive {
    let mut a = Archive::create(sess, out_filename, obj_filename);
    let used_libraries = sess.cstore.get_used_libraries();
    let used_libraries = used_libraries.borrow();
    for &(ref l, kind) in used_libraries.get().iter() {
        match kind {
            cstore::NativeStatic => {
                a.add_native_library(l.as_slice());
            }
            cstore::NativeFramework | cstore::NativeUnknown => {}
        }
    }
    // Note that it is important that we add all of our non-object "magical
    // files" *after* all of the object files in the archive. The reason for
    // this is as follows:
    //
    // * When performing LTO, this archive will be modified to remove
    //   obj_filename from above. The reason for this is described below.
    //
    // * When the system linker looks at an archive, it will attempt to
    //   determine the architecture of the archive in order to see whether its
    //   linkable.
    //
    //   The algorithm for this detection is: iterate over the files in the
    //   archive. Skip magical SYMDEF names. Interpret the first file as an
    //   object file. Read architecture from the object file.
    //
    // * As one can probably see, if "metadata" and "foo.bc" were placed
    //   before all of the objects, then the architecture of this archive would
    //   not be correctly inferred once 'foo.o' is removed.
    //
    // Basically, all this means is that this code should not move above the
    // code above.
    match trans {
        Some(trans) => {
            // Instead of putting the metadata in an object file section, rlibs
            // contain the metadata in a separate file. We use a temp directory
            // here so concurrent builds in the same directory don't try to use
            // the same filename for metadata (stomping over one another)
            let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
            let metadata = tmpdir.path().join(METADATA_FILENAME);
            fs::File::create(&metadata).write(trans.metadata);
            a.add_file(&metadata, false);
            fs::unlink(&metadata);
            // For LTO purposes, the bytecode of this library is also inserted
            // into the archive.
            let bc = obj_filename.with_extension("bc");
            a.add_file(&bc, false);
            if !sess.opts.save_temps {
                fs::unlink(&bc);
            }
            // After adding all files to the archive, we need to update the
            // symbol table of the archive. This currently dies on OSX (see
            // #11162), and isn't necessary there anyway
            match sess.targ_cfg.os {
                abi::OsMacos => {}
                _ => { a.update_symbols(); }
            }
        }
        None => {}
    }
    return a;
}
fn link_rlib ( sess : Session , trans : Option < & CrateTranslation > , // None == no metadata/bytecode obj_filename : & Path , out_filename : & Path ) -> Archive { let mut a = Archive :: create ( sess , out_filename , obj_filename ) ; let used_libraries = sess . cstore . get_used_libraries ( ) ; let used_libraries = used_libraries . borrow ( ) ; for & ( ref l , kind ) in used_libraries . get ( ) . iter ( ) { match kind { cstore :: NativeStatic => { a . add_native_library ( l . as_slice ( ) ) ; } cstore :: NativeFramework | cstore :: NativeUnknown => { } } } // Note that it is important that we add all of our non-object "magical // files" *after* all of the object files in the archive. The reason for // this is as follows: // // * When performing LTO, this archive will be modified to remove //   obj_filename from above. The reason for this is described below. // // * When the system linker looks at an archive, it will attempt to //   determine the architecture of the archive in order to see whether its //   linkable. // //   The algorithm for this detection is: iterate over the files in the //   archive. Skip magical SYMDEF names. Interpret the first file as an //   object file. Read architecture from the object file. // // * As one can probably see, if "metadata" and "foo.bc" were placed //   before all of the objects, then the architecture of this archive would //   not be correctly inferred once 'foo.o' is removed. // // Basically, all this means is that this code should not move above the // code above. match trans { Some ( trans ) => { // Instead of putting the metadata in an object file section, rlibs // contain the metadata in a separate file. We use a temp directory // here so concurrent builds in the same directory don't try to use // the same filename for metadata (stomping over one another) let tmpdir = TempDir :: new ( " " ) . expect ( " " ) ; let metadata = tmpdir . path ( ) . join ( METADATA_FILENAME ) ; fs :: File :: create ( & metadata ) . write ( trans . metadata ) ; a . add_file ( & metadata , false ) ; fs :: unlink ( & metadata ) ; // For LTO purposes, the bytecode of this library is also inserted // into the archive. let bc = obj_filename . with_extension ( " " ) ; a . add_file ( & bc , false ) ; if ! sess . opts . save_temps { fs :: unlink ( & bc ) ; } // After adding all files to the archive, we need to update the // symbol table of the archive. This currently dies on OSX (see // #11162), and isn't necessary there anyway match sess . targ_cfg . os { abi :: OsMacos => { } _ => { a . update_symbols ( ) ; } } } None => { } } return a ; }
Create an 'rlib'
An rlib in its current incarnation is essentially a renamed .a file.
Create an ' rlib ' An rlib in its current incarnation is essentially a renamed . a file .
sess
Session
trans
Option<&CrateTranslation>
obj_filename
&Path
out_filename
&Path
sess
Session
trans
Option<&CrateTranslation>
obj_filename
&Path
out_filename
&Path