mirror of https://github.com/aminya/setup-cpp
feat: add setupCmake
Used some code from https://github.com/aminya/install-cmake/blob/new-versions-and-arch/src/cmake.ts
This commit is contained in:
parent
3b557ec4c5
commit
33a3592a63
|
@ -6,8 +6,12 @@ inputs:
|
||||||
compiler:
|
compiler:
|
||||||
description: "The compiler and its version."
|
description: "The compiler and its version."
|
||||||
required: false
|
required: false
|
||||||
|
architecture:
|
||||||
|
description: "The CPU architecture"
|
||||||
|
required: false
|
||||||
cmake:
|
cmake:
|
||||||
description: "The cmake version to install."
|
description: "The cmake version to install."
|
||||||
|
default: '3.20.2'
|
||||||
required: false
|
required: false
|
||||||
ninja:
|
ninja:
|
||||||
description: "The ninja version to install."
|
description: "The ninja version to install."
|
||||||
|
|
12
package.json
12
package.json
|
@ -29,10 +29,16 @@
|
||||||
},
|
},
|
||||||
"prettier": "prettier-config-atomic",
|
"prettier": "prettier-config-atomic",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@actions/core": "^1.5.0",
|
||||||
|
"@actions/tool-cache": "^1.7.1",
|
||||||
"@types/node": "^16.9.1",
|
"@types/node": "^16.9.1",
|
||||||
|
"@types/semver": "^7.3.8",
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"eslint-config-atomic": "^1.16.2",
|
"eslint-config-atomic": "^1.16.2",
|
||||||
|
"hasha": "^5.2.2",
|
||||||
|
"parcel": "^2.0.0-rc.0",
|
||||||
"prettier-config-atomic": "^2.0.5",
|
"prettier-config-atomic": "^2.0.5",
|
||||||
|
"semver": "^7.3.5",
|
||||||
"shx": "0.3.3",
|
"shx": "0.3.3",
|
||||||
"terser-config-atomic": "^0.1.1",
|
"terser-config-atomic": "^0.1.1",
|
||||||
"typescript": "^4.4.3"
|
"typescript": "^4.4.3"
|
||||||
|
@ -55,9 +61,5 @@
|
||||||
"cmake",
|
"cmake",
|
||||||
"ninja",
|
"ninja",
|
||||||
"meson"
|
"meson"
|
||||||
],
|
]
|
||||||
"dependencies": {
|
|
||||||
"@actions/core": "^1.5.0",
|
|
||||||
"parcel": "^2.0.0-rc.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
1240
pnpm-lock.yaml
1240
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,106 @@
|
||||||
|
import { extractZip, extractTar, find, downloadTool, cacheDir } from "@actions/tool-cache"
|
||||||
|
import { getInput, addPath, group, startGroup, endGroup } from "@actions/core"
|
||||||
|
import { join, basename } from "path"
|
||||||
|
import { existsSync } from "fs"
|
||||||
|
import semverLte from "semver/functions/lte"
|
||||||
|
import semverCoerce from "semver/functions/coerce"
|
||||||
|
import * as hasha from "hasha"
|
||||||
|
import { tmpdir } from "os"
|
||||||
|
|
||||||
|
interface PackageInfo {
|
||||||
|
url: string
|
||||||
|
binPath: string
|
||||||
|
extractFunction: {
|
||||||
|
(url: string, outputPath: string): Promise<string>
|
||||||
|
}
|
||||||
|
dropSuffix: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the platform data for cmake */
|
||||||
|
function getCmakePlatformData(version: string, platform?: NodeJS.Platform): PackageInfo {
|
||||||
|
const semVersion = semverCoerce(version) ?? version
|
||||||
|
const platformStr = platform ?? process.platform
|
||||||
|
const arch = getInput("architecture") || process.arch
|
||||||
|
switch (platformStr) {
|
||||||
|
case "win32": {
|
||||||
|
const isOld = semverLte(semVersion, "v3.19.6")
|
||||||
|
let osArchStr: string
|
||||||
|
if (["ia32", "x86", "i386", "x32"].includes(arch)) {
|
||||||
|
osArchStr = isOld ? "win32-x86" : "windows-i386"
|
||||||
|
} else {
|
||||||
|
osArchStr = isOld ? "win64-x64" : "windows-x86_64"
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
binPath: "bin/",
|
||||||
|
dropSuffix: ".zip",
|
||||||
|
extractFunction: extractZip,
|
||||||
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.zip`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "darwin": {
|
||||||
|
const isOld = semverLte(semVersion, "v3.19.1")
|
||||||
|
const osArchStr = isOld ? "Darwin-x86_64" : "macos-universal"
|
||||||
|
return {
|
||||||
|
binPath: "CMake.app/Contents/bin/",
|
||||||
|
dropSuffix: ".tar.gz",
|
||||||
|
extractFunction: extractTar,
|
||||||
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.tar.gz`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "linux": {
|
||||||
|
const isOld = semverLte(semVersion, "v3.19.8")
|
||||||
|
let osArchStr: string
|
||||||
|
if (["aarch64"].includes(arch)) {
|
||||||
|
osArchStr = isOld ? "Linux-aarch64" : "linux-aarch64"
|
||||||
|
} else {
|
||||||
|
osArchStr = isOld ? "Linux-x86_64" : "linux-x86_64"
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
binPath: "bin/",
|
||||||
|
dropSuffix: ".tar.gz",
|
||||||
|
extractFunction: extractTar,
|
||||||
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.tar.gz`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported platform '${platformStr}'`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Setup cmake */
|
||||||
|
export async function setupCmake(version: string): Promise<string> {
|
||||||
|
// Restore from cache (if found).
|
||||||
|
const cmakeDir = find("cmake", version)
|
||||||
|
if (cmakeDir) {
|
||||||
|
addPath(cmakeDir)
|
||||||
|
return join(cmakeDir, process.platform === "win32" ? "cmake.exe" : "cmake")
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = getCmakePlatformData(version, process.platform)
|
||||||
|
|
||||||
|
// Get an unique output directory name from the URL.
|
||||||
|
const key: string = await hasha.async(data.url)
|
||||||
|
const cmakePath = join(process.env.RUNNER_TEMP ?? tmpdir(), key)
|
||||||
|
|
||||||
|
const { pathname } = new URL(data.url)
|
||||||
|
const dirName = basename(pathname)
|
||||||
|
const outputPath = join(cmakePath, dirName.replace(data.dropSuffix, ""), data.binPath)
|
||||||
|
|
||||||
|
if (!existsSync(cmakePath)) {
|
||||||
|
await group("Download and extract CMake", async () => {
|
||||||
|
const downloaded = await downloadTool(data.url)
|
||||||
|
await data.extractFunction(downloaded, cmakePath)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
startGroup(`Add CMake to PATH`)
|
||||||
|
addPath(outputPath)
|
||||||
|
} finally {
|
||||||
|
endGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
await cacheDir(cmakePath, "cmake", version)
|
||||||
|
|
||||||
|
return join(outputPath, process.platform === "win32" ? "cmake.exe" : "cmake")
|
||||||
|
}
|
10
src/main.ts
10
src/main.ts
|
@ -1,8 +1,13 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
|
import { setupCmake } from "./cmake/cmake"
|
||||||
|
|
||||||
export async function main(): Promise<number> {
|
export async function main(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
// TODO
|
// setup cmake
|
||||||
|
const cmakeVersion = core.getInput("cmake")
|
||||||
|
if (cmakeVersion !== "false" && cmakeVersion !== "") {
|
||||||
|
await setupCmake(cmakeVersion)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.error(err as string | Error)
|
core.error(err as string | Error)
|
||||||
core.setFailed("install-cpp failed")
|
core.setFailed("install-cpp failed")
|
||||||
|
@ -18,6 +23,7 @@ main()
|
||||||
process.exitCode = ret
|
process.exitCode = ret
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
core.error("main() failed!", error)
|
core.error("main() failed!")
|
||||||
|
core.error(error as string | Error)
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue