Skip to content

Conversation

m3dwards
Copy link
Contributor

@m3dwards m3dwards commented May 15, 2025

The windows job uses the external dependency ilammy/msvc-dev-cmd which runs javascript. We use this to put various tools on the path such as MSBuild.exe and mt.exe. We can remove this dependency and use vswhere.exe directly to find these tools and create a "Developer command prompt" as someone would on their dev machine.

While in this area of the code, this PR also runs some additional manifest checks on the windows binaries.

Fixes: #32508

@DrahtBot
Copy link
Contributor

DrahtBot commented May 15, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32513.

Reviews

See the guideline for information on the review process.

Type Reviewers
Stale ACK hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32672 (ci: update pwsh to use custom shell that fails-fast by m3dwards)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Tests label May 15, 2025
@fanquake fanquake requested a review from hebasto May 15, 2025 13:38
@hebasto
Copy link
Member

hebasto commented May 15, 2025

Concept ACK.

Thank you for taking this!

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2549a10, tested locally on Windows 11. Additionally tested in my personal repo with invalidated vcpkg binary cache.

@davidgumberg
Copy link
Contributor

It might be better to use a more general solution for setting up VS prompts, this would also work once #32396 is merged.

      - name: Set up VS Developer Prompt
        shell: pwsh
        run: |
          $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
          $installationPath = & 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' -latest -property installationPath
          if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
            & "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -no_logo && set" | foreach-object {
              $name, $value = $_ -split '=', 2
              echo "$name=$value" >> $env:GITHUB_ENV
            }
          }

(davidgumberg@83c53bf)

This snippet was mostly taken from this vswhere wiki article: https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt#using-powershell

@hebasto
Copy link
Member

hebasto commented May 16, 2025

It might be better to use a more general solution for setting up VS prompts, this would also work once #32396 is merged.

@m3dwards

Could you please rebase this PR on top of #32396?

@m3dwards m3dwards force-pushed the 250515-remove-js-ci branch from 449cb9e to dc403f0 Compare May 20, 2025 11:56
@m3dwards
Copy link
Contributor Author

Rebased and taken @davidgumberg's great suggestion.

@davidgumberg
Copy link
Contributor

This approach here should also be applied to replace the Find mt.exe tool step in the Windows, test cross-built job.

@m3dwards m3dwards force-pushed the 250515-remove-js-ci branch from 5bd3a34 to ff2e35f Compare May 24, 2025 12:02
@m3dwards
Copy link
Contributor Author

@hebasto @davidgumberg I believe all comments have been addressed?

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ff2e35f.

While touching this code, it seems reasonable to also address the other @davidgumberg's comment:

Might be nice to have a CI check like davidgumberg@1b98160 to prevent future regressions, but OK for a separate PR if out of scope.

@m3dwards
Copy link
Contributor Author

While touching this code, it seems reasonable to also address the other @davidgumberg's comment:

I don't mind adding that.

@hodlinator
Copy link
Contributor

I suspect checking for manifests will currently fail for bench_bitcoin.exe as it doesn't yet have a manifest. Not sure about other binaries. Wouldn't be against adding missing manifests unless it slows down the builds noticeably.

"MT_EXE=${sdk_dir}bin\${sdk_latest}\x64\mt.exe" >> $env:GITHUB_ENV
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installationPath = & $vswherePath -latest -property installationPath
if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry for the churn here)

I think we actually want to drop this if guard here and above, the CI job should fail right here if the path to vsdevcmd.bat breaks, so that the cause/fix is obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry, I'm reworking it to do more manifest checks anyway so changes at this point are fine.

Will look at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be addressed

@m3dwards m3dwards force-pushed the 250515-remove-js-ci branch from ff2e35f to a453e66 Compare May 30, 2025 17:38
@m3dwards
Copy link
Contributor Author

m3dwards commented Jun 2, 2025

While touching this code, it seems reasonable to also address the other @davidgumberg's comment:

Added

@bitcoin bitcoin deleted a comment from Dakota48423 Jun 2, 2025

Write-Host "Checking $exeName"
& mt.exe -nologo -inputresource:$_.FullName -validate_manifest
if ($LASTEXITCODE -ne 0) {
Copy link
Contributor

@davidgumberg davidgumberg Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, this if branch will never be reached since the CI script will exit if the line above has a non-zero exit code.

Copy link
Contributor Author

@m3dwards m3dwards Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default behaviour in powershell is to continue on error (unless it's a terminating error like throw). When calling a powershell cmdlet you can set $ErrorActionPreference = 'Stop' but being as this is a call to an external process I don't believe that approach works here, hence why checking the exit code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which now worries me about elsewhere we have used powershell, if it will exit like we think it should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default behaviour in powershell is to continue on error

Do we have that turned off for all of our CIs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't appear to be turned off on our CI and I think it should be.

In Powershell 7.4 and up there is now a setting PSNativeCommandUseErrorActionPreference which should make calling native commands respect the ErrorActionPreference so we should set both of those, globally if possible. I will look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wrong about powershell cmdlets: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference

Github sets ErrorActionPreference to stop but it doesn't appear that they set PSNativeCommandUseErrorActionPreference which is why calling native executables (like mt.exe) can still fail silently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default behaviour in powershell is to continue on error

Do we have that turned off for all of our CIs?

We did:

defaults:
run:
# Enforce fail-fast behavior for all platforms.
# See: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
shell: bash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hebasto but there are a few places where we use pwsh, which will still fail fast if using exclusively cmdlets but doesn't appear to fail when calling native executables.

Here is a commit to demonstrate it won't always failfast: 4bf1031

and the job run that didn't fail: https://github.com/m3dwards/bitcoin/actions/runs/15415032095/job/43375709475

Suggest we set PSNativeCommandUseErrorActionPreference to true everywhere we use pwsh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR enables failing fast for executables in pwsh:

#32672

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m3dwards and others added 3 commits June 3, 2025 14:17
We can use vswhere.exe directly to create a vs developer
prompt and so can remove this third party dependency.

Co-authored-by: David Gumberg <davidzgumberg@gmail.com>
This sets up a vs developer command prompt and should hopefully should
be more resilient to upstream changes

Co-authored-by: David Gumberg <davidzgumberg@gmail.com>
The other executables have manifests and these should be checked in
addition to bitcoind. Skipping fuzz.exe, bench_bitcoin.exe and
test_bitcoin-qt.exe as they do not have manifests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ci: remove third-party javascript usage from Windows CI
6 participants