Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a schema for Projection.json #337

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,29 @@ jobs:
- name: CMake Build
shell: pwsh
run: cmake --build --preset debug

json-schema:
name: JSON Schema
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- name: Test Schema
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
Test-Json `
-Path InteropTests\WinRTComponent\Projection.json `
-SchemaFile Generator\Projection.schema.json

required:
name: Go/No-Go
runs-on: ubuntu-latest
needs: [spm-support, spm-generator-and-interoptests, cmake, json-schema]
if: always()
steps:
- name: Check for required job failures
if: contains(needs.*.result, 'failure')
run: exit 1
18 changes: 11 additions & 7 deletions Generator/Create-NuGetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
Creates the Swift/WinRT nuget package, including the code generator executable and support module sources.
#>
param(
[string]$NativeExe = $null,
[string]$X64BinPath = $null,
[string]$Arm64BinPath = $null,
[string]$Version = $null,
[string]$StagingDir = $null,
[string]$NuGetExe = "nuget.exe",
[string] $NativeExe = $null,
[string] $X64BinPath = $null,
[string] $Arm64BinPath = $null,
[string] $Version = $null,
[string] $StagingDir = $null,
[string] $NuGetExe = "nuget.exe",
[Parameter(Mandatory=$true)]
[string]$OutputPath)
[string] $OutputPath)

$ErrorActionPreference = "Stop"

Expand Down Expand Up @@ -79,6 +79,10 @@ Out-File -FilePath $StagingDir\swift\Package.swift -InputObject $PackageSwift -E
Copy-Item -Path $RepoRoot\Package.resolved -Destination $StagingDir\swift\ -Force -ErrorAction Ignore | Out-Null # Might not have one
Copy-Item -Path $RepoRoot\Support\Sources\* -Destination $StagingDir\swift\ -Recurse -Force | Out-Null

Write-Host " json schema..."
New-Item -ItemType Directory $StagingDir\json -Force | Out-Null
Copy-Item -Path $PSScriptRoot\Projection.schema.json -Destination $StagingDir\json\ -Force | Out-Null

Write-Host " readme..."
Copy-Item -Path $RepoRoot\Readme.md -Destination $StagingDir\ -Force | Out-Null

Expand Down
46 changes: 46 additions & 0 deletions Generator/Projection.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Defines how to project WinRT types into Swift",
"type": "object",
"properties": {
"modules": {
"description": "Defines the Swift modules to be generated.",
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9_]+$": {
"description": "Defines a generated Swift module.",
"type": "object",
"properties": {
"assemblies": {
"description": "A list of name patterns for assemblies whose types contribute to this module.",
"type": "array",
"items": {
"type": "string"
}
},
"types": {
"title": "A list of name patterns for types to be included in the generated Swift module.",
"type": "array",
"items": {
"type": "string"
}
},
"flattenNamespaces": {
"title": "Whether to ignore WinRT namespaces when generating Swift types.",
"type": "boolean"
},
"fileNameInManifest": {
"title": "The filename of the dll which provides class activation for this module.",
"type": "string"
}
},
"required": [
"assemblies"
],
"additionalProperties": false
}
},
"additionalProperties": false
}
}
}
2 changes: 1 addition & 1 deletion InteropTests/WinRTComponent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include(GenerateProjection.cmake)
generate_projection(
SWIFTWINRT_EXE "${SWIFTWINRT_EXE}"
WINRTCOMPONENT_WINMD "${WINRTCOMPONENT_WINMD}"
PROJECTION_JSON "${CMAKE_CURRENT_SOURCE_DIR}/projection.json"
PROJECTION_JSON "${CMAKE_CURRENT_SOURCE_DIR}/Projection.json"
PROJECTION_DIR "${PROJECTION_DIR}")

# Define the dll build (requires cl.exe)
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ 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](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) or [the schema](Generator/Projection.schema.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).
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).

### With the Swift Package Manager (SPM)

Expand Down
Loading