diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9be5991..caa155e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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' @@ -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() diff --git a/__tests__/installer/xcode.test.ts b/__tests__/installer/xcode.test.ts index feddd2f..76339b8 100644 --- a/__tests__/installer/xcode.test.ts +++ b/__tests__/installer/xcode.test.ts @@ -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`, @@ -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')) @@ -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`, diff --git a/action.yml b/action.yml index 9f8009f..a0d9bf8 100644 --- a/action.yml +++ b/action.yml @@ -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. diff --git a/dist/index.js b/dist/index.js index 92363d0..0fb934a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -984,6 +984,10 @@ class XcodeToolchainInstaller extends base_1.ToolchainInstaller { 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`; } async install(arch) { diff --git a/src/installer/xcode.ts b/src/installer/xcode.ts index 9adec41..fc4d70e 100644 --- a/src/installer/xcode.ts +++ b/src/installer/xcode.ts @@ -38,6 +38,10 @@ export class XcodeToolchainInstaller extends ToolchainInstaller