win-build/README.mdown

136 lines
4.4 KiB
Plaintext
Raw Permalink Normal View History

2021-02-18 18:39:35 +00:00
# Visual Studio Build Tools Container
This project builds a minimal (ish) Docker container for the Visual Studio build tools (MSVC).
A second image is constructed for Windows XP Visual Studio build tools (v141_xp).
Powershell scripts are included to try and recreate these build environments directly on a Windows 10 workstation.
# Requirements
2023-03-27 18:31:49 +00:00
A Windows 11 10.0.22621.1413+ workstation or VM with minimum 8 GB of memory is required.
The more concurrent containers you have running, the more memory and CPU cores are required.
2021-02-18 18:39:35 +00:00
**Each container requires one core and approximately 4 GB of memory.**
0. Download and install [Docker for Windows](https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe).
- Select "Switch to Windows Containers" when prompted.
# Build Image
Prior to running a container the Docker image will need to be built.
This step is automated but time consuming.
It only needs to be built once.
0. Open powershell and navigate to this project.
0. Run docker compose with the configuration provided by this project in `docker-compose.yaml`
```bash
docker-compose build
```
This will install both the Windows v142 and Windows XP v141_xp build chains into their respective containers.
Reference these containers later with the names:
2023-03-27 18:31:49 +00:00
- win_build:ltsc2022
2021-02-18 18:39:35 +00:00
2023-03-27 18:31:49 +00:00
- rust_build:ltsc2022
2021-02-19 19:12:33 +00:00
2023-03-27 18:31:49 +00:00
- winxp_build:ltsc2022
2021-02-18 18:39:35 +00:00
# Run Containers
It is recommend that a docker compose file is used to run these containers as paths on Windows can be a bit tricky.
Make sure to use forward slashes in paths used within docker compose files.
Below is an example `docker-compose.yaml` file used to build a project configured with cmake.
```yaml
version: '3'
services:
win_build:
2023-03-27 18:31:49 +00:00
image: win_build:ltsc2022
2021-02-18 18:39:35 +00:00
volumes:
- .:C:/source/
```
- `volumes:` are mounted within the Docker container.
- `C:/source/` is assumed to be the project being build with MSVC.
2023-03-27 18:31:49 +00:00
To build a Windows XP project use the `image: winxp_build:ltsc2022` container image.
2021-02-18 18:39:35 +00:00
# Build Your Windows Project
The above `docker-compose.yaml` file should be stored within your project and will reference the built Docker images by name, not by path.
Once this file is created within your project run the following command to begin the build process.
```bash
docker-compose run win_build
```
This will drop you into the visual studio developer shell or console for winxp.
2021-02-19 20:50:01 +00:00
To modify the developer shell environments replace `entrypoint:` in your `docker-compose.yaml` with the desired environment variables or scripted build commands.
2021-02-19 19:31:58 +00:00
```yaml
version: '3'
services:
win_build:
2023-03-27 18:31:49 +00:00
image: win_build:ltsc2022
volumes:
- .:C:/source/
2021-02-19 20:50:01 +00:00
entrypoint: powershell -Command Import-Module C:\\msvc\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll; Enter-VsDevShell -VsInstallPath C:\\msvc\\ -DevCmdArguments -arch=amd64
2021-02-18 18:39:35 +00:00
```
# Optional Workstation Scripts
We have done our best to provide powershell scripts that should reproduce these build environments on a Windows 10 workstation.
They can be ran but should be evaluated as there is no error checking.
- [win_build_tools_install.ps1](win_build_tools_install.ps1)
- [winxp_build_tools_install.ps1](winxp_build_tools_install.ps1)
2021-02-19 19:30:38 +00:00
# Troubleshooting
2023-03-27 18:31:49 +00:00
## `error C2471: cannot update program database`
2021-02-19 19:30:38 +00:00
MSBuild has trouble writing files to a mounted directory which occurs even if the out path is set in the project.
It is recommended that you include a script in your project that copies the `C:\source` directory into the container prior to running the build commands.
```powershell
2021-02-19 20:33:36 +00:00
Copy-Item C:\source\ -Destination C:\build\ -Recurse -Force
2021-02-20 01:15:02 +00:00
MSBuild C:\build\project.sln
Copy-Item C:\build\bin -Destination C:\source\ -Recurse -Force
2021-02-23 23:32:37 +00:00
Remove-Item -Recurse C:\build\
2021-02-19 19:30:38 +00:00
```
2021-07-15 21:57:11 +00:00
2023-03-27 18:31:49 +00:00
## `docker-compose build not implimented`
2021-07-15 21:57:11 +00:00
https://docs.docker.com/compose/cli-command/#compose-v2-and-the-new-docker-compose-command
Docker Desktop includes an experimental version of docker-compose which may result in this error.
Use the following command to disable.
```
docker-compose disable-v2
```
2023-03-27 18:19:35 +00:00
2023-03-27 18:31:49 +00:00
## service immediately exits on `docker-compose up`
2023-03-27 18:19:35 +00:00
Reminder to run the container instead:
```
docker-compose run win_build
```
2023-03-27 18:31:49 +00:00
## `a Windows version 10.0.XXXXX-based image is incompatible with a 10.0.XXXXX host`
Microsoft paid a lot of money to check each container version.
Two solutions:
0. Update your workstation to Windows 11 10.0.22621.1413+
0. Replace the string `ltsc2022` with `ltsc2019` across the entire project and rebuild.