mirror of
https://github.com/ilammy/msvc-dev-cmd.git
synced 2026-09-07 06:07:19 +08:00
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.
This commit is contained in:
@@ -18,13 +18,42 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Download Internet
|
- name: Download Internet
|
||||||
run: npm install
|
run: npm install
|
||||||
- name: Enable Developer Command Prompt
|
- name: Enable Developer Command Prompt (amd64)
|
||||||
uses: ./
|
uses: ./
|
||||||
- name: Compile and run some C code
|
with:
|
||||||
|
arch: amd64
|
||||||
|
- name: Compile and run some C code (amd64)
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: |
|
run: |
|
||||||
cl.exe hello.c
|
cl.exe hello.c
|
||||||
hello.exe
|
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:
|
audit:
|
||||||
name: npm audit
|
name: npm audit
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
|
|||||||
@@ -87,6 +87,48 @@ If you experience compilation errors where `link` complains about unreasonable c
|
|||||||
Recommended workaround is to remove `/usr/bin/link` if that interferes with your builds.
|
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.
|
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:
|
||||||
|
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
|
## License
|
||||||
|
|
||||||
MIT, see [LICENSE](LICENSE).
|
MIT, see [LICENSE](LICENSE).
|
||||||
|
|||||||
@@ -55,6 +55,21 @@ function findVcvarsall() {
|
|||||||
throw new Error('Microsoft Visual Studio not found')
|
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() {
|
function main() {
|
||||||
if (process.platform != 'win32') {
|
if (process.platform != 'win32') {
|
||||||
core.info('This is not a Windows virtual environment, bye!')
|
core.info('This is not a Windows virtual environment, bye!')
|
||||||
@@ -139,11 +154,18 @@ function main() {
|
|||||||
if (!string.includes('=')) {
|
if (!string.includes('=')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const [name, new_value] = string.split('=')
|
let [name, new_value] = string.split('=')
|
||||||
const old_value = old_env_vars[name]
|
let old_value = old_env_vars[name]
|
||||||
// For new variables "old_value === undefined".
|
// For new variables "old_value === undefined".
|
||||||
if (new_value !== old_value) {
|
if (new_value !== old_value) {
|
||||||
core.info(`Setting ${name}`)
|
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.exportVariable(name, new_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user