From aa2e60900e4cc1eda092dd8f53dab2b32efeacf5 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 1 Feb 2021 13:01:31 +0100 Subject: [PATCH 1/3] CI: Cleanup, checkout v2 (#24) - Remove the fail-fast: tag, it's non-functional since a matrix isn't used anymore - Update to the faster checkout v2 --- .github/workflows/main.yml | 6 ++---- .github/workflows/release.yml | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 486fded..274f9c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,11 +13,9 @@ jobs: test: name: default runs-on: windows-latest - strategy: - fail-fast: false steps: - name: Check out source code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Download Internet run: npm install - name: Enable Developer Command Prompt @@ -32,6 +30,6 @@ jobs: runs-on: windows-latest steps: - name: Check out source code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - run: npm install - run: npm audit --audit-level=moderate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03e739d..e9c853f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,13 +11,11 @@ jobs: test: name: release runs-on: windows-latest - strategy: - fail-fast: false steps: - name: Setup Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1 - name: Check out source code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Compile and run some C code shell: cmd run: | @@ -28,5 +26,5 @@ jobs: runs-on: windows-latest steps: - name: Check out source code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - run: npm audit --audit-level=moderate From 754fb4dc409b42a24910117c98f725a2ba63d21c Mon Sep 17 00:00:00 2001 From: Alexei Lozovsky Date: Sun, 7 Mar 2021 15:16:28 +0900 Subject: [PATCH 2/3] Detect and report vcvarsall.bat errors (#28) If the parameters passed to the script are incorrect -- for example, architecture is set to something the script does not understand -- then the script will print an error message *and* exit successfully without doing anything useful. Detect the error messages, forward them to the user, and fail the action. Hopefully, the information from the script will be enough to pinpoint the source of the issue. For example, if the action is run with: arch: Win32 then the output will be Found with vswhere: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat Error: [ERROR:vcvarsall.bat] Invalid argument found : Win32 Error: Could not setup Developer Command Prompt: invalid parameters which is close enough. --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index fec3981..47d142f 100644 --- a/index.js +++ b/index.js @@ -104,6 +104,24 @@ function main() { core.debug(`Running: ${command}`) const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n') + // If vsvars.bat is given an incorrect command line, it will print out + // an error and *still* exit successfully. Parse out errors from output + // which don't look like environment variables, and fail if appropriate. + var failed = false + for (let line of environment) { + if (line.match(/^\[ERROR.*\]/)) { + failed = true + // Don't print this particular line which will be confusing in output. + if (line.match(/Error in script usage. The correct usage is:$/)) { + continue + } + core.error(line) + } + } + if (failed) { + throw new Error('invalid parameters') + } + for (let string of environment) { const [name, value] = string.split('=') for (let pattern of InterestingVariables) { From 6f493f9a67b5ae82dffe3cac554a0373262c47d3 Mon Sep 17 00:00:00 2001 From: Alexei Lozovsky Date: Sun, 7 Mar 2021 15:23:48 +0900 Subject: [PATCH 3/3] Architecture aliases: Win32 & Win64 (#29) By a public request, let's support aliases for architecture parameters. Treat "arch: Win32" as "x86" and "Win64" as "x64". Test this on CI just in case x86 breaks or something. --- .github/workflows/main.yml | 17 +++++++++++++++++ README.md | 4 +++- index.js | 13 ++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 274f9c3..b5cb384 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,3 +33,20 @@ jobs: uses: actions/checkout@v2 - run: npm install - run: npm audit --audit-level=moderate + alias-arch: + name: arch aliases + runs-on: windows-latest + steps: + - name: Check out source code + uses: actions/checkout@v2 + - name: Download Internet + run: npm install + - name: Enable Developer Command Prompt + uses: ./ + with: + arch: Win32 + - name: Compile and run some C code + shell: cmd + run: | + cl.exe hello.c + hello.exe diff --git a/README.md b/README.md index cd72800..71b3128 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ Supports Windows. Does nothing on Linux and macOS. ## Inputs - `arch` – target architecture - - native compilation: `x86`, `x64` (default), `amd64` (synonym for x64) + - native compilation: + - `x64` (default) or its synonyms: `amd64`, `win64` + - `x86` or its synonyms: `win32` - cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`, `amd64_x86`, `amd64_arm`, `amd64_arm64` - `sdk` – Windows SDK to use diff --git a/index.js b/index.js index 47d142f..a5a31a6 100644 --- a/index.js +++ b/index.js @@ -77,12 +77,23 @@ function main() { // Add standard location of "vswhere" to PATH, in case it's not there. process.env.PATH += path.delimiter + VSWHERE_PATH - const arch = core.getInput('arch') + var arch = core.getInput('arch') const sdk = core.getInput('sdk') const toolset = core.getInput('toolset') const uwp = core.getInput('uwp') const spectre = core.getInput('spectre') + // There are all sorts of way the architectures are called. In addition to + // values supported by Microsoft Visual C++, recognize some common aliases. + let arch_aliases = { + "win32": "x86", + "win64": "x64", + } + // Ignore case when matching as that's what humans expect. + if (arch.toLowerCase() in arch_aliases) { + arch = arch_aliases[arch.toLowerCase()] + } + // Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack: // Call the configuration batch file and then output *all* the environment variables.