Merge pull request #7 from aminya/vcpkg

This commit is contained in:
Amin Yahyaabadi 2021-11-21 12:16:08 -06:00 committed by GitHub
commit 6b4377de1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 500 additions and 515 deletions

View File

@ -19,6 +19,7 @@ The package can be used locally or from CI services like GitHub Actions. Stay tu
- gcc - gcc
- cmake - cmake
- ninja - ninja
- vcpkg
- meson - meson
- conan - conan
- ccache - ccache
@ -42,26 +43,26 @@ Tip: You can automate downloading using `wget`, `curl` or other similar tools.
Download the executable for your platform from [here](https://github.com/aminya/setup-cpp/releases/tag/v0.2.2), and run it with the available options. Download the executable for your platform from [here](https://github.com/aminya/setup-cpp/releases/tag/v0.2.2), and run it with the available options.
An example that installs llvm, cmake, ninja, ccache, and conan: An example that installs llvm, cmake, ninja, ccache, and vcpkg:
```ps1 ```ps1
# windows example (open shell as admin) # windows example (open shell as admin)
curl -O "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_windows.exe" curl -O "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_windows.exe"
./setup_cpp_windows --compiler llvm --cmake true --ninja true --ccache true --conan true ./setup_cpp_windows --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
``` ```
```ps1 ```ps1
# linux example # linux example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_linux" wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_linux"
chmod +x setup_cpp_linux chmod +x setup_cpp_linux
sudo ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --conan true sudo ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
``` ```
```ps1 ```ps1
# mac example # mac example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_mac" wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_mac"
chmod +x setup_cpp_mac chmod +x setup_cpp_mac
sudo ./setup_cpp_mac --compiler llvm --cmake true --ninja true --ccache true --conan true sudo ./setup_cpp_mac --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
``` ```
NOTE: In the `compiler` entry, you can specify the version after `-` like `llvm-11`. NOTE: In the `compiler` entry, you can specify the version after `-` like `llvm-11`.
@ -76,19 +77,19 @@ On Windows
```ps1 ```ps1
# open shell as admin # open shell as admin
curl "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp.js" curl "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp.js"
node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --conan true node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
``` ```
On Linux or Mac: On Linux or Mac:
```ps1 ```ps1
wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp.js" wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp.js"
sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --conan true sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
``` ```
# Inside GitHub Actions # Inside GitHub Actions
Here is a complete cross-platform example that tests llvm and gcc. It also uses cmake, ninja, conan, cppcheck, and ccache. Here is a complete cross-platform example that tests llvm and gcc. It also uses cmake, ninja, vcpkg, cppcheck, and ccache.
`.github/workflows/ci.yml`: `.github/workflows/ci.yml`:
@ -144,8 +145,8 @@ RUN apt-get install -y --no-install-recommends ca-certificates wget unzip
RUN wget --no-verbose "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_linux" RUN wget --no-verbose "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/setup_cpp_linux"
RUN chmod +x ./setup_cpp_linux RUN chmod +x ./setup_cpp_linux
# install llvm, cmake, ninja, ccache, and conan # install llvm, cmake, ninja, ccache, and vcpkg
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --conan true RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
ENTRYPOINT [ "/bin/sh" ] ENTRYPOINT [ "/bin/sh" ]
``` ```
@ -168,5 +169,4 @@ docker run -it setup_cpp
### Incomplete ### Incomplete
- [ ] msvc. It is implemented, but has bugs. See [this issue](https://github.com/aminya/cpp/issues/1) - msvc. It is implemented, but has bugs. See [this issue](https://github.com/aminya/setup-cpp/issues/1)
- [ ] vcpkg (TODO)

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -42,23 +42,23 @@
}, },
"devDependencies": { "devDependencies": {
"@types/cross-spawn": "^6.0.2", "@types/cross-spawn": "^6.0.2",
"@types/jest": "^27.0.2", "@types/jest": "^27.0.3",
"@types/mri": "^1.1.1", "@types/mri": "^1.1.1",
"@types/node": "^16.11.6", "@types/node": "^16.11.9",
"@types/semver": "^7.3.9", "@types/semver": "^7.3.9",
"@types/which": "^2.0.1", "@types/which": "^2.0.1",
"caxa": "^2.1.0", "caxa": "^2.1.0",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"eslint-config-atomic": "^1.16.4", "eslint-config-atomic": "^1.16.5",
"jest": "^27.3.1", "jest": "^27.3.1",
"npm-run-all2": "^5.0.2", "npm-run-all2": "^5.0.2",
"parcel": "^2.0.0", "parcel": "^2.0.1",
"prettier-config-atomic": "^3.0.1", "prettier-config-atomic": "^3.0.1",
"shx": "0.3.3", "shx": "0.3.3",
"terser-config-atomic": "^0.1.1", "terser-config-atomic": "^0.1.1",
"ts-jest": "^27.0.7", "ts-jest": "^27.0.7",
"typescript": "^4.4.4" "typescript": "^4.5.2"
}, },
"engines": { "engines": {
"node": ">=12.x" "node": ">=12.x"

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
const DefaultVersions: Record<string, string> = { const DefaultVersions: Record<string, string> = {
msvc: "2019", msvc: "2019",
llvm: "11.1.0", llvm: "13.0.0",
ninja: "1.10.2", ninja: "1.10.2",
cmake: "3.20.2", cmake: "3.22.0",
gcovr: "5.0", gcovr: "5.0",
conan: "1.40.1", conan: "1.42.1",
meson: "0.59.1", meson: "0.60.1",
python: "3.9.7", python: "3.10.0",
gcc: process.platform === "win32" ? "11.2.0" : "11", gcc: process.platform === "win32" ? "11.2.0.07112021" : "11",
} }
/** Get the default version if passed true or undefined, otherwise return the version itself */ /** Get the default version if passed true or undefined, otherwise return the version itself */

View File

@ -6,6 +6,7 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import semverMajor from "semver/functions/major" import semverMajor from "semver/functions/major"
import semverCoerce from "semver/functions/coerce" import semverCoerce from "semver/functions/coerce"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupGcc(version: string, _setupCppDir: string, arch: string) { export async function setupGcc(version: string, _setupCppDir: string, arch: string) {
@ -54,13 +55,13 @@ export async function setupGcc(version: string, _setupCppDir: string, arch: stri
} }
} }
if (binDir !== undefined) { if (binDir !== undefined) {
activateGcc(version, binDir) await activateGcc(version, binDir)
return { binDir } return { binDir }
} }
return undefined return undefined
} }
function activateGcc(version: string, binDir: string) { async function activateGcc(version: string, binDir: string) {
const majorVersion = semverMajor(semverCoerce(version) ?? version) const majorVersion = semverMajor(semverCoerce(version) ?? version)
// TODO // TODO
@ -79,4 +80,6 @@ function activateGcc(version: string, binDir: string) {
exportVariable("CC", `${binDir}/gcc-${majorVersion}`) exportVariable("CC", `${binDir}/gcc-${majorVersion}`)
exportVariable("CXX", `${binDir}/g++-${majorVersion}`) exportVariable("CXX", `${binDir}/g++-${majorVersion}`)
} }
await setupMacOSSDK()
} }

View File

@ -6,8 +6,7 @@ import { isValidUrl } from "../utils/http/validate_url"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { extractExe, extractTarByExe } from "../utils/setup/extract" import { extractExe, extractTarByExe } from "../utils/setup/extract"
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version" import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version"
import { getExecOutput } from "@actions/exec" import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
import { existsSync } from "fs"
//================================================ //================================================
// Version // Version
@ -48,6 +47,7 @@ export const VERSIONS: Set<string> = getVersions([
"11.1.0", "11.1.0",
"12.0.0", "12.0.0",
"12.0.1", "12.0.1",
"13.0.0",
]) ])
//================================================ //================================================
@ -104,7 +104,7 @@ function getDarwinUrl(version: string): string | null {
* This is useful when there were binaries released for the Linux (Ubuntu) platform for the last RC version but not for * This is useful when there were binaries released for the Linux (Ubuntu) platform for the last RC version but not for
* the actual release version. * the actual release version.
*/ */
const UBUNTU_RC: Map<string, string> = new Map([["12.0.1", "12.0.1-rc4"]]) const UBUNTU_RC: Map<string, string> = new Map()
/** The (latest) Ubuntu versions for each LLVM version. */ /** The (latest) Ubuntu versions for each LLVM version. */
const UBUNTU: { [key: string]: string } = { const UBUNTU: { [key: string]: string } = {
@ -138,11 +138,12 @@ const UBUNTU: { [key: string]: string } = {
"11.0.1": "-ubuntu-16.04", "11.0.1": "-ubuntu-16.04",
"11.1.0": "-ubuntu-16.04", "11.1.0": "-ubuntu-16.04",
"12.0.0": "-ubuntu-20.04", "12.0.0": "-ubuntu-20.04",
"12.0.1-rc4": "-ubuntu-21.04", "12.0.1": "-ubuntu-16.04",
"13.0.0": "-ubuntu-20.04",
} }
/** The latest supported LLVM version for the Linux (Ubuntu) platform. */ /** The latest supported LLVM version for the Linux (Ubuntu) platform. */
const MAX_UBUNTU: string = "12.0.1-rc4" const MAX_UBUNTU: string = "13.0.0"
/** Gets an LLVM download URL for the Linux (Ubuntu) platform. */ /** Gets an LLVM download URL for the Linux (Ubuntu) platform. */
function getLinuxUrl(versionGiven: string): string { function getLinuxUrl(versionGiven: string): string {
@ -258,7 +259,10 @@ export async function activateLLVM(directory: string, version: string) {
core.exportVariable("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`) core.exportVariable("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
core.exportVariable("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`) core.exportVariable("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
if (process.platform !== "win32") {
// https://github.com/aminya/setup-cpp/issues/6
core.exportVariable("CPATH", `${directory}/lib/clang/${llvmMajor}/include`) core.exportVariable("CPATH", `${directory}/lib/clang/${llvmMajor}/include`)
}
core.exportVariable("LDFLAGS", `-L${directory}/lib`) core.exportVariable("LDFLAGS", `-L${directory}/lib`)
core.exportVariable("CPPFLAGS", `-I${directory}/include`) core.exportVariable("CPPFLAGS", `-I${directory}/include`)
@ -268,15 +272,5 @@ export async function activateLLVM(directory: string, version: string) {
core.exportVariable("LIBRARY_PATH", `${directory}/lib`) core.exportVariable("LIBRARY_PATH", `${directory}/lib`)
if (process.platform === "darwin") { await setupMacOSSDK()
try {
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
const sdkroot = xcrun.stdout || xcrun.stderr
if (existsSync(sdkroot)) {
core.exportVariable("SDKROOT", sdkroot)
}
} catch (e) {
core.error(e as Error | string)
}
}
} }

View File

@ -0,0 +1,17 @@
import { getExecOutput } from "@actions/exec"
import { existsSync } from "fs"
import * as core from "@actions/core"
export async function setupMacOSSDK() {
if (process.platform === "darwin") {
try {
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
const sdkroot = xcrun.stdout || xcrun.stderr
if (existsSync(sdkroot)) {
core.exportVariable("SDKROOT", sdkroot)
}
} catch (e) {
core.error(e as Error | string)
}
}
}

View File

@ -22,12 +22,14 @@ import { getVersion } from "./default_versions"
import { setupGcc } from "./gcc/gcc" import { setupGcc } from "./gcc/gcc"
import { InstallationInfo } from "./utils/setup/setupBin" import { InstallationInfo } from "./utils/setup/setupBin"
import { error, success } from "./utils/io/io" import { error, success } from "./utils/io/io"
import { setupVcpkg } from "./vcpkg/vcpkg"
/** The setup functions */ /** The setup functions */
const setups = { const setups = {
cmake: setupCmake, cmake: setupCmake,
ninja: setupNinja, ninja: setupNinja,
python: setupPython, python: setupPython,
vcpkg: setupVcpkg,
conan: setupConan, conan: setupConan,
meson: setupMeson, meson: setupMeson,
gcovr: setupGcovr, gcovr: setupGcovr,
@ -47,6 +49,7 @@ const tools: Array<keyof typeof setups> = [
"choco", "choco",
"brew", "brew",
"python", "python",
"vcpkg",
"cmake", "cmake",
"ninja", "ninja",
"conan", "conan",
@ -233,6 +236,7 @@ All the available tools:
--gcc --gcc
--cmake --cmake
--ninja --ninja
--vcpkg
--meson --meson
--conan --conan
--ccache --ccache

View File

@ -0,0 +1,15 @@
/** Add bin extension to a binary. This will be `.exe` on Windows. */
export function addBinExtension(name: string) {
if (process.platform === "win32") {
return `${name}.exe`
}
return name
}
/** Add native shell extension. This will be `.bat` on Windows and `sh` on unix. */
export function addShellExtension(name: string) {
if (process.platform === "win32") {
return `${name}.bat`
}
return `${name}.sh`
}

View File

@ -89,10 +89,3 @@ export async function setupBin(
return { installDir, binDir } return { installDir, binDir }
} }
/** Add bin extension to a binary. This will be `.exe` on Windows. */
export function addBinExtension(name: string) {
if (process.platform === "win32") {
return `${name}.exe`
}
return name
}

View File

@ -1,7 +1,7 @@
import * as io from "@actions/io" import * as io from "@actions/io"
import { tmpdir } from "os" import { tmpdir } from "os"
import * as path from "path" import * as path from "path"
import { addBinExtension } from "../setup/setupBin" import { addBinExtension } from "../extension/extension"
import { join } from "path" import { join } from "path"
import spawn from "cross-spawn" import spawn from "cross-spawn"

View File

@ -0,0 +1,15 @@
import { setupVcpkg } from "../vcpkg"
import { testBin } from "../../utils/tests/test-helpers"
jest.setTimeout(300000)
async function testvcpkg() {
const { binDir } = await setupVcpkg("", "", "")
await testBin("vcpkg", ["--version"], binDir)
return binDir
}
describe("setup-vcpkg", () => {
it("should setup vcpkg", async () => {
await testvcpkg()
})
})

23
src/vcpkg/vcpkg.ts Normal file
View File

@ -0,0 +1,23 @@
import { addPath } from "@actions/core"
import execa from "execa"
import path from "path"
import untildify from "untildify"
import which from "which"
import { addShellExtension } from "../utils/extension/extension"
import { InstallationInfo } from "../utils/setup/setupBin"
let hasVCPKG = false
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupVcpkg(_version: string, _setupCppDir: string, _arch: string): InstallationInfo {
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: untildify("~/") })
const vcpkgDir = untildify("~/vcpkg")
execa.sync(addShellExtension("bootstrap-vcpkg"), { cwd: vcpkgDir, shell: true })
addPath(vcpkgDir)
hasVCPKG = true
return { binDir: vcpkgDir }
}
return { binDir: path.dirname(which.sync("vcpkg")) }
}