diff --git a/Cargo.lock b/Cargo.lock index b90bcfc7f2f44..6a21f090763c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3392,6 +3392,7 @@ dependencies = [ "bitflags", "cc", "jobserver", + "lazy_static 1.3.0", "libc", "log", "memmap", diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index b6177b2cc9b25..c8fdd2bab36f2 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -15,59 +15,16 @@ jobs: strategy: matrix: dist-x86_64-linux: {} - dist-x86_64-linux-alt: - IMAGE: dist-x86_64-linux - -# The macOS and Windows builds here are currently disabled due to them not being -# overly necessary on `try` builds. We also don't actually have anything that -# consumes the artifacts currently. Perhaps one day we can reenable, but for now -# it helps free up capacity on Azure. -# - job: macOS -# timeoutInMinutes: 600 -# pool: -# vmImage: macos-10.13 -# steps: -# - template: steps/run.yml -# strategy: -# matrix: -# dist-x86_64-apple: -# SCRIPT: ./x.py dist -# RUST_CONFIGURE_ARGS: --target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc -# DEPLOY: 1 -# RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 -# MACOSX_DEPLOYMENT_TARGET: 10.7 -# NO_LLVM_ASSERTIONS: 1 -# NO_DEBUG_ASSERTIONS: 1 -# DIST_REQUIRE_ALL_TOOLS: 1 -# -# dist-x86_64-apple-alt: -# SCRIPT: ./x.py dist -# RUST_CONFIGURE_ARGS: --enable-extended --enable-profiler --set rust.jemalloc -# DEPLOY_ALT: 1 -# RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 -# MACOSX_DEPLOYMENT_TARGET: 10.7 -# NO_LLVM_ASSERTIONS: 1 -# NO_DEBUG_ASSERTIONS: 1 -# -# - job: Windows -# timeoutInMinutes: 600 -# pool: -# vmImage: 'vs2017-win2016' -# steps: -# - template: steps/run.yml -# strategy: -# matrix: -# dist-x86_64-msvc: -# RUST_CONFIGURE_ARGS: > -# --build=x86_64-pc-windows-msvc -# --target=x86_64-pc-windows-msvc,aarch64-pc-windows-msvc -# --enable-full-tools -# --enable-profiler -# SCRIPT: python x.py dist -# DIST_REQUIRE_ALL_TOOLS: 1 -# DEPLOY: 1 -# -# dist-x86_64-msvc-alt: -# RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler -# SCRIPT: python x.py dist -# DEPLOY_ALT: 1 +- job: Windows + timeoutInMinutes: 600 + pool: + vmImage: 'vs2017-win2016' + steps: + - template: steps/run.yml + strategy: + matrix: + dist-x86_64-mingw: + SCRIPT: python x.py dist + RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler + CUSTOM_MINGW: 1 + DIST_REQUIRE_ALL_TOOLS: 1 \ No newline at end of file diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index d489852a1a43d..1f5fbeb2c7f2d 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -14,6 +14,7 @@ bitflags = "1.2.1" cc = "1.0.1" num_cpus = "1.0" memmap = "0.7" +lazy_static = "1" log = "0.4.5" libc = "0.2.44" jobserver = "0.1.11" diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index c7a599a5749b7..c54f160e41f14 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -918,7 +918,48 @@ pub fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary } } +fn get_compiler_libs_path(sess: &Session) -> Option { + use std::sync::Mutex; + + lazy_static::lazy_static! { + static ref SYSTEM_LIBS: Mutex> = Mutex::new(None); + } + + let system_libs = SYSTEM_LIBS.lock().unwrap().clone(); + if let Some(compiler_libs_path) = system_libs { + println!("cache: hit"); + return Some(compiler_libs_path); + } else { + println!("cache: miss"); + let compiler = if let Some(linker) = &sess.opts.cg.linker { + linker.clone().into_os_string() + } else if let Some(linker) = &sess.target.target.options.linker { + linker.into() + } else { + return None; + }; + if let Ok(output) = Command::new(compiler).arg("-print-file-name=crt2.o").output() { + if let Some(compiler_libs_path) = + PathBuf::from(std::str::from_utf8(&output.stdout).unwrap()).parent() + { + let compiler_libs_path = fix_windows_verbatim_for_gcc(compiler_libs_path); + *SYSTEM_LIBS.lock().unwrap() = Some(compiler_libs_path.clone()); + return Some(compiler_libs_path); + } + } + } + None +} + pub fn get_file_path(sess: &Session, name: &str) -> PathBuf { + if sess.target.target.llvm_target.contains("windows-gnu") { + if let Some(compiler_libs_path) = get_compiler_libs_path(sess) { + let file_path = compiler_libs_path.join(name); + if file_path.exists() { + return file_path; + } + } + } let fs = sess.target_filesearch(PathKind::Native); let file_path = fs.get_lib_path().join(name); if file_path.exists() { @@ -1100,6 +1141,12 @@ fn link_args<'a, B: ArchiveBuilder<'a>>( // target descriptor let t = &sess.target.target; + if sess.target.target.llvm_target.contains("windows-gnu") { + if let Some(compiler_libs_path) = get_compiler_libs_path(sess) { + cmd.include_path(&compiler_libs_path); + } + } + cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path)); for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {