Skip to content

Commit

Permalink
Move the InteropTests directory back to top level (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Oct 5, 2024
1 parent 30f6cfe commit fb5a3ce
Show file tree
Hide file tree
Showing 122 changed files with 34 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ jobs:
run: swift test --verbose --skip-build

- name: Build WinRTComponent
working-directory: Generator/InteropTests
working-directory: InteropTests
shell: pwsh
run: |
& .\SPMPrebuild.ps1 -SwiftWinRT "$Env:GITHUB_WORKSPACE\Generator\.build\debug\SwiftWinRT.exe"
- name: Build InteropTests
working-directory: Generator/InteropTests
working-directory: InteropTests
shell: pwsh
run: swift build --verbose --build-tests

- name: Run InteropTests
working-directory: Generator/InteropTests
working-directory: InteropTests
shell: pwsh
run: swift test --verbose --skip-build

Expand Down
2 changes: 1 addition & 1 deletion Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Generator> swift build --build-tests
Generator> swift test --skip-build
```

The `/Generator/InteropTests` subdirectory requires building `WinRTComponent.winmd` and `WinRTComponent.dll`, which SPM cannot do. A helper script, `SPMPrebuild.ps1`, will do that using CMake, after which the package can be built and tested normally.
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.
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,26 @@ cmake_minimum_required(VERSION 3.21.0)

project(SwiftWinRT LANGUAGES C Swift)

# Building InteropTests will require running the code generator,
# so we configure and build it as a subproject.
message(STATUS "Configuring Generator as subproject...")
execute_process(
COMMAND ${CMAKE_COMMAND}
-S "${CMAKE_CURRENT_SOURCE_DIR}/Generator"
-B "${CMAKE_CURRENT_BINARY_DIR}/Generator"
-G "${CMAKE_GENERATOR}"
-D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
-D "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
-D "CMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER}"
COMMAND_ERROR_IS_FATAL ANY)

message(STATUS "Building Generator as subproject...")
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/Generator"
COMMAND_ERROR_IS_FATAL ANY)

add_subdirectory(Support)
add_subdirectory(Generator)

# Now build InteropTests, which depends on SWIFTWINRT_EXE
set(SWIFTWINRT_EXE "${CMAKE_CURRENT_BINARY_DIR}/Generator/Sources/SwiftWinRT/SwiftWinRT.exe")
add_subdirectory(InteropTests)
36 changes: 4 additions & 32 deletions Generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
# This directory can be built in two modes: standalone or as a subdirectory.
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# Standalone mode. Only build the code generator.
# We can't build InteropTests in this mode because it depends on SwiftWinRT.exe
cmake_minimum_required(VERSION 3.21.0)
cmake_minimum_required(VERSION 3.21.0)

project(SwiftWinRT LANGUAGES C Swift)
project(SwiftWinRT LANGUAGES C Swift)

add_subdirectory(Dependencies)
add_subdirectory(Sources)
else()
# Subdirectory mode. Build both the code generator and InteropTests.
# Recursively invoke this build in standalone mode so that the code generator is built first,
# and can be used when building InteropTests.
message(STATUS "Configuring Generator as subproject...")
execute_process(
COMMAND ${CMAKE_COMMAND}
-S "${CMAKE_CURRENT_SOURCE_DIR}"
-B "${CMAKE_CURRENT_BINARY_DIR}/Build"
-G "${CMAKE_GENERATOR}"
-D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
-D "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
-D "CMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER}"
COMMAND_ERROR_IS_FATAL ANY)

message(STATUS "Building Generator as subproject...")
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/Build"
COMMAND_ERROR_IS_FATAL ANY)

# Now build InteropTests, which depends on SWIFTWINRT_EXE
set(SWIFTWINRT_EXE "${CMAKE_CURRENT_BINARY_DIR}/Build/Sources/SwiftWinRT/SwiftWinRT.exe")
add_subdirectory(InteropTests)
endif()
add_subdirectory(Dependencies)
add_subdirectory(Sources)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription
let package = Package(
name: "InteropTests",
dependencies: [
.package(name: "Support", path: "../.."),
.package(name: "Support", path: ".."),
.package(name: "Projection", path: "WinRTComponent/Projection"),
],
targets: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ $ErrorActionPreference = "Stop"
if (-not $SwiftWinRT) {
Write-Host -ForegroundColor Cyan "Building SwiftWinRT.exe with SPM..."
$SwiftConfiguration = "debug"
$GeneratorProjectDir = "$PSScriptRoot\.."
$RepoRoot = (& git.exe -C "$PSScriptRoot" rev-parse --path-format=absolute --show-toplevel).Trim()
$GeneratorProjectDir = "$RepoRoot\Generator"
& swift.exe build `
--package-path $GeneratorProjectDir `
--configuration $SwiftConfiguration `
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Setup your project's build to:
1. Download the latest NuGet package from this repo's [Releases](https://github.com/tristanlabelle/swift-winrt/releases). Eventually those will be pushed to `nuget.org`.
2. Invoke the `SwiftWinRT.exe` located in the NuGet package, specifying:
- The Windows SDK and WinMD files to be projected.
- A `projection.json` file to describe the modules to generate, which assemblies should contribute to each of them, and which types to include. Refer to [this example](https://github.com/tristanlabelle/swift-winrt/blob/main/InteropTests/projection.json).
- A `projection.json` file to describe the modules to generate, which assemblies should contribute to each of them, and which types to include. Refer to [this example](InteropTests/projection.json).
- An output directory path.
3. Reference and build the support module under the `swift` subdirectory of the NuGet package.
4. Reference and build the generated code modules. For each module specified in `projection.json`, there should be an assembly module (with projected types), an ABI module (with C code) and any number of namespace modules (with type aliases for convenience).
Expand Down

0 comments on commit fb5a3ce

Please sign in to comment.