+/// Copies third party objects needed by various targets for self-contained linkage.
+fn copy_self_contained_objects(
+ builder: &Builder<'_>,
+ compiler: &Compiler,
+ target: Interned<String>,
+) -> Vec<PathBuf> {
+ let libdir = builder.sysroot_libdir(*compiler, target);
+ let mut target_deps = vec![];
+
+ // Copies the CRT objects.
+ //
+ // rustc historically provides a more self-contained installation for musl targets
+ // not requiring the presence of a native musl toolchain. For example, it can fall back
+ // to using gcc from a glibc-targeting toolchain for linking.
+ // To do that we have to distribute musl startup objects as a part of Rust toolchain
+ // and link with them manually in the self-contained mode.
+ if target.contains("musl") {
+ let srcdir = builder.musl_root(target).unwrap().join("lib");
+ for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
+ copy_and_stamp(
+ builder,
+ &libdir_self_contained,
+ &srcdir,
+ obj,
+ &mut target_deps,
+ );
+ }
+ } else if target.ends_with("-wasi") {
+ let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
+ copy_and_stamp(
+ builder,
+ &libdir_self_contained,
+ &srcdir,
+ "crt1.o",
+ &mut target_deps,
+ );
+ }
+
+ target_deps
+}
+