@@ -27,7 +27,7 @@ use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
2727use crate :: dist;
2828use crate :: llvm;
2929use crate :: tool:: SourceType ;
30- use crate :: util:: get_clang_cl_resource_dir ;
30+ use crate :: util:: get_clang_rt_dir ;
3131use crate :: util:: { exe, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date} ;
3232use crate :: LLVM_TOOLS ;
3333use crate :: { CLang , Compiler , DependencyType , GitRepo , Mode } ;
@@ -923,10 +923,38 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
923923 // found. This is to avoid the linker errors about undefined references to
924924 // `__llvm_profile_instrument_memop` when linking `rustc_driver`.
925925 let mut llvm_linker_flags = String :: new ( ) ;
926- if builder. config . llvm_profile_generate && target. contains ( "msvc" ) {
927- if let Some ( ref clang_cl_path) = builder. config . llvm_clang_cl {
928- // Add clang's runtime library directory to the search path
929- let clang_rt_dir = get_clang_cl_resource_dir ( clang_cl_path) ;
926+ if builder. config . llvm_profile_generate {
927+ if target. contains ( "msvc" ) {
928+ if let Some ( ref clang_cl_path) = builder. config . llvm_clang_cl {
929+ // Add clang's runtime library directory to the search path
930+ let clang_rt_dir = get_clang_rt_dir ( clang_cl_path, true ) ;
931+ llvm_linker_flags. push_str ( & format ! ( "-L{}" , clang_rt_dir. display( ) ) ) ;
932+ }
933+ }
934+
935+ if target. contains ( "apple" ) {
936+ let clang_rt_profile_lib_suffix = if target. ends_with ( "ios-sim" ) {
937+ "iossim"
938+ } else if target. ends_with ( "ios" ) {
939+ "ios"
940+ } else if target. ends_with ( "tvos-sim" ) {
941+ "tvossim"
942+ } else if target. ends_with ( "tvos" ) {
943+ "tvos"
944+ } else if target. ends_with ( "darwin" ) {
945+ "osx"
946+ } else if target. ends_with ( "watchos-sim" ) {
947+ "watchossim"
948+ } else if target. ends_with ( "watchos" ) {
949+ "watchos"
950+ } else {
951+ panic ! ( "clang has no clang_rt.profile library for {target}" ) ;
952+ } ;
953+ let clang = builder. cc ( target) ;
954+ let clang_rt_dir = get_clang_rt_dir ( clang, false ) ;
955+ let clang_rt_profile_lib = format ! ( "libclang_rt.profile_{clang_rt_profile_lib_suffix}" ) ;
956+ llvm_linker_flags. push_str ( & format ! ( "-l{clang_rt_profile_lib}" ) ) ;
957+ llvm_linker_flags. push_str ( " " ) ;
930958 llvm_linker_flags. push_str ( & format ! ( "-L{}" , clang_rt_dir. display( ) ) ) ;
931959 }
932960 }
0 commit comments