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
- cmake
- ninja
- vcpkg
- meson
- conan
- 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.
An example that installs llvm, cmake, ninja, ccache, and conan:
An example that installs llvm, cmake, ninja, ccache, and vcpkg:
```ps1
# windows example (open shell as admin)
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
# linux example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/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
# mac example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.2.2/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`.
@ -76,19 +77,19 @@ On Windows
```ps1
# open shell as admin
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:
```ps1
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
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`:
@ -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 chmod +x ./setup_cpp_linux
# install llvm, cmake, ninja, ccache, and conan
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --conan true
# install llvm, cmake, ninja, ccache, and vcpkg
RUN ./setup_cpp_linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
ENTRYPOINT [ "/bin/sh" ]
```
@ -168,5 +169,4 @@ docker run -it setup_cpp
### Incomplete
- [ ] msvc. It is implemented, but has bugs. See [this issue](https://github.com/aminya/cpp/issues/1)
- [ ] vcpkg (TODO)
- msvc. It is implemented, but has bugs. See [this issue](https://github.com/aminya/setup-cpp/issues/1)

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

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
const DefaultVersions: Record<string, string> = {
msvc: "2019",
llvm: "11.1.0",
llvm: "13.0.0",
ninja: "1.10.2",
cmake: "3.20.2",
cmake: "3.22.0",
gcovr: "5.0",
conan: "1.40.1",
meson: "0.59.1",
python: "3.9.7",
gcc: process.platform === "win32" ? "11.2.0" : "11",
conan: "1.42.1",
meson: "0.60.1",
python: "3.10.0",
gcc: process.platform === "win32" ? "11.2.0.07112021" : "11",
}
/** 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 semverMajor from "semver/functions/major"
import semverCoerce from "semver/functions/coerce"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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) {
activateGcc(version, binDir)
await activateGcc(version, binDir)
return { binDir }
}
return undefined
}
function activateGcc(version: string, binDir: string) {
async function activateGcc(version: string, binDir: string) {
const majorVersion = semverMajor(semverCoerce(version) ?? version)
// TODO
@ -79,4 +80,6 @@ function activateGcc(version: string, binDir: string) {
exportVariable("CC", `${binDir}/gcc-${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 { extractExe, extractTarByExe } from "../utils/setup/extract"
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version"
import { getExecOutput } from "@actions/exec"
import { existsSync } from "fs"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
//================================================
// Version
@ -48,6 +47,7 @@ export const VERSIONS: Set<string> = getVersions([
"11.1.0",
"12.0.0",
"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
* 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. */
const UBUNTU: { [key: string]: string } = {
@ -138,11 +138,12 @@ const UBUNTU: { [key: string]: string } = {
"11.0.1": "-ubuntu-16.04",
"11.1.0": "-ubuntu-16.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. */
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. */
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("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("LDFLAGS", `-L${directory}/lib`)
core.exportVariable("CPPFLAGS", `-I${directory}/include`)
@ -268,15 +272,5 @@ export async function activateLLVM(directory: string, version: string) {
core.exportVariable("LIBRARY_PATH", `${directory}/lib`)
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)
}
}
await setupMacOSSDK()
}

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 { InstallationInfo } from "./utils/setup/setupBin"
import { error, success } from "./utils/io/io"
import { setupVcpkg } from "./vcpkg/vcpkg"
/** The setup functions */
const setups = {
cmake: setupCmake,
ninja: setupNinja,
python: setupPython,
vcpkg: setupVcpkg,
conan: setupConan,
meson: setupMeson,
gcovr: setupGcovr,
@ -47,6 +49,7 @@ const tools: Array<keyof typeof setups> = [
"choco",
"brew",
"python",
"vcpkg",
"cmake",
"ninja",
"conan",
@ -233,6 +236,7 @@ All the available tools:
--gcc
--cmake
--ninja
--vcpkg
--meson
--conan
--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 }
}
/** 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 { tmpdir } from "os"
import * as path from "path"
import { addBinExtension } from "../setup/setupBin"
import { addBinExtension } from "../extension/extension"
import { join } from "path"
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")) }
}