Skip to content

Path to bin directory of MinGW is not in the PATH environment variable. #6103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 10 tasks
TheVice opened this issue Aug 17, 2022 · 2 comments
Closed
2 of 10 tasks

Comments

@TheVice
Copy link

TheVice commented Aug 17, 2022

Description

Hello.

By not added path to bin directory of MinGW some of C++ application, that was created by this compiler, will not run at same build environment.
For example application where access to the data member of non constant string is present, see repros steps for full source sample.

It detected after updated to the 11.2 version, see #5729 and #5530. Previous environment (8.1.0) work fine - because in PATH environment variable exists paths to the directories with dll's, that have equal functional to the dll's exists at bin directory of MinGW:

  • C:\Strawberry\c\bin\libgcc_s_seh-1.dll
  • C:\Strawberry\c\bin\libstdc++-6.dll
  • C:\Strawberry\perl\bin\libgcc_s_seh-1.dll
  • C:\Strawberry\perl\bin\libstdc++-6.dll
  • C:\Program Files\Git\mingw64\bin\libgcc_s_seh-1.dll
  • C:\Program Files\Git\mingw64\bin\libstdc++-6.dll

Files from Strawberry sub directories is equal to each other. See #5459 why this directories in the PATH environment variable.

P.S.
This issue is continue the discussion that was started in the #5729 pull request, but also present the simple sample code. Addition suggestion can be found also in that pull request.

Platforms affected

  • Azure DevOps
  • GitHub Actions

Virtual environments affected

  • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • macOS 10.15
  • macOS 11
  • macOS 12
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

Virtual Environment
Environment: windows-2022
Version: 20220814.1
Included Software: https://github.com/actions/runner-images/blob/win22/20220814.1/images/win/Windows2022-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/win22%2F20220814.1

Is it regression?

Probably, no. Not at least when upgrade to the 11.2 was made. It just uncover previous shadow behavior that exists also for MinGW 8.1.0. So at choco side it should be check too.

Expected behavior

Executable that build by MinGW compiler should able to start at same build environment - by finding dll files with required functional.

Actual behavior

Executable unable to start according to not found dll files with required functional.
For example application exit code can be '-1073741511'.

Repro steps

  1. Create a C++ source file main.cpp with next code:
#include <string>
#include <cstdlib>

int main(int argc, char** argv)
{
	(void)argc;
	std::string argument(argv[0]);
	return 0 == *(argument.data() + argument.size()) ? EXIT_SUCCESS : EXIT_FAILURE;
}
  1. Create a CMakeLitst.txt with next code:
cmake_minimum_required(VERSION 3.20)
project(main)
add_executable(main "${CMAKE_SOURCE_DIR}/main.cpp")
  1. Attempt to build it with MinGW compile and run application that was build by it at current version of Windows Server 2022 environment. For example next yml code from .github/workflows/cmake.yml file can be used for it:
name: CMake

on: [push, pull_request]

jobs:
  build:
    name: >-
      ${{ github.ref_name }}
      ${{ matrix.os }}
      ${{ matrix.compiler }}
      ${{ matrix.optimized && 'release' || 'debug' }}
      ${{ matrix.patch && 'First patch apply' || 'no first patch' }}
      ${{ matrix.patch_2 && 'Second patch apply' || 'no second patch' }}

    strategy:
      fail-fast: false
      matrix:
        compiler: [mingw]
        os: [windows-2019, windows-2022]
        optimized: [true, false]
        target_platform: [x64]
        patch: [true, false]
        patch_2: [true, false]
        exclude:
        - os: windows-2019
          patch: true

        - os: windows-2019
          patch_2: true

        - patch: true
          patch_2: true

    env:
      CMAKE_BUILD_DIR: >-
        ${{ format(
            startsWith(matrix.os, 'windows') && '{0}\build' || '{0}/build',
            github.workspace) }}
      CMAKE_GENERATOR: ${{ 'mingw' == matrix.compiler && '-G "MinGW Makefiles"' || '' }}
      CMAKE_BUILD_TYPE: >-
        ${{ format(
            'msvc' == matrix.compiler && '' || '-DCMAKE_BUILD_TYPE={0}',
            (matrix.optimized && 'Release' || 'Debug')) }}
      CMAKE_CONFIG_TYPE: ${{ matrix.optimized && 'Release' || 'Debug' }}
      CMAKE_TARGET_PLATFORM: >-
        ${{ format(
            'msvc' == matrix.compiler && '-A {0}' || '',
            matrix.target_platform) }}
      EXECUTABLE_EXTENSION: ${{ startsWith(matrix.os, 'windows') && '.exe' || '' }}
      BINARY_PATH: >-
        ${{ format(
              ('msvc' == matrix.compiler && '{0}\build\{1}\') ||
              (startsWith(matrix.os, 'windows') && '{0}\build\' || '{0}/build/'),
            github.workspace,
            matrix.optimized && 'Release' || 'Debug') }}

    runs-on: ${{ matrix.os }}

    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Create project files
      run: >-
        cmake
        ${{ env.CMAKE_TARGET_PLATFORM }}
        ${{ env.CMAKE_GENERATOR }}
        ${{ env.CMAKE_BUILD_TYPE }}
        -S ${{ github.workspace }}
        -B ${{ env.CMAKE_BUILD_DIR }}

    - name: Build
      run: >-
        cmake
        --build ${{ env.CMAKE_BUILD_DIR }}
        --config ${{ env.CMAKE_CONFIG_TYPE }}

    - name: Add libraries to the folder with application that was made with MinGW
      if: ${{ 'mingw' == matrix.compiler && matrix.patch }}
      shell: pwsh
      run: |
        $path = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin\cpp.exe"
        if(Test-Path -Path $path)
        {
          $argument = "--version"
          $source = "$env:TEMP\1.txt"
          Start-Process -FilePath $path -ArgumentList $argument -NoNewWindow -Wait -RedirectStandardOutput $source
          $source = [System.IO.File]::ReadAllLines($source)[0]
          $argument = $source.LastIndexOf(" ")
          $argument++
          $source = $source.Substring($argument)
          $ver = [System.Version]::Parse($source)
          if([System.Version]::Parse("9.0") -le $ver)
          {
            Write-Warning -Message "Patch will be apply."
            $path = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin\libstdc++-6.dll"
            if(Test-Path -Path $path)
            {
              cp $path ${{ env.BINARY_PATH }}
            }
            else
            {
              Write-Warning -Message $path
            }
            $path = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin\libgcc_s_seh-1.dll"
            if(Test-Path -Path $path)
            {
              cp $path ${{ env.BINARY_PATH }}
            }
            else
            {
              Write-Warning -Message $path
            }
          }
          else
          {
            Write-Host "Nothing to do."
          }
        }

    - name: Run main application
      if: ${{ 'mingw' == matrix.compiler }}
      shell: pwsh
      run: |
        $app = "${{ env.BINARY_PATH }}main${{ env.EXECUTABLE_EXTENSION }}"
        $process = Start-Process -FilePath "$app" -NoNewWindow -Wait -PassThru
        if ($process.ExitCode -ne 0)
        {
          $path = "First attempt to start application failed. Exit code of application '$app' is not equal to the '0', instead it - '{0}'." -f $process.ExitCode
          Write-Warning $path
          if (${{ matrix.patch_2 }})
          {
            $path = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin;"
            $path += [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
            $env:Path = $path
          }
          $process = Start-Process -FilePath "$app" -NoNewWindow -Wait -PassThru
          if ($process.ExitCode -ne 0)
          {
            $app = "Second attempt failed. Exit code of application '$app' is not equal to the '0', instead it - '{0}'." -f $process.ExitCode
            throw (New-Object -TypeName System.Exception -ArgumentList $app)
          }
        }
        Write-Host "The application '$app' is success started."

I left in this build file comparing with Windows Server 2019 environment and two patches from user side for Windows Server 2022 environment.

Please not that second patch work only for Release configuration and will failed with Debug, so is weird - because first patch will copy required dll files from same place for both configuration.

Sample run of this code, that also located in this commit, can be found in this action run.

@al-cheb
Copy link
Contributor

al-cheb commented Aug 17, 2022

Hello @TheVice.
We don't have any plans to add mingw in the Path. If you need to update the PATH you could use - https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path

@al-cheb al-cheb closed this as completed Aug 17, 2022
@TheVice
Copy link
Author

TheVice commented Aug 17, 2022

@al-cheb thank you.
Work in same way like a per step setting of $env:Path at PowerShell script (patch 2 in first message of this issue) but required to set only once for multiple steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants