Skip to content

Commit

Permalink
add license and update readme (#112)
Browse files Browse the repository at this point in the history
* add license and update readme

* update version and add pipeline for building package for nuget.org

* Update LICENSE

Co-authored-by: Tristan Labelle <tristan@thebrowser.company>

* Update README.md

Co-authored-by: Tristan Labelle <tristan@thebrowser.company>

---------

Co-authored-by: Tristan Labelle <tristan@thebrowser.company>
  • Loading branch information
stevenbrix and tristanlabelle authored Oct 26, 2023
1 parent 3a05cc9 commit d653114
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 24 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/nuget-public.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build for Nuget.org

on:
workflow_dispatch:

jobs:
release-and-publish:
env:
NUGET_VERSION_MAJOR: 0
NUGET_VERSION_MINOR: ${{ github.run_number }}
NUGET_VERSION_PATCH: 0
runs-on: windows-2022
name: Swift/WinRT Release Build & Publish
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: ./.github/actions/windows-build
env:
NUGET_VERSION: ${{ env.NUGET_VERSION_MAJOR}}.${{env.NUGET_VERSION_MINOR }}.${{env.NUGET_VERSION_PATCH }}
with:
config: release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build Nuget
shell: cmd
run: |
cmake --build --preset release --target nuget
- name: Publish NuGet Package
uses: actions/upload-artifact@v3
with:
name: Nuget
path: ${{ github.workspace }}\build\release\*.nupkg
12 changes: 5 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:

jobs:
release-and-publish:
env:
NUGET_VERSION_MAJOR: 0
NUGET_VERSION_MINOR: 1
NUGET_VERSION_PATCH: ${{ github.run_number }}
runs-on: windows-2022
name: Swift/WinRT Release Build & Publish
permissions:
Expand All @@ -16,16 +20,10 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Get Git Hash
id: git-hash
shell: powershell
run: |
$hash=$(git log --format=%h -n1)
echo "GIT_HASH=$hash" >> $env:GITHUB_OUTPUT

- uses: ./.github/actions/windows-build
env:
NUGET_HASH: ${{ steps.git-hash.outputs.GIT_HASH }}
NUGET_VERSION: ${{ env.NUGET_VERSION_MAJOR }}.${{ env.NUGET_VERSION_MAJOR }}.${{ env.NUGET_VERSION_PATCH }}
with:
config: release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ endif()
add_subdirectory(swiftwinrt)
add_subdirectory(tests)

set(NUGET_VERSION 0.0.0.1)
if(DEFINED ENV{NUGET_HASH})
set(NUGET_VERSION_WITH_SUFFIX ${NUGET_VERSION}-$ENV{NUGET_HASH})
if (NOT DEFINED ENV{NUGET_VERSION})
set(NUGET_VERSION 0.1.0)
else()
set(NUGET_VERSION_WITH_SUFFIX ${NUGET_VERSION}-local)
set(NUGET_VERSION $ENV{NUGET_VERSION})
endif()

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/nuget/TheBrowserCompany.SwiftWinRT.nupkg
COMMAND ${CMAKE_BINARY_DIR}/nuget pack ${CMAKE_CURRENT_SOURCE_DIR}\\nuget\\swiftwinrt.nuspec -Properties swiftwinrt_exe=${CMAKE_CURRENT_SOURCE_DIR}\\out\\${CMAKE_BUILD_TYPE}\\bin\\swiftwinrt.exe -Version ${NUGET_VERSION_WITH_SUFFIX}
COMMAND ${CMAKE_BINARY_DIR}/nuget pack ${CMAKE_CURRENT_SOURCE_DIR}\\nuget\\swiftwinrt.nuspec -Properties swiftwinrt_exe=${CMAKE_CURRENT_SOURCE_DIR}\\out\\${CMAKE_BUILD_TYPE}\\bin\\swiftwinrt.exe -Version ${NUGET_VERSION}
)

add_custom_target(nuget
Expand Down
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2023 The Browser Company


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# swiftwinrt
# Swift/WinRT
Swift Language Projection for WinRT

This project is based on the Microsoft created [cppwinrt](https://github.com/microsoft/cppwinrt) project and carries the same source structure.

Swift/WinRT generates *both* the C ABI definition, which is imported into a Swift module *and* the actual Swift bindings which call into the ABI.
Swift/WinRT generates *both* the C ABI definition, which is imported into a Swift module *and* the actual Swift bindings which call into the ABI.

## Project Structure

Expand All @@ -15,7 +15,7 @@ This project has 4 different main projects:

For all C++ code (1 and 2 above) - they are built with **CMake**
For all Swift code (3 and 4 above) - they are built with **SPM**

## Developer Worklow

### Initial Setup
Expand Down Expand Up @@ -48,30 +48,30 @@ or, for a one-liner (on powershell);

**NOTE: you don't want to re-run configure every-time, so the one-liner omits that step**

While it is possible to use this one-liner for your inner-loop, there is a known issue which causes the swiftwinrt build to be dirtied every time, and re-running swiftwinrt in debug mode is very slow! This is why we set `CMAKE_SKIP_INSTALL_ALL_DEPENDENCY` in our [CMakePresets.json](./CMakePresets.json). So when you can building/testing in `release` mode will be quicker. Generally, this is the golden path forward for when you don't need to debug tests. However, if you need to debug tests, then you will likely want to build debug. See [below](#optimal-developer-workflow-for-debugging-tests) for optimal `debug` config workflow.
While it is possible to use this one-liner for your inner-loop, there is a known issue which causes the swift-winrt build to be dirtied every time, and re-running swift-winrt in debug mode is very slow! This is why we set `CMAKE_SKIP_INSTALL_ALL_DEPENDENCY` in our [CMakePresets.json](./CMakePresets.json). So when you can building/testing in `release` mode will be quicker. Generally, this is the golden path forward for when you don't need to debug tests. However, if you need to debug tests, then you will likely want to build debug. See [below](#optimal-developer-workflow-for-debugging-tests) for optimal `debug` config workflow.

### Debugging Tests in Visual Studio Code

The test code (written in Swift) is easily buildable and debuggable in VS Code. You can build using `Ctrl+Shift+B` and then debug via the standard VSCode debug window (or press `F5`).

**NOTE: When building tests in VSCode, swiftwinrt *is not* re-run, as this only runs the SPM portion of the build.**
**NOTE: When building tests in VSCode, swift-winrt *is not* re-run, as this only runs the SPM portion of the build.**

#### Optimal developer workflow for debugging tests

If you need to build debug, then the following workflow is recommended:
1. Open swiftwinrt directory in Visual Studio and select the release configuration (see [Debugging SwiftWinRT in Visual Studio](#debugging-swiftwinrt-in-visual-studio))
2. Open VSCode to the root of the repo and ensure the `Debug` preset is selected.
1. Open swiftwinrt directory in Visual Studio and select the release configuration (see [Debugging swift-winrt in Visual Studio](#debugging-swiftwinrt-in-visual-studio))
2. Open VSCode to the root of the repo and ensure the `Debug` preset is selected.

This workflow has a couple key benefits:
1. This will let you quickly re-run swiftwinrt in release mode when needed while still being able to only build debug for the tests.
2. Controlling when swiftwinrt is re-run has the benefit of allowing you to hand-edit any files you need to prototype with APIs.
1. This will let you quickly re-run swift-winrt in release mode when needed while still being able to only build debug for the tests.
2. Controlling when swift-winrt is re-run has the benefit of allowing you to hand-edit any files you need to prototype with APIs.

You do have to be careful that when you are done iterating (especially on handwritten changes) that you run a full build. However, your PR will fail if this happens.

### Debugging Swift/WinRT in Visual Studio
### Debugging swift-winrt in Visual Studio

When working on the bindings, the best experience is to use full Visual Studio (*not* VS Code) and open the [swiftwinrt cmake file](./swiftwinrt/CMakeLists.txt)
in VS and build that way.
When working on the bindings, the best experience is to use full Visual Studio (*not* VS Code) and open the [swift-winrt cmake file](./swiftwinrt/CMakeLists.txt)
in VS and build that way.

The build process generates a .rsp file which can be used to easily generate the bindings. So first, run a build so that this file is generated.

Expand Down

0 comments on commit d653114

Please sign in to comment.