Skip to content
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
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ jobs:
- os: ubuntu-22.04
swift: ${{ fromJSON(vars.SETUPSWIFT_CUSTOM_TOOLCHAINS).ubuntu2204 }} # custom toolchain
development: true
- os: macos-14
swift: '6.0.3'
development: false
sdk: aarch64-swift-linux-musl
sdk-url: https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz
sdk-checksum: 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd

steps:
- name: Checkout repository
Expand Down Expand Up @@ -210,6 +216,7 @@ jobs:
development: ${{ matrix.development }}
check-latest: ${{ needs.ci.outputs.check_latest }}
cache-snapshot: ${{ !matrix.development }}
prefer-oss-toolchain: ${{ matrix.sdk != '' }}

- name: Verify Swift version in macos
if: runner.os == 'macOS'
Expand All @@ -222,6 +229,16 @@ jobs:
if: runner.os == 'Windows'
run: which link | grep "Microsoft Visual Studio" || exit 1

- name: Install SDK
if: matrix.sdk != ''
run: swift sdk install "${{ matrix.sdk-url }}" --checksum "${{ matrix.sdk-checksum }}"

- name: Test Swift package
if: matrix.sdk != ''
run: |
swift package init --type library --name SetupLib
swift build --swift-sdk ${{ matrix.sdk }}

- name: Get cached installation
id: get-tool
if: failure()
Expand Down
44 changes: 44 additions & 0 deletions __tests__/installer/xcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('macOS toolchain installation verification', () => {
const installer = new XcodeToolchainInstaller(toolchain)
jest.spyOn(fs, 'access').mockResolvedValue()
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(core, 'getBooleanInput').mockReturnValue(false)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0`,
Expand All @@ -55,6 +56,48 @@ describe('macOS toolchain installation verification', () => {
expect(process.env.DEVELOPER_DIR).toBe(toolchain.xcodePath)
})

it('tests toolchain preinstalled not preferred', async () => {
const installer = new XcodeToolchainInstaller(toolchain)
const identifier = 'org.swift.581202305171a'
jest.spyOn(fs, 'access').mockResolvedValue()
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(core, 'getBooleanInput').mockReturnValue(true)
jest.spyOn(cache, 'restoreCache').mockResolvedValue(undefined)
jest.spyOn(toolCache, 'find').mockReturnValue('')
jest.spyOn(cache, 'saveCache').mockResolvedValue(1)
jest.spyOn(fs, 'access').mockResolvedValue()
jest.spyOn(fs, 'readFile').mockResolvedValue('')
jest.spyOn(fs, 'cp').mockResolvedValue()
jest.spyOn(plist, 'parse').mockReturnValue({CFBundleIdentifier: identifier})
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0`,
stderr: ''
})
const download = path.resolve('tool', 'download', 'path')
const extracted = path.resolve('tool', 'extracted', 'path')
const deployed = path.resolve('tool', 'deployed', 'path')
const cached = path.resolve('tool', 'cached', 'path')
const installationNeededSpy = jest.spyOn(installer, 'isInstallationNeeded')
const downloadSpy = jest
.spyOn(toolCache, 'downloadTool')
.mockResolvedValue(download)
const extractXarSpy = jest
.spyOn(toolCache, 'extractXar')
.mockResolvedValue(extracted)
const extractTarSpy = jest
.spyOn(toolCache, 'extractTar')
.mockResolvedValue(deployed)
const cacheSpy = jest.spyOn(toolCache, 'cacheDir').mockResolvedValue(cached)
await installer.install('x86_64')
await installer.install('aarch64')
for (const spy of [downloadSpy, extractXarSpy, extractTarSpy, cacheSpy]) {
expect(spy).toHaveBeenCalled()
}
expect(installationNeededSpy).toHaveBeenCalled()
expect(process.env.DEVELOPER_DIR).toBe(toolchain.xcodePath)
})

it('tests download', async () => {
const installer = new XcodeToolchainInstaller(toolchain)
expect(installer['version']).toStrictEqual(parseSemVer('5.8.1'))
Expand Down Expand Up @@ -185,6 +228,7 @@ describe('macOS toolchain installation verification', () => {
jest.spyOn(toolCache, 'find').mockReturnValue('')
jest.spyOn(fs, 'access').mockResolvedValue()
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(core, 'getBooleanInput').mockReturnValue(false)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: `swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0`,
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ inputs:
i.e. Microsoft.VisualStudio.Component.VC.ATL;Microsoft.VisualStudio.Component.VC.CMake.Project;Microsoft.VisualStudio.Component.Windows10SDK
required: false
default: ''
prefer-oss-toolchain:
description: >-
Whether to prefer installing Swift open source toolchain over using Xcode integrated toolchain.
i.e. Enable this option for installing static SDK: https://www.swift.org/documentation/articles/static-linux-getting-started.html
required: false
default: 'false'
outputs:
swift-version:
description: The actual Swift version that was configured.
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/installer/xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class XcodeToolchainInstaller extends ToolchainInstaller<XcodeToolchainSn
const command = this.swiftVersionCommand('')
const version = await this.installedSwiftVersion(command)
core.debug(`Found toolchain "${version}" bundled with Xcode ${xcode}`)
if (core.getBooleanInput('prefer-oss-toolchain')) {
core.debug(`Giving preference to open source toolchain`)
return true
}
return this.data.dir !== `swift-${version}-RELEASE`
}

Expand Down
Loading