|
| 1 | +# *-win7-windows-msvc |
| 2 | + |
| 3 | +**Tier: 3** |
| 4 | + |
| 5 | +Windows targets continuing support of windows7. |
| 6 | + |
| 7 | +## Target maintainers |
| 8 | + |
| 9 | +- @roblabla |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +This target supports all of core, alloc, std and test. This is automatically |
| 14 | +tested every night on private infrastructure hosted by the maintainer. Host |
| 15 | +tools may also work, though those are not currently tested. |
| 16 | + |
| 17 | +Those targets follow Windows calling convention for extern "C". |
| 18 | + |
| 19 | +Like any other Windows target, the created binaries are in PE format. |
| 20 | + |
| 21 | +## Building the target |
| 22 | + |
| 23 | +You can build Rust with support for the targets by adding it to the target list in config.toml: |
| 24 | + |
| 25 | +```toml |
| 26 | +[build] |
| 27 | +build-stage = 1 |
| 28 | +target = [ "x86_64-win7-windows-msvc" ] |
| 29 | +``` |
| 30 | + |
| 31 | +## Building Rust programs |
| 32 | + |
| 33 | +Rust does not ship pre-compiled artifacts for this target. To compile for this |
| 34 | +target, you will either need to build Rust with the target enabled (see |
| 35 | +"Building the target" above), or build your own copy by using `build-std` or |
| 36 | +similar. |
| 37 | + |
| 38 | +## Testing |
| 39 | + |
| 40 | +Created binaries work fine on Windows or Wine using native hardware. Remote |
| 41 | +testing is possible using the `remote-test-server` described [here](https://rustc-dev-guide.rust-lang.org/tests/running.html#running-tests-on-a-remote-machine). |
| 42 | + |
| 43 | +## Cross-compilation toolchains and C code |
| 44 | + |
| 45 | +Compatible C code can be built with either MSVC's `cl.exe` or LLVM's clang-cl. |
| 46 | + |
| 47 | +Cross-compilation is possible using clang-cl/lld-link. It also requires the |
| 48 | +Windows SDK, which can be acquired using [`xwin`](https://github.com/Jake-Shadle/xwin). |
| 49 | + |
| 50 | +- Install `clang-cl` and `lld-link` on your machine, and make sure they are in |
| 51 | + your $PATH. |
| 52 | +- Install `xwin`: `cargo install xwin` |
| 53 | +- Use `xwin` to install the Windows SDK: `xwin splat --output winsdk` |
| 54 | +- Create an `xwin-lld-link` script with the following content: |
| 55 | + |
| 56 | + ```bash |
| 57 | + #!/usr/bin/env bash |
| 58 | + set -e |
| 59 | + XWIN=/path/to/winsdk |
| 60 | + lld-link "$@" /libpath:$XWIN/crt/lib/x86_64 /libpath:$XWIN/sdk/lib/um/x86_64 /libpath:$XWIN/sdk/lib/ucrt/x86_64 |
| 61 | + ``` |
| 62 | + |
| 63 | +- Create an `xwin-clang-cl` script with the following content: |
| 64 | + |
| 65 | + ```bash |
| 66 | + #!/usr/bin/env bash |
| 67 | + set -e |
| 68 | + XWIN=/path/to/winsdk |
| 69 | + clang-cl /imsvc "$XWIN/crt/include" /imsvc "$XWIN/sdk/include/ucrt" /imsvc "$XWIN/sdk/include/um" /imsvc "$XWIN/sdk/include/shared" --target="x86_64-pc-windows-msvc" "$@" |
| 70 | + ``` |
| 71 | + |
| 72 | +- In your config.toml, add the following lines: |
| 73 | + |
| 74 | + ```toml |
| 75 | + [target.x86_64-win7-windows-msvc] |
| 76 | + linker = "path/to/xwin-lld-link" |
| 77 | + cc = "path/to/xwin-clang-cl" |
| 78 | + ``` |
| 79 | + |
| 80 | +You should now be able to cross-compile the Rust std, and any rust program. |
0 commit comments