Compare commits

..

54 Commits

Author SHA1 Message Date
Mozi 460a772e4c Add note about the optional "vsversion" input (#77) 2024-03-31 00:13:11 +02:00
Oleksii Lozovskyi 1a76314737 Make npm audit happy (#75) 2024-01-01 06:17:50 +02:00
Amin Yahyaabadi c32fdcf92e Add a lib.js to export functions without running main (#70) 2024-01-01 06:12:51 +02:00
Quentin Dreyer 6357fb6ce3 Add BuildTools edition (#69) 2024-01-01 06:01:54 +02:00
Maj Soklič 1e07d4d99d Update NodeJS to v20 (#72) 2024-01-01 05:58:10 +02:00
Maj Soklič b8472a4c87 Update Checkout v2 -> v4 (#71) 2024-01-01 05:57:22 +02:00
Martin Thomson 7ab0add6fc differen[t] typo (#74) 2024-01-01 05:55:40 +02:00
Oleksii Lozovskyi a742a854f5 Bump minimatch to 3.1.2 (#64) 2023-02-25 01:23:19 +02:00
Simran bba535b3fe Bump @actions/core to 1.10.0 (#62) 2023-02-05 01:54:41 +02:00
Oleksii Lozovskyi 674ff850cb Have "Release" job test release/v1 branch (#61)
Instead of the v1 tag, that is. This makes it possible to push changes
to release/v1 branch and get CI test them without actually moving the
release tag which effectively publishes the updates to users.
2022-10-15 04:10:36 +03:00
Alexei Lozovsky f57be51dee Bump to 1.13.0-dev
Syncing the version because it ticked me off.
2022-10-15 10:03:44 +09:00
Mathias LANG 4734b1a57b Update the action to node 16 (#60)
Node 12 is deprecated and gives off a warning:
https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2022-10-15 03:42:27 +03:00
Oleksii Lozovskyi f6f64f2dd6 Remove "node_modules" (#57)
It's needed only on the release branch. No need to pollute development
branches with that. CI is able to "npm install" it back.
2022-08-29 13:50:25 +03:00
Oleksii Lozovskyi fe44a129df Bump @actions/core to 1.9.1 (#56)
Fixes CVE-2022-35954. Does not look like anything terriblity important
to me, but hey, audit is happy.
2022-08-28 10:38:29 +03:00
Amin Yahyaabadi 357f053bad Support specifying the visual studio version (#52)
* feat: support specifying the visual studio version

* fix: add upper bound for vswhere -version
2022-08-28 10:21:09 +03:00
Alexei Lozovsky 9f8ae839b0 Make npm audit happy (#50)
* Upgrade "ansi-regex" 5.0.0 => 5.0.1

And various other stuff because npm can't just upgrade one thing in the
lockfile, it need to upgrade everything it can. Move along, nothing
interesting to see here.

* Upgrade "eslint" 6 => 7

And also unpin the minor version. This resolves a bunch of "critical"
audit advisories from transitive dependencies.
2021-10-07 18:02:35 +03:00
Darrell Wright bb050e7771 Add support for VS2022 (#48)
Check $ProgramFiles too since that's where new stuff goes.
2021-10-07 17:45:10 +03:00
Amin Yahyaabadi f456b805b3 Export setupMSVCDevCmd to allow library usage (#47) 2021-09-16 03:11:51 +03:00
Alexei Lozovsky 74a501b087 Resolve audit warnings (#45)
* Update glob-parent to resolve CVE-2020-28469

* Run audit tasks on Ubuntu runners (they are cheaper)

* Audit only production dependencies

That is, something that can actually affect users of this action.
I don't really want to be bothered with yet another "prototype pollution"
or "denial of service" in transitive dependencies of eslint.

* Audit dev-dependencies for critical vulnerabilities

That said, still audit development dependencies for critical
vulnerabilities if they come along. Hopefully, this should be rare.
2021-06-09 12:25:52 +03:00
Alexei Lozovsky af5661e514 Add "x86-64" to the list of aliases too 2021-05-29 16:55:35 +03:00
Alexei Lozovsky e78ece9a2a Add "x86_64" and "x86-64" aliases for "x64" (#44)
By a popular request...
2021-05-29 16:43:24 +03:00
Mozi 985d494a0f Print the error message from conf scripts at once (#41)
Printing them line by line will generate a bunch of error messages on
the summary page of GitHub Actions workflow. I think it's a bit
annoying.

Note that this change will also affect the format of the final output
error message, but no information will be lost.
2021-05-26 16:32:04 +03:00
Mozi c5426bf30a Separate output content from CMD with form feed (#40)
The command "cls" will produce a '\f' (0x0c, page break or form feed)
character.
2021-05-26 14:53:04 +03:00
Mozi 100402d805 Make eslint work in CI (#42) 2021-05-26 14:51:43 +03:00
Alexei Lozovsky 08b850b4d0 Allow repeated invocation (#37)
* Workaround for repeated invocations

As noted in the comment, repeated invocations of this action might have
caused environment variables to overflow. This cute hack avoid this,
allowing to reconfigure environment.

* Note caveats in README

While this approach mostly works, I still have reservations so let's
leave some cautionary notes.

* Test repeated reconfiguration on CI

Well, let's build our "Hello, world!" four times, for four different
architectures, because why not.
2021-05-08 11:54:58 +03:00
Alexei Lozovsky ff72ae9ce3 Update usage examples (#36)
* Use newer actions/checkout@v2 in examples

That's the current version. Even our own build scripts use it.

* Correct actions syntax

By the way, it's been ages since steps get their own section...

* Provide an example with matrix

Finally, have some example to showcase input usage.

* Move inputs after examples

Since they are more useful, put copy-pastable examples first. Then you
can look at all available inputs, now that you know how to use them.
2021-05-08 11:14:35 +03:00
Alexei Lozovsky f5e8657374 Update npm format and resolve advisories (#35)
Just another day in JavaScriptLand: some "HIGH PRIORITY" vulnerability
has been fixed (CVE-2021-23337). Update our package-lock.json version
too because npm wants that.
2021-05-08 10:51:14 +03:00
Alexei Lozovsky dd5e2fa0a7 Autodetect variables to export (#32)
Instead of using a hardcoded list of variables to export, use a more
smart approach: first inspect the original environment, then look what
variables have changed as a result of "vcvarsall.bat" invocation, and
export all those new values.

Also, log the variables we export to be more debugging-friendly.
2021-03-20 10:49:55 +02:00
Alexei Lozovsky 2962e34b14 Describe conflicts with "shell: bash" (#31) 2021-03-19 14:26:39 +02:00
Frederik Seiffert 38903dd110 Export UCRTVersion and UniversalCRTSdkDir (#30)
These are required to build some components from the Swift toolchain.
2021-03-17 15:27:49 +02:00
Alexei Lozovsky 6f493f9a67 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.
2021-03-07 08:23:48 +02:00
Alexei Lozovsky 754fb4dc40 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.
2021-03-07 08:16:28 +02:00
Ewout ter Hoeven aa2e60900e 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
2021-02-01 14:01:31 +02:00
Alexei Lozovsky 87f7e3e8ba Async cleanup and improved logging (#21)
* Avoid unnecessary async-await

Since this is basically a linear script, we don't *really* need all this
async fluff, despite Node.js having a predisposition for async calls.
For one, it does not make much sense to immediately await an async call.
There is a synchronous version of exec -- execSync -- for that.

Suggested-by: Amin Yahyaabadi <aminyahyaabadi74@gmail.com>

* Make logging more verbose

Provide more insight in what paths are tried and where we have found
Visual Studio. Use info level so that it's visible without Actions
debugging being enabled. That way the users get to see a bit more
of the decision making process.
2020-12-13 08:03:03 +02:00
Alexei Lozovsky d9df5e2567 Add default vswhere location to PATH (#20)
Instead of checking "vswhere" in PATH and then in the default location
explicitly, just add the default locatio to PATH. That makes a single
attempt sufficient.
2020-12-13 07:49:04 +02:00
Alexei Lozovsky ccb28adcc4 Add node_modules on master with up-to-date deps
GitHub Actions tutorials suggest that you should not commit Node.js crap
onto your master branch, but it's not like this action has a lot of
dependencies, and not being able to test "ilammy/msvc-dev-cmd@master" is
so annoying... Therefore, do

    npm install --only production

and commit the results.
2020-12-11 20:05:07 +09:00
Serge Camille 3c1ec87255 Add VCINSTALLDIR to list of exported variables (#23)
This should allow windeployqt to pick up the exported environment variable.
2020-12-11 14:27:22 +09:00
Nicolas Jarnoux 75fbadd7d3 Check default vswhere location too (#19)
On some self-hosted runners "vswhere" is not available in the PATH.
Add another check in the findWithVswhere() function. It checks the
default installation of vswhere as stated by Microsoft, just in case
it is there but just not in the PATH.

Furthermore, the check refers to non-existent method core.warn()
instead of core.warning(). Use the correct method for reporting.
2020-10-18 13:38:45 +03:00
Alexei Lozovsky 840499b504 Avoid slow "vswhere" calls (#14)
Recently added Visual Studio location with "vswhere" seems to be very
slow when using "-find" with path patterns. As in, 5 minutes slow.

vswhere does not provide much insight into why this happens, but I guess
that's because filesystem operations (and search in particular) are not
very fast on Windows.

Improve the search performance by combining vswhere with probing. Use
vswhere to locate the installation root, and then probe around for the
batch script we need.

Also, don't use vswhere for Visual Studio 2015 as it does not seem to
work. Rely only on probing here.

And also, add some debug logs so that it's possible to track which path
has been used, if you're interested in it.
2020-10-03 17:51:55 +03:00
dependabot[bot] ecded17017 Bump @actions/core from 1.2.2 to 1.2.6 (#13)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.2 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-01 22:32:34 +03:00
Amin Yahyaabadi 4b3ec49c71 Use vswhere to find vcvarsall.bat (#11)
The Windows images provided by GitHub have a native program called
"vswhere", which can be used to find vcvarsall.bat.

* use vswhere to find vcvarsall
* don't require child_process twice
* use vswhere to find the 2015 bat file
* refactor findWithVswhere
* move finding vcbuildtools using vswhere upward
* print error of vswhere
2020-09-23 13:20:24 +03:00
dependabot[bot] 8a8bb270fb Bump lodash from 4.17.15 to 4.17.19 (#10)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-18 16:03:34 +03:00
Alexei Lozovsky be0a358ece Look for vcbuildtools.bat of VS 2015 as well (#9)
"Visual C++" has its build tool batch files in a different place.
Let's look there as well if we have not found 2017 or 2019 stuff.

Thanks to ReactOS project for figuring this out.

Co-authored-by: Victor Perevertkin <victor.perevertkin@reactos.org>
2020-06-14 20:55:01 +03:00
Oleh Prypin 5a6b51d5ac Refactor to not use the helper script (#6)
Choose vcvarsall.bat within JS code, call CMD directly with a command instead of writing a temporary file.
2020-05-09 21:24:12 +03:00
ilammy 9269bb4baf Bump transitive dependency versions
Resolve CVE-2020-7598 in minimis -- one of our transitive dependencies.
2020-04-30 21:23:23 +03:00
Nicolas Jarnoux ef0a58bd96 Enable other editions of msvc (#4)
I'll probably use self hosted runners in a project and the Community
version of Visual Studio will be installed on those. This enables the
script to check for Community and Professional editions in addition
to the Entreprise one offered by GitHub.

The modification generates a kinda search map ordered by version then
by edition. It generates the batch script that runs vcvarsall.bat
on the fly given that search map.
2020-04-26 23:54:04 +03:00
ilammy 52e66840de Prepare for next release 2020-03-19 09:03:19 +02:00
ilammy ddf4cb029f Fail audit on moderate and above vulnerabilities
Set the threshold to "moderate" and above. Currently msvc-dev-cmd has
an issue in transitive dev-dependency "minimist" [1] via somewhat long
chain of dependencies:

  - eslint > file-entry-cache > flat-cache > write > mkdirp > minimist
  - eslint > mkdirp > minimist

In order for this to be resolved all these packages need to do something
about their pinned versions. I don't want to sit there with a red build
because of some possible low-severity prototype pollution in dev
dependency. Anything higher -- okay, I'll look at at, and apply a fix
if necessary. (Maybe we should not audit dev dependencies at all...)

This particular vulnerability can be exploited by an attacker who can
submit a pull request and do "something bad"™ to Actions runners
executing jobs for this repository. However, since it's a dev
dependency, nothing will happen to our users. So we can safely ignore
this advisory.

[1]: https://npmjs.com/advisories/1179
2020-03-19 08:41:04 +02:00
ilammy 26cb400781 Run "npm audit" for release branch too
I'd like to be notified about weird vulnerabilities in JavaScript
libraries for the release branch as well. It's double important
since the release branch ships particular pinned version of *all*
dependencies.
2020-03-19 08:34:02 +02:00
Sean Kelly 075328686b Add VisualStudioVersion variable to exports (#3)
This variable seems to be necessary for some build tools like colcon:

https://colcon.readthedocs.io/en/released/
2020-03-19 08:24:49 +02:00
ilammy e6cca73138 Refresh dependencies
"npm audit" started whining about moderate denial of service
vulnerability in a dependency of dependency of dependency
(eslint > espree > acorn). This is not really serious because
we use "eslint" only for development. However, red builds are not good
so bump the pinned version in package.lock. (Released versions are not
affected because they do not include eslint.)
2020-03-12 12:54:03 +02:00
ilammy aa189b6b13 Refresh dependencies
It's not like we need any new features, but let's bump the versions
because we are in JavaScript land.

Also, run "npm audit" regularly, just in case a serious vulnerability
is discovered.
2020-02-12 00:19:19 +02:00
ilammy 164e882247 Integration test for release version
Make sure that the released version is also fine. Run this test every
time a push is made into the release branch as well as on schedule.
2020-02-12 00:00:24 +02:00
ilammy a71277ef87 Use cmd.exe as shell
It works well and we don't need PowerShell which has weird notion of
default executable search path.
2020-02-12 00:00:24 +02:00
9 changed files with 2156 additions and 617 deletions
-11
View File
@@ -1,11 +0,0 @@
name: Python package
on: [push]
jobs:
build:
runs-on: "windows-latest"
strategy:
matrix:
python-version:
- "2.7"
steps:
- uses: ilammy/msvc-dev-cmd@v1
+58 -11
View File
@@ -6,7 +6,6 @@ on:
branches: branches:
- master - master
- release/* - release/*
- wip/debugging
schedule: schedule:
- cron: '0 6 * * *' - cron: '0 6 * * *'
@@ -14,22 +13,70 @@ jobs:
test: test:
name: default name: default
runs-on: windows-latest runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
steps: steps:
- name: Check out source code - name: Check out source code
uses: actions/checkout@v1 uses: actions/checkout@v4
- name: Download Internet
run: npm install
- name: Run eslint
run: npm run lint
- name: Enable Developer Command Prompt (amd64)
uses: ./
with:
arch: amd64
- name: Compile and run some C code (amd64)
shell: cmd
run: |
cl.exe hello.c
hello.exe
- name: Enable Developer Command Prompt (amd64_x86)
uses: ./
with:
arch: amd64_x86
- name: Compile and run some C code (x86)
shell: cmd
run: |
cl.exe hello.c
hello.exe
- name: Enable Developer Command Prompt (amd64_arm)
uses: ./
with:
arch: amd64_arm
- name: Compile some C code (arm)
shell: cmd
run: |
cl.exe hello.c
dumpbin /headers hello.exe
- name: Enable Developer Command Prompt (amd64_arm64)
uses: ./
with:
arch: amd64_arm64
- name: Compile some C code (arm64)
shell: cmd
run: |
cl.exe hello.c
dumpbin /headers hello.exe
audit:
name: npm audit
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- run: npm install
- run: npm audit --audit-level=moderate --production
- run: npm audit --audit-level=critical
alias-arch:
name: arch aliases
runs-on: windows-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Download Internet - name: Download Internet
run: npm install run: npm install
- name: Enable Developer Command Prompt - name: Enable Developer Command Prompt
uses: ./ uses: ./
with:
arch: Win32
- name: Compile and run some C code - name: Compile and run some C code
shell: cmd shell: cmd
run: | run: |
+10 -12
View File
@@ -4,7 +4,6 @@ on:
push: push:
branches: branches:
- release/* - release/*
- wip/debugging
schedule: schedule:
- cron: '0 6 * * *' - cron: '0 6 * * *'
@@ -12,22 +11,21 @@ jobs:
test: test:
name: release name: release
runs-on: windows-latest runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
steps: steps:
- name: Setup Developer Command Prompt - name: Setup Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1 uses: ilammy/msvc-dev-cmd@release/v1
- name: Check out source code - name: Check out source code
uses: actions/checkout@v1 uses: actions/checkout@v4
- name: Compile and run some C code - name: Compile and run some C code
shell: cmd shell: cmd
run: | run: |
cl.exe hello.c cl.exe hello.c
hello.exe hello.exe
audit:
name: npm audit
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- run: npm audit --audit-level=moderate --production
- run: npm audit --audit-level=critical
+102 -12
View File
@@ -8,12 +8,57 @@ This sets up the environment for compiling C/C++ code from command line.
Supports Windows. Does nothing on Linux and macOS. Supports Windows. Does nothing on Linux and macOS.
## Example usage
Basic usage for default compilation settings is like this:
```yaml
jobs:
test:
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- name: Build something requiring CL.EXE
run: |
cmake -G "NMake Makefiles" .
nmake
# ...
```
If you want something non-default,
like using a specific version of Visual Studio,
or cross-compling for a different target,
you will need to configure those settings via inputs:
```yaml
jobs:
test:
# Run a job for each of the specified target architectures:
strategy:
matrix:
arch:
- amd64
- amd64_x86
- amd64_arm64
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- name: Build something requiring CL.EXE
run: |
cmake -G "NMake Makefiles" .
nmake
# ...
```
## Inputs ## Inputs
- `arch` target architecture - `arch` target architecture
- native compilation: `x86`, `x64` (default), `amd64` (synonym for x64) - native compilation:
- cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`, - `x64` (default) or its synonyms: `amd64`, `win64`, `x86_64`, `x86-64`
`amd64_x86`, `amd64_arm`, `amd64_arm64` - `x86` or its synonyms: `win32`
- cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`, `amd64_x86`, `amd64_arm`, `amd64_arm64`
- `sdk` Windows SDK to use - `sdk` Windows SDK to use
- do not specify to use the default SDK - do not specify to use the default SDK
- or specify full Windows 10 SDK number (e.g, `10.0.10240.0`) - or specify full Windows 10 SDK number (e.g, `10.0.10240.0`)
@@ -25,21 +70,66 @@ Supports Windows. Does nothing on Linux and macOS.
- `14.XX.YYYYY` for a specific full version number (e.g, `14.11.25503`) - `14.XX.YYYYY` for a specific full version number (e.g, `14.11.25503`)
- `uwp` set `true` to build for Universal Windows Platform (i.e., for Windows Store) - `uwp` set `true` to build for Universal Windows Platform (i.e., for Windows Store)
- `spectre` set `true` to use Visual Studio libraries with [Spectre](https://meltdownattack.com) mitigations - `spectre` set `true` to use Visual Studio libraries with [Spectre](https://meltdownattack.com) mitigations
- `vsversion` the Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019"); omit this input to select the latest version of Visual Studio. On [GitHub-hosted runners](https://docs.github.com/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners), this input is not required because there is only one Visual Studio in the environment.
## Example usage ## Caveats
### Name conflicts with `shell: bash`
Using `shell: bash` in Actions may shadow some of the paths added by MSVC.
In particular, `link.exe` (Microsoft C linker) is prone to be shadowed by `/usr/bin/link` (GNU filesystem link tool).
Unfortunately, this happens because GitHub Actions unconditionally *prepend* GNU paths when `shell: bash` is used,
on top of any paths set by `msvc-dev-cmd`, every time at the start of each new step.
Hence, there aren't many non-destructive options here.
If you experience compilation errors where `link` complains about unreasonable command-line arguments,
“extra operand *something-something* that's probably it.
Recommended workaround is to remove `/usr/bin/link` if that interferes with your builds.
If this is not acceptable, please file an issue, then we'll figure out something better.
### Reconfiguration
You can invoke `ilammy/msvc-dev-cmd` multiple times during your jobs with different inputs
to reconfigure the environment for building with different settings
(e.g., to target multiple architectures).
```yaml ```yaml
jobs: jobs:
test: release:
- uses: actions/checkout@v1 steps:
- uses: ilammy/msvc-dev-cmd@v1 # ...
- name: Build something requiring CL.EXE - name: Configure build for amd64
run: | uses: ilammy/msvc-dev-cmd@v1
cmake -G "NMake Makefiles" . with:
nmake arch: amd64
# ...
- run: build # (for amd64)
- name: Configure build for x86
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64_x86
- run: build # (for x86)
- name: Configure build for ARM64
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64_arm64
- run: build # (for ARM64)
# ...
``` ```
This mostly works but it's not really recommended
since Developer Command Prompt was not meant for recursive reconfiguration.
That said, if it does not work for you, please file an issue.
Consider using [`strategy.matrix`](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix)
to execute different build configuration in parallel, independent environments.
## License ## License
MIT, see [LICENSE](LICENSE). MIT, see [LICENSE](LICENSE).
+3 -1
View File
@@ -12,8 +12,10 @@ inputs:
description: VC++ compiler toolset version description: VC++ compiler toolset version
uwp: uwp:
description: Build for Universal Windows Platform description: Build for Universal Windows Platform
vsversion:
description: The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
runs: runs:
using: node12 using: node20
main: index.js main: index.js
branding: branding:
icon: terminal icon: terminal
+11 -91
View File
@@ -1,100 +1,20 @@
const { setupMSVCDevCmd } = require('./lib')
const core = require('@actions/core') const core = require('@actions/core')
const execFile = require('util').promisify(require('child_process').execFile)
const fs = require('fs').promises
const os = require('os')
const path = require('path')
const process = require('process')
const MSVS_2017 = '%ProgramFiles(x86)%\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Auxiliary\\Build' function main() {
const MSVS_2019 = '%ProgramFiles(x86)%\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build' var arch = core.getInput('arch')
const InterestingVariables = [
'INCLUDE',
'LIB',
'LIBPATH',
'Path',
'Platform',
/^VCTools/,
/^VSCMD_/,
/^WindowsSDK/i,
]
async function main() {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
return
}
const arch = core.getInput('arch')
const sdk = core.getInput('sdk') const sdk = core.getInput('sdk')
const toolset = core.getInput('toolset') const toolset = core.getInput('toolset')
const uwp = core.getInput('uwp') const uwp = core.getInput('uwp')
const spectre = core.getInput('spectre') const spectre = core.getInput('spectre')
const vsversion = core.getInput('vsversion')
// Due to the way Microsoft Visual C++ is configured, we have to resort to the following hack: setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion)
// write a helper batch file which calls the configuration batch file and then outputs the
// configured environment variables, which we then pass to GitHub Actions.
const helper = path.join(os.homedir(), 'msvc-dev-cmd.bat')
var args = [arch]
if (uwp == 'true') {
args.push('uwp')
}
if (sdk) {
args.push(sdk)
}
if (toolset) {
args.push(`-vcvars_ver=${toolset}`)
}
if (spectre == 'true') {
args.push('-vcvars_spectre_libs=spectre')
}
core.debug(`Arguments: ${args.join(' ')}`)
core.debug(`Writing helper file: ${helper}`)
await fs.writeFile(helper, `
@IF EXIST "${MSVS_2017}\\vcvarsall.bat" GOTO :2017
@IF EXIST "${MSVS_2019}\\vcvarsall.bat" GOTO :2019
@ECHO "Microsoft Visual Studio not found"
@EXIT 1
:2017
@CALL "${MSVS_2017}\\vcvarsall.bat" ${args.join(' ')}
@GOTO ENV
:2019
@CALL "${MSVS_2019}\\vcvarsall.bat" ${args.join(' ')}
@GOTO ENV
:ENV
@IF ERRORLEVEL 1 EXIT
@SET
`)
var environment
try {
core.debug('Executing helper')
const { stdout } = await execFile('cmd.exe', ['/q', '/c', helper])
environment = stdout.split('\r\n')
}
catch (error) {
core.debug(`Helper failed: ${error.message}`)
throw error
}
finally {
core.debug('Removing helper')
await fs.unlink(helper)
}
for (let string of environment) {
const [name, value] = string.split('=')
for (let pattern of InterestingVariables) {
if (name.match(pattern)) {
core.exportVariable(name, value)
break
}
}
}
core.info(`Configured Developer Command Prompt`)
} }
main().catch(() => core.setFailed('Could not setup Developer Command Prompt')) try {
main()
}
catch (e) {
core.setFailed('Could not setup Developer Command Prompt: ' + e.message)
}
+225
View File
@@ -0,0 +1,225 @@
const core = require('@actions/core')
const child_process = require('child_process')
const fs = require('fs')
const path = require('path')
const process = require('process')
const PROGRAM_FILES_X86 = process.env['ProgramFiles(x86)']
const PROGRAM_FILES = [process.env['ProgramFiles(x86)'], process.env['ProgramFiles']]
const EDITIONS = ['Enterprise', 'Professional', 'Community', 'BuildTools']
const YEARS = ['2022', '2019', '2017']
const VsYearVersion = {
'2022': '17.0',
'2019': '16.0',
'2017': '15.0',
'2015': '14.0',
'2013': '12.0',
}
function vsversion_to_versionnumber(vsversion) {
if (Object.values(VsYearVersion).includes(vsversion)) {
return vsversion
} else {
if (vsversion in VsYearVersion) {
return VsYearVersion[vsversion]
}
}
return vsversion
}
exports.vsversion_to_versionnumber = vsversion_to_versionnumber
function vsversion_to_year(vsversion) {
if (Object.keys(VsYearVersion).includes(vsversion)) {
return vsversion
} else {
for (const [year, ver] of Object.entries(VsYearVersion)) {
if (ver === vsversion) {
return year
}
}
}
return vsversion
}
exports.vsversion_to_year = vsversion_to_year
const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`
function findWithVswhere(pattern, version_pattern) {
try {
let installationPath = child_process.execSync(`vswhere -products * ${version_pattern} -prerelease -property installationPath`).toString().trim()
return installationPath + '\\' + pattern
} catch (e) {
core.warning(`vswhere failed: ${e}`)
}
return null
}
exports.findWithVswhere = findWithVswhere
function findVcvarsall(vsversion) {
const vsversion_number = vsversion_to_versionnumber(vsversion)
let version_pattern
if (vsversion_number) {
const upper_bound = vsversion_number.split('.')[0] + '.9'
version_pattern = `-version "${vsversion_number},${upper_bound}"`
} else {
version_pattern = "-latest"
}
// If vswhere is available, ask it about the location of the latest Visual Studio.
let path = findWithVswhere('VC\\Auxiliary\\Build\\vcvarsall.bat', version_pattern)
if (path && fs.existsSync(path)) {
core.info(`Found with vswhere: ${path}`)
return path
}
core.info("Not found with vswhere")
// If that does not work, try the standard installation locations,
// starting with the latest and moving to the oldest.
const years = vsversion ? [vsversion_to_year(vsversion)] : YEARS
for (const prog_files of PROGRAM_FILES) {
for (const ver of years) {
for (const ed of EDITIONS) {
path = `${prog_files}\\Microsoft Visual Studio\\${ver}\\${ed}\\VC\\Auxiliary\\Build\\vcvarsall.bat`
core.info(`Trying standard location: ${path}`)
if (fs.existsSync(path)) {
core.info(`Found standard location: ${path}`)
return path
}
}
}
}
core.info("Not found in standard locations")
// Special case for Visual Studio 2015 (and maybe earlier), try it out too.
path = `${PROGRAM_FILES_X86}\\Microsoft Visual C++ Build Tools\\vcbuildtools.bat`
if (fs.existsSync(path)) {
core.info(`Found VS 2015: ${path}`)
return path
}
core.info(`Not found in VS 2015 location: ${path}`)
throw new Error('Microsoft Visual Studio not found')
}
exports.findVcvarsall = findVcvarsall
function isPathVariable(name) {
const pathLikeVariables = ['PATH', 'INCLUDE', 'LIB', 'LIBPATH']
return pathLikeVariables.indexOf(name.toUpperCase()) != -1
}
function filterPathValue(path) {
let paths = path.split(';')
// Remove duplicates by keeping the first occurance and preserving order.
// This keeps path shadowing working as intended.
function unique(value, index, self) {
return self.indexOf(value) === index
}
return paths.filter(unique).join(';')
}
/** See https://github.com/ilammy/msvc-dev-cmd#inputs */
function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion) {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
return
}
// Add standard location of "vswhere" to PATH, in case it's not there.
process.env.PATH += path.delimiter + VSWHERE_PATH
// 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",
"x86_64": "x64",
"x86-64": "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.
var args = [arch]
if (uwp == 'true') {
args.push('uwp')
}
if (sdk) {
args.push(sdk)
}
if (toolset) {
args.push(`-vcvars_ver=${toolset}`)
}
if (spectre == 'true') {
args.push('-vcvars_spectre_libs=spectre')
}
const vcvars = `"${findVcvarsall(vsversion)}" ${args.join(' ')}`
core.debug(`vcvars command-line: ${vcvars}`)
const cmd_output_string = child_process.execSync(`set && cls && ${vcvars} && cls && set`, {shell: "cmd"}).toString()
const cmd_output_parts = cmd_output_string.split('\f')
const old_environment = cmd_output_parts[0].split('\r\n')
const vcvars_output = cmd_output_parts[1].split('\r\n')
const new_environment = cmd_output_parts[2].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.
const error_messages = vcvars_output.filter((line) => {
if (line.match(/^\[ERROR.*\]/)) {
// Don't print this particular line which will be confusing in output.
if (!line.match(/Error in script usage. The correct usage is:$/)) {
return true
}
}
return false
})
if (error_messages.length > 0) {
throw new Error('invalid parameters' + '\r\n' + error_messages.join('\r\n'))
}
// Convert old environment lines into a dictionary for easier lookup.
let old_env_vars = {}
for (let string of old_environment) {
const [name, value] = string.split('=')
old_env_vars[name] = value
}
// Now look at the new environment and export everything that changed.
// These are the variables set by vsvars.bat. Also export everything
// that was not there during the first sweep: those are new variables.
core.startGroup('Environment variables')
for (let string of new_environment) {
// vsvars.bat likes to print some fluff at the beginning.
// Skip lines that don't look like environment variables.
if (!string.includes('=')) {
continue;
}
let [name, new_value] = string.split('=')
let old_value = old_env_vars[name]
// For new variables "old_value === undefined".
if (new_value !== old_value) {
core.info(`Setting ${name}`)
// Special case for a bunch of PATH-like variables: vcvarsall.bat
// just prepends its stuff without checking if its already there.
// This makes repeated invocations of this action fail after some
// point, when the environment variable overflows. Avoid that.
if (isPathVariable(name)) {
new_value = filterPathValue(new_value)
}
core.exportVariable(name, new_value)
}
}
core.endGroup()
core.info(`Configured Developer Command Prompt`)
}
exports.setupMSVCDevCmd = setupMSVCDevCmd
+1743 -474
View File
File diff suppressed because it is too large Load Diff
+4 -5
View File
@@ -1,11 +1,10 @@
{ {
"name": "msvc-dev-cmd", "name": "msvc-dev-cmd",
"version": "1.0.0", "version": "1.13.0-dev",
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++", "description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"lint": "eslint index.js", "lint": "eslint index.js"
"test": "eslint index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -28,9 +27,9 @@
}, },
"homepage": "https://github.com/ilammy/msvc-dev-cmd#readme", "homepage": "https://github.com/ilammy/msvc-dev-cmd#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.1.1" "@actions/core": "^1.10.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^6.5.0" "eslint": "^7"
} }
} }