Skip to content

minpack compiled with GFortran from MSYS2 on Windows #47

minpack compiled with GFortran from MSYS2 on Windows

minpack compiled with GFortran from MSYS2 on Windows #47

name: GFortran on Windows
run-name: minpack compiled with GFortran from MSYS2 on Windows
on:
push:
paths-ignore:
- "**/*.md"
- "doc/**"
pull_request:
paths-ignore:
- "**/*.md"
- "doc/**"
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
USE_DOWNLOAD: ['OFF']
CMAKE_BUILD_TYPE: ['Release', 'Debug']
LIBRARY_KIND: ['SHARED', 'STATIC']
MSYS2_CONFIG: [{ sys: mingw64, env: x86_64, fc: gfortran.exe }, { sys: ucrt64, env: ucrt-x86_64, fc: gfortran.exe }]
env:
# Fortran compiler + C compiler + GNU Make
MSYS2_PACKAGES_TO_INSTALL: "mingw-w64-${{ matrix.MSYS2_CONFIG.env }}-fc mingw-w64-${{ matrix.MSYS2_CONFIG.env }}-make"
steps:
- name: Restore MSYS2 (${{ matrix.MSYS2_CONFIG.env }}) packages
id: restore-msys2-packages
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: 'C:\msys64\tmp\*-${{ matrix.MSYS2_CONFIG.env }}-*'
key: minpack-builder-${{ matrix.MSYS2_CONFIG.env }}
# Here, instead of installing packages in the conventional way,
# we grab a list of mirrors for the environment (${{ matrix.MSYS2_CONFIG.env }}),
# then each package content is downloaded separetely from a different mirror.
# After all packages have been downloaded to disk, we install them.
#
# This workaround takes place to avoid a kind of "flooding" on the main MSYS2
# servers, due the amount of content we have to download in parallel builds.
- name: Download Fortran compiler + GNU Make
if: ${{ steps.restore-msys2-packages.outputs.cache-hit != 'true' }}
shell: pwsh
run: |
C:\msys64\usr\bin\bash.exe -lc "pacman -S ${{ env.MSYS2_PACKAGES_TO_INSTALL }} --print > /tmp/url.list"
C:\msys64\usr\bin\bash.exe -lc "for e in `$(cat /tmp/url.list); do echo `$(basename `$e); done" > $env:RUNNER_TEMP\packages.list
$raw_mirrors = New-Object 'System.Collections.Generic.List[string]';
Get-Content C:\msys64\etc\pacman.d\mirrorlist.${{ matrix.MSYS2_CONFIG.sys }} |
Where-Object { $_ -match "Server\s+=\s+https" } |
Foreach-Object {
$raw_mirrors.Add($_.Substring($_.IndexOf("https")));
}
$mirrors = $raw_mirrors.ToArray();
$ProgressPreference = 'SilentlyContinue';
[System.IO.File]::ReadAllLines((Get-Item $env:RUNNER_TEMP\packages.list).FullName) | ForEach-Object {
[System.Security.Cryptography.RandomNumberGenerator]::Shuffle[string]($mirrors);
$package = $_;
$retries = 0;
$success = $false;
$max_retries = $mirrors.Length;
$connection_timeout = 30;
$read_timeout = 1;
while ((-not $success) -and ($retries -lt $max_retries))
{
$mirror = $mirrors[$retries];
$uri = "${mirror}${package}";
if ($retries -gt 0)
{
C:\msys64\usr\bin\bash.exe -lc "echo -e '\e[32mRetry[\e[33m$retries\e[37m / \e[31m$max_retries\e[32m] >> \e[37mDownloading \e[35m$package\e[37m from \e[36m$uri\e[37m'";
}
else
{
Write-Host "Downloading $package from $uri";
}
try
{
Invoke-WebRequest -Uri $uri -MaximumRetryCount 0 -ConnectionTimeoutSeconds $connection_timeout -OperationTimeoutSeconds $read_timeout -OutFile C:\msys64\tmp\$package;
$success = $true;
}
catch
{
C:\msys64\usr\bin\bash.exe -lc "echo -e '\e[33mFailed to download $package from $mirror\e[37m'";
$retries++;
}
}
if (-not $success)
{
Write-Host "Failed to download $package";
exit 1;
}
}
- name: Save MSYS2 packages on cache
if: ${{ steps.restore-msys2-packages.outputs.cache-hit != 'true' }}
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: 'C:\msys64\tmp\*-${{ matrix.MSYS2_CONFIG.env }}-*'
key: minpack-builder-${{ matrix.MSYS2_CONFIG.env }}
- name: Install MSYS2 packages
run: |
C:\msys64\usr\bin\bash.exe -lc "pacman -U /tmp/*.pkg.tar.zst --noconfirm"
- name: Add MSYS2 tools to system environment PATH, and set FC environment variables
shell: pwsh
run: |
Add-Content $env:GITHUB_PATH "C:\msys64\${{ matrix.MSYS2_CONFIG.sys }}\bin"
Add-Content $env:GITHUB_ENV "FC=${{ matrix.MSYS2_CONFIG.fc }}"
- name: Restore assets
id: restore-assets
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: assets-cache
key: minpack-assets
enableCrossOsArchive: true
- name: Checkout assets
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
if: ${{ matrix.USE_DOWNLOAD=='OFF' && steps.restore-assets.outputs.cache-hit != 'true' }}
with:
ref: assets-ci-v1
path: assets
- name: Place minpack sources in the cache directory
if: ${{ matrix.USE_DOWNLOAD=='OFF' && steps.restore-assets.outputs.cache-hit != 'true' }}
shell: pwsh
run: |
New-Item "assets-cache" -ItemType Directory | Out-Null;
foreach ($current_file in "disclaimer", "chkder.f", "dogleg.f", "dpmpar.f", "enorm.f", "fdjac1.f", "fdjac2.f", "hybrd1.f", "hybrd.f", "hybrj1.f", "hybrj.f", "lmder1.f", "lmder.f", "lmdif1.f", "lmdif.f", "lmpar.f", "lmstr1.f", "lmstr.f", "qform.f", "qrfac.f", "qrsolv.f", "r1mpyq.f", "r1updt.f", "rwupdt.f")
{
$filePath = Join-Path -Path "assets" -ChildPath $current_file;
Copy-Item -Path $filePath -Destination "assets-cache";
}
- name: Save assets
if: ${{ matrix.USE_DOWNLOAD=='OFF' && steps.restore-assets.outputs.cache-hit != 'true' }}
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: assets-cache
key: minpack-assets
enableCrossOsArchive: true
- name: Checkout repository to minpack-builder directory
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
path: minpack-builder
- name: Place minpack sources in the correct directory for minpack-builder
if: ${{ matrix.USE_DOWNLOAD=='OFF' }}
shell: pwsh
run: |
foreach ($current_file in "disclaimer", "chkder.f", "dogleg.f", "dpmpar.f", "enorm.f", "fdjac1.f", "fdjac2.f", "hybrd1.f", "hybrd.f", "hybrj1.f", "hybrj.f", "lmder1.f", "lmder.f", "lmdif1.f", "lmdif.f", "lmpar.f", "lmstr1.f", "lmstr.f", "qform.f", "qrfac.f", "qrsolv.f", "r1mpyq.f", "r1updt.f", "rwupdt.f")
{
$filePath = Join-Path -Path "assets-cache" -ChildPath $current_file;
Copy-Item -Path $filePath -Destination "minpack-builder";
}
- name: Set environment variables to build and install directories
shell: pwsh
run: |
Add-Content $env:GITHUB_ENV "BUILDDIR=$env:RUNNER_TEMP\build"
Add-Content $env:GITHUB_ENV "INSTALLDIR=$env:RUNNER_TEMP\install-gfortran"
- name: Configure the build of minpack
shell: cmd
run: |
IF "${{ matrix.LIBRARY_KIND }}"=="SHARED" (
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF -DCMAKE_BUILD_TYPE=${{ matrix.CMAKE_BUILD_TYPE }} -DUSE_DOWNLOAD=${{ matrix.USE_DOWNLOAD }} --install-prefix %INSTALLDIR% -S minpack-builder -B %BUILDDIR%
) ELSE IF "${{ matrix.LIBRARY_KIND }}"=="STATIC" (
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DCMAKE_BUILD_TYPE=${{ matrix.CMAKE_BUILD_TYPE }} -DUSE_DOWNLOAD=${{ matrix.USE_DOWNLOAD }} --install-prefix %INSTALLDIR% -S minpack-builder -B %BUILDDIR%
) ELSE (
ECHO Unknown LIBRARY_KIND in the build matrix
EXIT /B 1
)
- name: Build minpack
shell: cmd
run: cmake --build %BUILDDIR% --config ${{ matrix.CMAKE_BUILD_TYPE }}
- name: Install minpack
shell: cmd
run: cmake --install %BUILDDIR% --config ${{ matrix.CMAKE_BUILD_TYPE }}