// Link in all of our upstream crates' native dependencies. Remember that
// all of these upstream native dependencies are all non-static
// dependencies. We've got two cases then:
//
// 1. The upstream crate is an rlib. In this case we *must* link in the
// native dependency because the rlib is just an archive.
//
// 2. The upstream crate is a dylib. In order to use the dylib, we have to
// have the dependency present on the system somewhere. Thus, we don't
// gain a whole lot from not linking in the dynamic dependency to this
// crate as well.
//
// The use case for this is a little subtle. In theory the native
// dependencies of a crate are purely an implementation detail of the crate
// itself, but the problem arises with generic and inlined functions. If a
// generic function calls a native function, then the generic function must
// be instantiated in the target crate, meaning that the native symbol must
// also be resolved in the target crate.
Link in all of our upstream crates' native dependencies. Remember that
all of these upstream native dependencies are all non-static
dependencies. We've got two cases then.

1. The upstream crate is an rlib. In this case we *must* link in the
native dependency because the rlib is just an archive.

2. The upstream crate is a dylib. In order to use the dylib, we have to
have the dependency present on the system somewhere. Thus, we don't
gain a whole lot from not linking in the dynamic dependency to this
crate as well.

The use case for this is a little subtle. In theory the native
dependencies of a crate are purely an implementation detail of the crate
itself, but the problem arises with generic and inlined functions. If a
generic function calls a native function, then the generic function must
be instantiated in the target crate, meaning that the native symbol must
also be resolved in the target crate.
Link in all of our upstream crates ' native dependencies . Remember that all of these upstream native dependencies are all non - static dependencies . We ' ve got two cases then . 1 . The upstream crate is an rlib . In this case we * must * link in the native dependency because the rlib is just an archive . 2 . The upstream crate is a dylib . In order to use the dylib we have to have the dependency present on the system somewhere . Thus we don ' t gain a whole lot from not linking in the dynamic dependency to this crate as well . The use case for this is a little subtle . In theory the native dependencies of a crate are purely an implementation detail of the crate itself but the problem arises with generic and inlined functions . If a generic function calls a native function then the generic function must be instantiated in the target crate meaning that the native symbol must also be resolved in the target crate .
fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session) {
    // Be sure to use a topological sorting of crates because there may be
    // interdependencies between native libraries. When passing -nodefaultlibs,
    // for example, almost all native libraries depend on libc, so we have to
    // make sure that's all the way at the right (liblibc is near the base of
    // the dependency chain).
    //
    // This passes RequireStatic, but the actual requirement doesn't matter,
    // we're just getting an ordering of crate numbers, we're not worried about
    // the paths.
    let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
    for (cnum, _) in crates {
        let libs = csearch::get_native_libraries(&sess.cstore, cnum);
        for &(kind, ref lib) in &libs {
            match kind {
                cstore::NativeUnknown => cmd.link_dylib(lib),
                cstore::NativeFramework => cmd.link_framework(lib),
                cstore::NativeStatic => {
                    sess.bug("statics shouldn't be propagated");
                }
            }
        }
    }
}
fn add_upstream_native_libraries ( cmd : & mut Linker , sess : & Session ) { // Be sure to use a topological sorting of crates because there may be // interdependencies between native libraries. When passing -nodefaultlibs, // for example, almost all native libraries depend on libc, so we have to // make sure that's all the way at the right (liblibc is near the base of // the dependency chain). // // This passes RequireStatic, but the actual requirement doesn't matter, // we're just getting an ordering of crate numbers, we're not worried about // the paths. let crates = sess . cstore . get_used_crates ( cstore :: RequireStatic ) ; for ( cnum , _ ) in crates { let libs = csearch :: get_native_libraries ( & sess . cstore , cnum ) ; for & ( kind , ref lib ) in & libs { match kind { cstore :: NativeUnknown => cmd . link_dylib ( lib ) , cstore :: NativeFramework => cmd . link_framework ( lib ) , cstore :: NativeStatic => { sess . bug ( " " ) ; } } } } }
Link in all of our upstream crates' native dependencies.
Link in all of our upstream crates ' native dependencies .
cmd
&mut Linker
sess
&Session