Skip to content

Add workflow to build SwiftFormat. #544

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

Merged
merged 1 commit into from
May 25, 2023
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
76 changes: 76 additions & 0 deletions .github/workflows/SwiftFormat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: SwiftFormat

on:
workflow_dispatch:

jobs:
windows:
runs-on: windows-latest

strategy:
matrix:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with github actions but do we need the matrix here if we'll be building the same tag/branch on all architectures of the build?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is originally in @compnerd action because the plan is that this is built for an arbitrary number of toolchain releases when (a future version of) this is upstreamed to nick's SwiftFormat repo. Right now, the matrix is no-op.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matrix I was using was for the Swift compiler version. Since we are not ABI stable on Windows, we need the release version matrix for the compile still as the standard library will change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mangini did we test building with the 5.7 toolchain and running against a 5.9 toolchain? I'm worried about the ABI instability in the runtime meaning that we won't be able to use the releases with newer toolchains.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compnerd Do you mean that this SwiftFormat binary is dynamically-linked and that its version needs to include the version of the swift compiler that compiled it? If so, I interpret it as that the matrix needs to have both the compiler version and the SwiftFormat version.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjyamauchi correct. swiftCore, Foundation, and dispatch are always dynamically linked, and the version needs to be the version from the runtime distributed with the toolchain that it was built with. Extending the matrix to both sounds right.

include:
- tag: 0.51.10
branch: master

steps:
# Build
- uses: actions/checkout@v2
with:
fetch-depth: 1
ref: refs/tags/${{ matrix.tag }}
repository: nicklockwood/SwiftFormat

- uses: compnerd/gha-setup-swift@main
with:
branch: development
tag: DEVELOPMENT-SNAPSHOT-2023-05-22-a

- name: test
run: |
swift test

- name: build
run: |
swift build -c release

# Package
- uses: actions/checkout@v2
with:
fetch-depth: 1
ref: ${{ vars.GITHUB_REF_NAME }}
repository: ${{ vars.GITHUB_REPOSITORY }}
path: ${{ github.workspace }}/SourceCache/${{ vars.GITHUB_REPOSITORY }}

- uses: microsoft/[email protected]

- name: package
run: |
msbuild -restore ${{ github.workspace }}\SourceCache\${{ vars.GITHUB_REPOSITORY }}\installer-scripts\SwiftFormat.wixproj -nologo -p:Configuration=Release -p:ProductVersion=${{ matrix.tag }} -p:SWIFTFORMAT_BUILD=${{ github.workspace }}\.build\release -p:OutputPath=${{ github.workspace }}\artifacts -p:RunWixToolsOutOfProc=true

# Release
- uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: create_release
with:
draft: true
prerelease: true
release_name: SwiftFormat-${{ matrix.tag }}
tag_name: SwiftFormat-${{ matrix.tag }}
- uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_content_type: application/octet-stream
asset_name: swiftformat.exe
asset_path: .build\x86_64-unknown-windows-msvc\release\swiftformat.exe
upload_url: ${{ steps.create_release.outputs.upload_url }}
- uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_content_type: application/octet-stream
asset_name: SwiftFormat.msi
asset_path: ${{ github.workspace }}\artifacts\SwiftFormat.msi
upload_url: ${{ steps.create_release.outputs.upload_url }}
52 changes: 52 additions & 0 deletions installer-scripts/SwiftFormat-amd64.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package
Language="1033"
Manufacturer="nicklockwood"
Name="SwiftFormat for Windows x86_64"
UpgradeCode="98e01ac8-a17d-43fd-99ed-1cd8b58715bf"
Version="$(var.ProductVersion)"
Scope="perMachine">
<SummaryInformation Description="SwiftFormat for Windows x86_64" />

<!-- NOTE(compnerd) use pre-3.0 schema for better compatibility. -->
<Media Id="1" Cabinet="SwiftFormat.cab" EmbedCab="yes" />

<!-- Directory Structure -->
<!-- WindowsVolume is not a StandardDirectory value, but rather a standard property. See https://github.com/wixtoolset/issues/issues/7314 -->
<SetDirectory Id="WINDOWSVOLUME" Value="[WindowsVolume]" />
<Directory ComponentGuidGenerationSeed="7818d7fe-5173-4a41-9809-e72263ea9738" Id="WINDOWSVOLUME">
<Directory Id="INSTALLDIR">
<Directory Id="Library" Name="Library">
<Directory Id="Developer" Name="Developer">
<Directory Id="Tools" Name="Tools">
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>

<!-- Components -->
<ComponentGroup Id="SwiftFormat">
<Component Id="swiftformat.exe" Directory="Tools" Guid="77126634-5f91-40a7-b344-035ce99ef46f">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good opportunity to try removing Component-specific guids. I believe ComponentGuidGenerationSeed enables all of these guids to be generated deterministically. Full discussion here:

https://github.com/orgs/wixtoolset/discussions/7337

Suggested change
<Component Id="swiftformat.exe" Directory="Tools" Guid="77126634-5f91-40a7-b344-035ce99ef46f">
<Component Id="swiftformat.exe" Directory="Tools">

Copy link
Collaborator Author

@hjyamauchi hjyamauchi May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tristanlabelle I'm getting this error after dropping Guid=...

D:\a\swift-build\swift-build\SourceCache\installer-scripts\SwiftFormat.wxs(35): error WIX0230: The Component/@Guid attribute's value '*' is not valid for this component because it does not meet the criteria for having an automatically generated guid. Components using a Directory as a KeyPath or containing ODBCDataSource child elements cannot use an automatically generated guid. Make sure your component doesn't have a Directory as the KeyPath and move any ODBCDataSource child elements to components with explicit component guids. [D:\a\swift-build\swift-build\SourceCache\installer-scripts\SwiftFormat.wixproj]

Component indeed has a Directory attribute:

<Component Id="swiftformat.exe" Directory="Tools">

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just merge the directory layout and component bits. That would allow us to remove the Directory attribute right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah if that syntax is valid then that would make sense! I was wondering what was the alternative to what we are doing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compnerd Any examples or reference on how to merge directory/component? Apple's wsx files follow this unmerged pattern.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjyamauchi the wxs files there were authored by me and originally in this repository :)

I think that the ComponentGroup will need to be replaced by Components as per the WiX Schema: https://wixtoolset.org/docs/schema/wxs/directory/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think I found a way to avoid guid in the .exe component by removing the component group and moving the component into a directory. But it still complains about the EnvironmentVariables component's missing guid when it's moved into a directory.

Copy link
Collaborator Author

@hjyamauchi hjyamauchi May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this: "Generatable guids are supported only for components with a single file as the component's keypath or no files and a registry value as the keypath." It sounds like the .exe component can have generated guid but not the environment variable one because the latter doesn't have a file or registery value as a child in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#549 is what I got far. @compnerd @tristanlabelle Do you see a way to use autogenerated GUID for the environment variable component?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't but it's probably no big deal? I think the guids were local to the installer and even if they were not, it might make sense for the guids to clash if you tried to run multiple installers setting the same environment variable. (not sure)

<File Id="swiftformat.exe" Source="$(var.SWIFTFORMAT_BUILD)\swiftformat.exe" Checksum="yes" />
</Component>
</ComponentGroup>

<Component Id="EnvironmentVariables" Directory="INSTALLDIR" Guid="b46687c3-f836-47e5-9b43-d9fd2552a731">
<Environment Id="Path" Action="set" Name="Path" Part="last" Permanent="no" System="yes" Value="[INSTALLDIR]Library\Developer\Tools" />
</Component>

<Feature Id="SwiftFormat" AllowAbsent="no" AllowAdvertise="yes" ConfigurableDirectory="INSTALLDIR" Description="SwiftFormat for Windows x86_64" Level="1" Title="SwiftFormat (Windows x86_64)">
<ComponentGroupRef Id="SwiftFormat" />
<ComponentRef Id="EnvironmentVariables" />
</Feature>

<UI>
<ui:WixUI Id="WixUI_InstallDir" />
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2" />
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2" />
</UI>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"></Property>

</Package>
</Wix>
52 changes: 52 additions & 0 deletions installer-scripts/SwiftFormat-arm64.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package
Language="1033"
Manufacturer="nicklockwood"
Name="SwiftFormat for Windows aarch64"
UpgradeCode="12571ad2-06b7-46e0-9e03-209db2b5667d"
Version="$(var.ProductVersion)"
Scope="perMachine">
<SummaryInformation Description="SwiftFormat for Windows aarch64" />

<!-- NOTE(compnerd) use pre-3.0 schema for better compatibility. -->
<Media Id="1" Cabinet="SwiftFormat.cab" EmbedCab="yes" />

<!-- Directory Structure -->
<!-- WindowsVolume is not a StandardDirectory value, but rather a standard property. See https://github.com/wixtoolset/issues/issues/7314 -->
<SetDirectory Id="WINDOWSVOLUME" Value="[WindowsVolume]" />
<Directory ComponentGuidGenerationSeed="ae6cd8c6-6eba-46ff-8784-d432fa64367e" Id="WINDOWSVOLUME">
<Directory Id="INSTALLDIR">
<Directory Id="Library" Name="Library">
<Directory Id="Developer" Name="Developer">
<Directory Id="Tools" Name="Tools">
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>

<!-- Components -->
<ComponentGroup Id="SwiftFormat">
<Component Id="swiftformat.exe" Directory="Tools" Guid="2803667e-f043-4bf8-94d6-f3926be39597">
<File Id="swiftformat.exe" Source="$(var.SWIFTFORMAT_BUILD)\swiftformat.exe" Checksum="yes" />
</Component>
</ComponentGroup>

<Component Id="EnvironmentVariables" Directory="INSTALLDIR" Guid="9e402459-cfe7-4476-a084-fc613016b626">
<Environment Id="Path" Action="set" Name="Path" Part="last" Permanent="no" System="yes" Value="[INSTALLDIR]Library\Developer\Tools" />
</Component>

<Feature Id="SwiftFormat" AllowAbsent="no" AllowAdvertise="yes" ConfigurableDirectory="INSTALLDIR" Description="SwiftFormat for Windows aarch64" Level="1" Title="SwiftFormat (Windows aarch64)">
<ComponentGroupRef Id="SwiftFormat" />
<ComponentRef Id="EnvironmentVariables" />
</Feature>

<UI>
<ui:WixUI Id="WixUI_InstallDir" />
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2" />
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2" />
</UI>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"></Property>

</Package>
</Wix>
32 changes: 32 additions & 0 deletions installer-scripts/SwiftFormat.wixproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="WixToolset.Sdk/4.0.0">
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<PropertyGroup>
<ProductArchitecture Condition=" '$(ProductArchitecture)' == '' ">amd64</ProductArchitecture>
<ProductArchitecture>$(ProductArchitecture)</ProductArchitecture>

<ProductVersion Condition=" '$(ProductVersion)' == '' ">0.0.0</ProductVersion>
<ProductVersion>$(ProductVersion)</ProductVersion>
</PropertyGroup>

<PropertyGroup>
<OutputPath>build\</OutputPath>
<IntermediateOutputPath>build\obj\</IntermediateOutputPath>
</PropertyGroup>

<!-- <Import Project="WiXCodeSigning.targets" /> -->

<PropertyGroup>
<DefineConstants>ProductVersion=$(ProductVersion);SWIFTFORMAT_BUILD=$(SWIFTFORMAT_BUILD)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="SwiftFormat-$(ProductArchitecture).wxs" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a good opportunity to prototype having a single .wxs file for both architectures and using variables to account for any differences. It would inform if we can do the same thing for the toolset.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wixtoolset maintainer also said that component GUIDs were not system-global so we could consolidate architectures even if we can't figure out how to remove the GUIDs.

</ItemGroup>
</Project>