diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-07-01 23:39:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-01 23:39:07 +0200 |
| commit | 01aa10c2ffd49238d0aef83253190c8df0d77c87 (patch) | |
| tree | a6b1e1e54a7f726afb79df01a37b89a51c7c9fb2 /src/bootstrap/lib.rs | |
| parent | 194764fdc070d95ce2200548a2e6267d701068bd (diff) | |
| parent | b6e28b59679e3e4ee47b20090035ef33889b3f3b (diff) | |
| download | rust-01aa10c2ffd49238d0aef83253190c8df0d77c87.tar.gz rust-01aa10c2ffd49238d0aef83253190c8df0d77c87.zip | |
Rollup merge of #98418 - topjohnwu:macos-dylib, r=jyn514
Allow macOS to build LLVM as shared library Inspired by how [homebrew](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm.rb) builds and distributes llvm, here we manually create a symlink with a versioned dylib path to make `llvm-config` work properly. Note, the resulting `rustc` executable and `librustc_driver-<hash>.dylib` still links to the un-versioned `libLLVM.dylib` as expected when distributed in the final output. I have confirmed this by checking `otool -L` on both binaries. After the change, enabling `llvm.link-shared` and `llvm.thin-lto` will be possible on macOS.
Diffstat (limited to 'src/bootstrap/lib.rs')
| -rw-r--r-- | src/bootstrap/lib.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 859d35b7d7b..40ff0381c8b 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -107,15 +107,11 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; use std::env; use std::fs::{self, File}; +use std::io; use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::str; -#[cfg(unix)] -use std::os::unix::fs::symlink as symlink_file; -#[cfg(windows)] -use std::os::windows::fs::symlink_file; - use filetime::FileTime; use once_cell::sync::OnceCell; @@ -1460,7 +1456,7 @@ impl Build { src = t!(fs::canonicalize(src)); } else { let link = t!(fs::read_link(src)); - t!(symlink_file(link, dst)); + t!(self.symlink_file(link, dst)); return; } } @@ -1585,6 +1581,14 @@ impl Build { iter.map(|e| t!(e)).collect::<Vec<_>>().into_iter() } + fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> { + #[cfg(unix)] + use std::os::unix::fs::symlink as symlink_file; + #[cfg(windows)] + use std::os::windows::fs::symlink_file; + if !self.config.dry_run { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) } + } + fn remove(&self, f: &Path) { if self.config.dry_run { return; |
