Skip to content

Commit

Permalink
Update building instructions (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Nov 23, 2024
1 parent da8a8af commit 8c1b09d
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,28 @@ This project is configured to build with both CMake and the Swift Package Manage

Pull requests are validated with a GitHub Actions workflow which builds using both build systems and runs tests from the SPM build.

## CMake

To build with CMake, open a `VS Developer Command Prompt` at the root of this repo and type:

```cmd
cmake --preset debug
cmake --build --preset debug
```

When building from the root of the repo, the Generator project will be built during the configure phase, so that the resulting executable can be used to generate test projections later in the build.

The repo is configured such that many subdirectories can be built the same way, to scope down the build.

You can also use [Visual Studio Code](https://code.visualstudio.com/) with the [CMake Tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) to configure and build, as long as you start it from within a `VS Developer Command Prompt`.

## SPM

The root of the repo is an SPM package that builds the support module and can run its tests. This allows SPM references to the git repo to resolve to the support module.

```cmd
swift build --build-tests
swift test --skip-build
```

The `/Generator` subdirectory is an independent SPM package that builds the code generator and can run its tests:

```cmd
Generator> swift build --build-tests
Generator> swift test --skip-build
```

The `/InteropTests` subdirectory requires building `WinRTComponent.winmd` and `WinRTComponent.dll`, and invoking `SwiftWinRT.exe`, which SPM cannot do. A helper script, `SPMPrebuild.ps1`, will do that using CMake, after which the package can be built and tested normally.
## Prerequisites

- Windows 10 or above (building on other platforms should be possible but is untested)
- A Swift toolchain, version 5.10 or above
- `winget install --id Swift.Toolchain`
- Visual Studio (any edition) with the Desktop C++ Workload
- `winget install --id Microsoft.VisualStudio.2022.Community --override "--quiet --add Microsoft.VisualStudio.Workload.NativeDesktop"`
- A Windows SDK (any reasonably recent version)
- Comes with Visual Studio, or use `winget install --id Microsoft.WindowsSDK.10.0.22000`
- CMake and ninja
- Comes with Visual Studio, or use `winget install --id Kitware.CMake` and `winget install --id Ninja-build.Ninja`
- NuGet
- `winget install Microsoft.NuGet`

## In Visual Studio Code
Open Visual Studio Code from a `x64 Native Tools Command Prompt for VS 2022` and use standard IDE commands for building (<kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>B</kbd>). Subfolders `Generator` and `InteropTests` can also be opened for a scoped down development environment.

## From the command line
1. Open a `x64 Native Tools Command Prompt for VS 2022`.
2. Refer to the [Build and Test workflow](.github/workflows/build-and-test.yml) for build commands.
- With CMake, the Generator project will be built during the configure phase so that the resulting executable can be used to generate test projections later on, but the tests themselves will not be built due to XCTest dependencies on SPM.
- With SPM, the build is split in several steps:
- The root `Package.swift`, which defines modules supporting the generated code.
- The `Generator` subfolder, which builds the code genreator.
- The `InteropTests` subfolder, which builds tests against a WinRT component and relies on a prebuild Powershell script.

0 comments on commit 8c1b09d

Please sign in to comment.