diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5cb384..f3d7f66 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,13 +18,42 @@ jobs: uses: actions/checkout@v2 - name: Download Internet run: npm install - - name: Enable Developer Command Prompt + - 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 diff --git a/README.md b/README.md index 0e6ec0c..a68b89e 100644 --- a/README.md +++ b/README.md @@ -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. 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 MIT, see [LICENSE](LICENSE). diff --git a/index.js b/index.js index c54c6c3..c87d7e0 100644 --- a/index.js +++ b/index.js @@ -55,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!') @@ -139,11 +154,18 @@ function main() { if (!string.includes('=')) { continue; } - const [name, new_value] = string.split('=') - const old_value = old_env_vars[name] + 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) } }