@@ -885,107 +885,6 @@ pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<Version> {
885885 None
886886}
887887
888- /// For tests using the `needs-llvm-zstd` directive:
889- /// - for local LLVM builds, try to find the static zstd library in the llvm-config system libs.
890- /// - for `download-ci-llvm`, see if `lld` was built with zstd support.
891- pub fn llvm_has_libzstd ( config : & Config ) -> bool {
892- // Strategy 1: works for local builds but not with `download-ci-llvm`.
893- //
894- // We check whether `llvm-config` returns the zstd library. Bootstrap's `llvm.libzstd` will only
895- // ask to statically link it when building LLVM, so we only check if the list of system libs
896- // contains a path to that static lib, and that it exists.
897- //
898- // See compiler/rustc_llvm/build.rs for more details and similar expectations.
899- fn is_zstd_in_config ( llvm_bin_dir : & Utf8Path ) -> Option < ( ) > {
900- let llvm_config_path = llvm_bin_dir. join ( "llvm-config" ) ;
901- let output = Command :: new ( llvm_config_path) . arg ( "--system-libs" ) . output ( ) . ok ( ) ?;
902- assert ! ( output. status. success( ) , "running llvm-config --system-libs failed" ) ;
903-
904- let libs = String :: from_utf8 ( output. stdout ) . ok ( ) ?;
905- for lib in libs. split_whitespace ( ) {
906- if lib. ends_with ( "libzstd.a" ) && Utf8Path :: new ( lib) . exists ( ) {
907- return Some ( ( ) ) ;
908- }
909- }
910-
911- None
912- }
913-
914- // Strategy 2: `download-ci-llvm`'s `llvm-config --system-libs` will not return any libs to
915- // use.
916- //
917- // The CI artifacts also don't contain the bootstrap config used to build them: otherwise we
918- // could have looked at the `llvm.libzstd` config.
919- //
920- // We infer whether `LLVM_ENABLE_ZSTD` was used to build LLVM as a byproduct of testing whether
921- // `lld` supports it. If not, an error will be emitted: "LLVM was not built with
922- // LLVM_ENABLE_ZSTD or did not find zstd at build time".
923- #[ cfg( unix) ]
924- fn is_lld_built_with_zstd ( llvm_bin_dir : & Utf8Path ) -> Option < ( ) > {
925- let lld_path = llvm_bin_dir. join ( "lld" ) ;
926- if lld_path. exists ( ) {
927- // We can't call `lld` as-is, it expects to be invoked by a compiler driver using a
928- // different name. Prepare a temporary symlink to do that.
929- let lld_symlink_path = llvm_bin_dir. join ( "ld.lld" ) ;
930- if !lld_symlink_path. exists ( ) {
931- std:: os:: unix:: fs:: symlink ( lld_path, & lld_symlink_path) . ok ( ) ?;
932- }
933-
934- // Run `lld` with a zstd flag. We expect this command to always error here, we don't
935- // want to link actual files and don't pass any.
936- let output = Command :: new ( & lld_symlink_path)
937- . arg ( "--compress-debug-sections=zstd" )
938- . output ( )
939- . ok ( ) ?;
940- assert ! ( !output. status. success( ) ) ;
941-
942- // Look for a specific error caused by LLVM not being built with zstd support. We could
943- // also look for the "no input files" message, indicating the zstd flag was accepted.
944- let stderr = String :: from_utf8 ( output. stderr ) . ok ( ) ?;
945- let zstd_available = !stderr. contains ( "LLVM was not built with LLVM_ENABLE_ZSTD" ) ;
946-
947- // We don't particularly need to clean the link up (so the previous commands could fail
948- // in theory but won't in practice), but we can try.
949- std:: fs:: remove_file ( lld_symlink_path) . ok ( ) ?;
950-
951- if zstd_available {
952- return Some ( ( ) ) ;
953- }
954- }
955-
956- None
957- }
958-
959- #[ cfg( not( unix) ) ]
960- fn is_lld_built_with_zstd ( _llvm_bin_dir : & Utf8Path ) -> Option < ( ) > {
961- None
962- }
963-
964- if let Some ( llvm_bin_dir) = & config. llvm_bin_dir {
965- // Strategy 1: for local LLVM builds.
966- if is_zstd_in_config ( llvm_bin_dir) . is_some ( ) {
967- return true ;
968- }
969-
970- // Strategy 2: for LLVM artifacts built on CI via `download-ci-llvm`.
971- //
972- // It doesn't work for cases where the artifacts don't contain the linker, but it's
973- // best-effort: CI has `llvm.libzstd` and `lld` enabled on the x64 linux artifacts, so it
974- // will at least work there.
975- //
976- // If this can be improved and expanded to less common cases in the future, it should.
977- if config. target == "x86_64-unknown-linux-gnu"
978- && config. host == config. target
979- && is_lld_built_with_zstd ( llvm_bin_dir) . is_some ( )
980- {
981- return true ;
982- }
983- }
984-
985- // Otherwise, all hope is lost.
986- false
987- }
988-
989888/// Takes a directive of the form `"<version1> [- <version2>]"`, returns the numeric representation
990889/// of `<version1>` and `<version2>` as tuple: `(<version1>, <version2>)`.
991890///
0 commit comments