Compare commits

..

19 Commits

Author SHA1 Message Date
Alexei Lozovsky 7defe92547 msvc-dev-cmd v1.9.0 2021-05-29 22:45:09 +09: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
Alexei Lozovsky 62f16bb530 msvc-dev-cmv v1.8.1
Also updating and adding whatever the new version of npm wants to be
updated and added in its package files. This should not affect the
behavior of the action.
2021-05-26 22:40:20 +09: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 5611a7cba9 msvc-dev-cmd v1.8.0 2021-05-08 18:02:11 +09: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 18f5f2cef4 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.

(cherry picked from commit f5e8657374)

I'm doing this to shut GitHub Actions CI. It might be a good idea to
make a minor release with this as well. We'll see. But CI is going to
use the "release/v1" branch code and "npm audit" will complain.
2021-05-08 16:56:37 +09: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
Alexei Lozovsky d39d8f7626 msvc-dev-cmd v1.7.0 2021-03-17 22:30:38 +09: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 24b406e1cf msvc-dev-cmd v1.6.0 2021-03-07 15:29:22 +09: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
7 changed files with 1586 additions and 202 deletions
+52 -6
View File
@@ -13,25 +13,71 @@ 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
- name: Run eslint
run: npm run lint
- name: Enable Developer Command Prompt (amd64)
uses: ./
- name: Compile and run some C code
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: 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
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
+2 -4
View File
@@ -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
+100 -11
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.
## Example usage
Basic usage for default compilation settings is like this:
```yaml
jobs:
test:
steps:
- uses: actions/checkout@v2
- 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 differen 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@v2
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- name: Build something requiring CL.EXE
run: |
cmake -G "NMake Makefiles" .
nmake
# ...
```
## Inputs
- `arch` target architecture
- native compilation: `x86`, `x64` (default), `amd64` (synonym for x64)
- cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`,
`amd64_x86`, `amd64_arm`, `amd64_arm64`
- native compilation:
- `x64` (default) or its synonyms: `amd64`, `win64`, `x86_64`
- `x86` or its synonyms: `win32`
- cross-compilation: `x86_amd64`, `x86_arm`, `x86_arm64`, `amd64_x86`, `amd64_arm`, `amd64_arm64`
- `sdk` Windows SDK to use
- do not specify to use the default SDK
- or specify full Windows 10 SDK number (e.g, `10.0.10240.0`)
@@ -26,20 +71,64 @@ Supports Windows. Does nothing on Linux and macOS.
- `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
## 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
jobs:
test:
- uses: actions/checkout@v1
- uses: ilammy/msvc-dev-cmd@v1
- name: Build something requiring CL.EXE
run: |
cmake -G "NMake Makefiles" .
nmake
release:
steps:
# ...
- name: Configure build for amd64
uses: ilammy/msvc-dev-cmd@v1
with:
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
MIT, see [LICENSE](LICENSE).
+84 -23
View File
@@ -11,19 +11,6 @@ const VERSIONS = ['2019', '2017']
const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`
const InterestingVariables = [
'INCLUDE',
'LIB',
'LIBPATH',
'VCINSTALLDIR',
'Path',
'Platform',
'VisualStudioVersion',
/^VCTools/,
/^VSCMD_/,
/^WindowsSDK/i,
]
function findWithVswhere(pattern) {
try {
let installationPath = child_process.execSync(`vswhere -products * -latest -prerelease -property installationPath`).toString().trim()
@@ -68,6 +55,21 @@ function findVcvarsall() {
throw new Error('Microsoft Visual Studio not found')
}
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(';')
}
function main() {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
@@ -77,12 +79,25 @@ 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",
"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.
@@ -100,19 +115,65 @@ function main() {
args.push('-vcvars_spectre_libs=spectre')
}
const command = `"${findVcvarsall()}" ${args.join(' ')} && set`
core.debug(`Running: ${command}`)
const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n')
const vcvars = `"${findVcvarsall()}" ${args.join(' ')}`
core.debug(`vcvars command-line: ${vcvars}`)
for (let string of environment) {
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('=')
for (let pattern of InterestingVariables) {
if (name.match(pattern)) {
core.exportVariable(name, value)
break
}
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`)
}
+13
View File
@@ -0,0 +1,13 @@
{
"name": "msvc-dev-cmd",
"version": "1.9.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"node_modules/@actions/core": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
}
}
}
+1332 -154
View File
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -1,11 +1,10 @@
{
"name": "msvc-dev-cmd",
"version": "1.5.0",
"version": "1.9.0",
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
"main": "index.js",
"scripts": {
"lint": "eslint index.js",
"test": "eslint index.js"
"lint": "eslint index.js"
},
"repository": {
"type": "git",