|
45 | 45 | # instead of `lib.exe` for assembling archives, so we need to inject this custom
|
46 | 46 | # dependency here.
|
47 | 47 | NATIVE_TOOL_DEPS_core_T_x86_64-pc-windows-msvc += llvm-ar.exe
|
| 48 | + |
| 49 | +# When working with MSVC on windows, each DLL needs to explicitly declare its |
| 50 | +# interface to the outside world through some means. The options for doing so |
| 51 | +# include: |
| 52 | +# |
| 53 | +# 1. A custom attribute on each function itself |
| 54 | +# 2. A linker argument saying what to export |
| 55 | +# 3. A file which lists all symbols that need to be exported |
| 56 | +# |
| 57 | +# The Rust compiler takes care (1) for us for all Rust code by annotating all |
| 58 | +# public-facing functions with dllexport, but we have a few native dependencies |
| 59 | +# which need to cross the DLL boundary. The most important of these dependencies |
| 60 | +# is LLVM which is linked into `rustc_llvm.dll` but primarily used from |
| 61 | +# `rustc_trans.dll`. This means that many of LLVM's C API functions need to be |
| 62 | +# exposed from `rustc_llvm.dll` to be forwarded over the boundary. |
| 63 | +# |
| 64 | +# Unfortunately, at this time, LLVM does not handle this sort of exportation on |
| 65 | +# Windows for us, so we're forced to do it ourselves if we want it (which seems |
| 66 | +# like the path of least resistance right now). To do this we generate a `.DEF` |
| 67 | +# file [1] which we then custom-pass to the linker when building the rustc_llvm |
| 68 | +# crate. This DEF file list all symbols that are exported from |
| 69 | +# `src/librustc_llvm/lib.rs` and is generated by a small python script. |
| 70 | +# |
| 71 | +# Fun times! |
| 72 | +# |
| 73 | +# [1]: https://msdn.microsoft.com/en-us/library/28d6s79h.aspx |
| 74 | +RUSTFLAGS_rustc_llvm_T_x86_64-pc-windows-msvc += \ |
| 75 | + -C link-args="-DEF:x86_64-pc-windows-msvc/rt/rustc_llvm.def" |
| 76 | +CUSTOM_DEPS_rustc_llvm_T_x86_64-pc-windows-msvc += \ |
| 77 | + x86_64-pc-windows-msvc/rt/rustc_llvm.def |
| 78 | + |
| 79 | +x86_64-pc-windows-msvc/rt/rustc_llvm.def: $(S)src/etc/mklldef.py \ |
| 80 | + $(S)src/librustc_llvm/lib.rs |
| 81 | + $(CFG_PYTHON) $^ $@ rustc_llvm-$(CFG_FILENAME_EXTRA) |
0 commit comments