Skip to content

Commit

Permalink
Merge pull request #562 from dennisameling/native-arm64-sdk
Browse files Browse the repository at this point in the history
Use new git-sdk-arm64 for aarch64
  • Loading branch information
dscho authored Dec 22, 2022
2 parents 1a859cf + eb5175d commit 1478e8d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 138 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The supported flavors are:

### CPU architecture support

Git for Windows SDK comes in variants targeting `x86_64` (AKA "64-bit") and `i686` (AKA 32-bit). The default is `x86_64` and can be overridden like this:
Git for Windows SDK comes in variants targeting `x86_64` (AKA "64-bit"), `i686` (AKA 32-bit) and `aarch64` (AKA arm64). The default is `x86_64` and can be overridden like this:

```yaml
- uses: git-for-windows/setup-git-for-windows-sdk
Expand All @@ -60,9 +60,7 @@ Git for Windows SDK comes in variants targeting `x86_64` (AKA "64-bit") and `i68
architecture: i686
```

Please note that only the `build-installers` and the `full` flavors are available for `i686`.

As a special case, the architecture `aarch64` (AKA "ARM64") is also handled, even if there is no SDK fully targeting Windows/ARM64 (due to missing Cygwin/MSYS support for that architecture); Selecting this architecture will install the `x86_64` flavor of Git for Windows' SDK and then add the MINGW toolchain targeting Windows/ARM64.
Please note that only the `build-installers` and the `full` flavors are available for `i686`. For `aarch64`, only the `full` flavor is available.

### Verbosity

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
default: 'minimal'
architecture:
required: false
description: 'The architecture of the SDK: x86_64, i686 or aarch64. Note that "aarch64" uses the x86_64 SDK, but adds "clangarm64" to the path.'
description: 'The architecture of the SDK: x86_64, i686 or aarch64. Note that "aarch64" only supports the "full" flavor for now.'
default: 'x86_64'
msys:
required: false
Expand Down
67 changes: 12 additions & 55 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

84 changes: 8 additions & 76 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from '@actions/core'
import {mkdirp} from './src/downloader'
import {restoreCache, saveCache} from '@actions/cache'
import process from 'process'
import {spawn, spawnSync} from 'child_process'
import {spawnSync} from 'child_process'
import {
getArtifactMetadata,
getViaGit,
Expand All @@ -13,65 +13,6 @@ import * as fs from 'fs'
const flavor = core.getInput('flavor')
const architecture = core.getInput('architecture')

async function installArm64Dependencies(
outputDirectory: string
): Promise<void> {
if (flavor === 'minimal') {
throw new Error(`ARM64 not yet supported with flavor '${flavor}`)
}

mkdirp(`${outputDirectory}/clangarm64`)
fs.appendFileSync(
`${outputDirectory}/etc/pacman.conf`,
`
[clangarm64]
Server = https://mirror.msys2.org/mingw/clangarm64/`
)

const packages = [
'base-devel',
'mingw-w64-clang-aarch64-openssl',
'mingw-w64-clang-aarch64-zlib',
'mingw-w64-clang-aarch64-curl',
'mingw-w64-clang-aarch64-expat',
'mingw-w64-clang-aarch64-libiconv',
'mingw-w64-clang-aarch64-pcre2',
'mingw-w64-clang-aarch64-libssp'
]
if (
flavor === 'full' ||
flavor === 'makepkg-git' ||
flavor === 'build-installers'
) {
packages.push(
'mingw-w64-clang-aarch64-toolchain',
'mingw-w64-clang-aarch64-asciidoc'
)
}

const child = spawn('pacman.exe', ['-Sy', '--noconfirm', ...packages])

child.stdout.setEncoding('utf-8')
child.stderr.setEncoding('utf-8')

child.stdout.on('data', data => {
core.info(data)
})

child.stderr.on('data', data => {
core.error(data)
})

return new Promise((resolve, reject) => {
child.on('error', error => reject(error))
child.on('close', status =>
status === 0
? resolve()
: reject(new Error(`Process exited with status code ${status}`))
)
})
}

async function run(): Promise<void> {
try {
if (process.platform !== 'win32') {
Expand All @@ -81,15 +22,19 @@ async function run(): Promise<void> {
return
}

const architectureToDownload =
architecture === 'aarch64' ? 'x86_64' : architecture
if (architecture === 'aarch64' && flavor !== 'full') {
throw new Error(
'On aarch64, only the "full" flavor is supported at this time.'
)
}

const githubToken = core.getInput('github-token')
const verbose = core.getInput('verbose')
const msysMode = core.getInput('msys') === 'true'

const {artifactName, download, id} = await getViaGit(
flavor,
architectureToDownload,
architecture,
githubToken
)
const outputDirectory = core.getInput('path') || `C:/${artifactName}`
Expand Down Expand Up @@ -154,12 +99,6 @@ async function run(): Promise<void> {
`/${mingw.toLocaleLowerCase()}/bin`
]

if (architecture === 'aarch64') {
// Some binaries aren't available yet in the /clangarm64/bin folder, but Windows 11 ARM64
// has support for x64 emulation, so let's add /mingw64/bin as a fallback.
binPaths.splice(binPaths.length - 1, 0, '/mingw64/bin')
}

for (const binPath of msysMode ? binPaths.reverse() : binPaths) {
core.addPath(`${outputDirectory}${binPath}`)
}
Expand Down Expand Up @@ -199,13 +138,6 @@ async function run(): Promise<void> {
})) {
ln(`/dev/${linkPath}`, `/proc/self/${target}`)
}

if (msystem === 'CLANGARM64') {
// ARM64 dependencies aren't included yet in the Git for Windows SDK. Ask Pacman to install them.
core.startGroup(`Installing CLANGARM64 dependencies`)
await installArm64Dependencies(outputDirectory)
core.endGroup()
}
} catch (error) {
core.setFailed(error instanceof Error ? error.message : `${error}`)
}
Expand Down
11 changes: 10 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ export function getArtifactMetadata(
architecture: string
): {bitness: string; repo: string; artifactName: string} {
const bitness = architecture === 'i686' ? '32' : '64'
const repo = `git-sdk-${bitness}`
const repo = {
i686: 'git-sdk-32',
x86_64: 'git-sdk-64',
aarch64: 'git-sdk-arm64'
}[architecture]

if (repo === undefined) {
throw new Error(`Invalid architecture ${architecture} specified`)
}

const artifactName = `${repo}-${flavor}`

return {bitness, repo, artifactName}
Expand Down

0 comments on commit 1478e8d

Please sign in to comment.