Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ on:
description: "Build and include QuantLib test suite"
type: boolean
default: true
run_tests:
description: "Run the QuantLib test suite after building"
type: boolean
default: false
create_release:
description: "Create a GitHub Release with the zip asset"
type: boolean
Expand All @@ -43,15 +47,18 @@ jobs:
- name: Build QuantLib DLL
shell: pwsh
run: |
$buildTestsFlag = if ("${{ inputs.build_tests }}" -eq "true") { "-BuildTests" } else { "" }
$buildTests = "${{ inputs.build_tests }}" -ne "false"
$runTests = "${{ inputs.run_tests }}" -eq "true"
$buildTestsFlag = if ($buildTests) { "-BuildTests" } else { "" }
$runTestsFlag = if ($runTests) { "-RunTests" } else { "" }
$cmd = "scripts/Build-QuantLibDLL.ps1" +
" -QuantLibVersion $env:QL_VERSION" +
" -BoostVersion $env:BOOST_VERSION" +
" -InstallDir ${{ runner.temp }}\quantlib-install" +
" -TempDir ${{ runner.temp }}\quantlib-build" +
" -PackageZip" +
" -ZipOutputDir ${{ github.workspace }}" +
" $buildTestsFlag"
" $buildTestsFlag $runTestsFlag"
Write-Host "Running: $cmd"
Invoke-Expression $cmd

Expand Down
52 changes: 47 additions & 5 deletions scripts/Build-QuantLibDLL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
.PARAMETER BuildTests
Also build the QuantLib test suite.

.PARAMETER RunTests
Run the QuantLib test suite after building. Implies -BuildTests.

.PARAMETER PackageZip
Create a distributable zip containing QuantLib DLL + headers + Boost headers.

Expand All @@ -59,12 +62,16 @@ param(
[string]$TempDir = (Join-Path (Split-Path $PSScriptRoot) "build"),
[int]$Jobs = 0,
[switch]$BuildTests,
[switch]$RunTests,
[switch]$PackageZip,
[string]$ZipOutputDir = "."
)

$ErrorActionPreference = "Stop"

# -RunTests implies -BuildTests
if ($RunTests) { $BuildTests = [switch]::new($true) }

$BoostVersionU = $BoostVersion -replace '\.', '_'
if ($Jobs -eq 0) {
$Jobs = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors
Expand Down Expand Up @@ -215,9 +222,13 @@ $ppContent = Get-Content $ppHeader -Raw
if (-not $ppContent.Contains('qldefines.hpp')) {
$ppContent = $ppContent -replace '(#define\s+primitivepolynomials_hpp)', "`$1`n`n#include <ql/qldefines.hpp>"
}
$ppContent = $ppContent.Replace(
'extern const long *const PrimitivePolynomials',
'extern QL_EXPORT const long *const PrimitivePolynomials')
if (-not $ppContent.Contains('QL_EXPORT')) {
# NOTE: The declaration uses multi-line "extern ... 'C' ... const long *const"
# so we must match just "const long *const PrimitivePolynomials" (not "extern const ...").
$ppContent = $ppContent.Replace(
'const long *const PrimitivePolynomials',
'QL_EXPORT const long *const PrimitivePolynomials')
}
[System.IO.File]::WriteAllText($ppHeader, $ppContent)

# ==========================================================================
Expand All @@ -236,7 +247,7 @@ $cmakeArgs = @(
"-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON"
'-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL'
"-DBoost_INCLUDE_DIR=$BoostIncludeDir"
"-DQL_BUILD_BENCHMARK=OFF"
"-DQL_INSTALL_BENCHMARK=OFF"
"-DQL_BUILD_EXAMPLES=OFF"
"-DQL_BUILD_TEST_SUITE=$( if ($BuildTests) { 'ON' } else { 'OFF' } )"
"-Wno-dev"
Expand Down Expand Up @@ -300,7 +311,38 @@ if (Test-Path "$InstallDir\bin") {
}

# ==========================================================================
# 6. Package zip (optional)
# 6. Run test suite (optional)
# ==========================================================================
if ($RunTests) {
Write-Host "==> Running QuantLib test suite"
$TestExePath = Get-ChildItem -Recurse "$QLBuildDir\test-suite" -Filter "quantlib-test-suite.exe" |
Where-Object { $_.Directory.Name -eq "Release" } | Select-Object -First 1
if (-not $TestExePath) {
throw "quantlib-test-suite.exe not found under $QLBuildDir\test-suite"
}
Write-Host " Executable: $($TestExePath.FullName)"

# Add the DLL directory to PATH so the test can find the QuantLib DLL
$DllDir = (Get-ChildItem -Recurse $QLBuildDir -Filter "QuantLib*.dll" |
Where-Object { $_.Directory.Name -eq "Release" } | Select-Object -First 1).DirectoryName
$env:PATH = "$DllDir;$env:PATH"
Write-Host " DLL directory added to PATH: $DllDir"

$testOutput = & $TestExePath.FullName 2>&1 | Out-String
$testExitCode = $LASTEXITCODE
Write-Host $testOutput

if ($testExitCode -ne 0) {
throw "quantlib-test-suite.exe exited with code $testExitCode (expected 0)"
}
if ($testOutput -notmatch '\*\*\* No errors detected') {
throw "Test suite output did not contain '*** No errors detected'"
}
Write-Host "==> Test suite PASSED (exit code 0, no errors detected)"
}

# ==========================================================================
# 7. Package zip (optional)
# ==========================================================================
if ($PackageZip) {
Write-Host "==> Packaging distribution zip"
Expand Down
Loading