Skip to content

Commit 330aff8

Browse files
Copilot0xrinegade
andcommitted
Fix Windows OpenSSL linking issues - use Win32OpenSSL distribution and improve configuration
Co-authored-by: 0xrinegade <[email protected]>
1 parent 168bc8c commit 330aff8

File tree

3 files changed

+195
-54
lines changed

3 files changed

+195
-54
lines changed

.github/workflows/build.yml

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,88 @@ jobs:
4444
if: runner.os == 'Windows'
4545
shell: powershell
4646
run: |
47-
# Install OpenSSL via chocolatey
48-
choco install openssl -y
47+
# Download and install Win32OpenSSL for better compatibility
48+
Write-Host "Downloading Win32OpenSSL..."
49+
$url = "https://slproweb.com/download/Win64OpenSSL-3_2_1.exe"
50+
$output = "$env:TEMP\Win64OpenSSL.exe"
4951
50-
# Add OpenSSL to PATH
51-
$env:Path += ";C:\Program Files\OpenSSL-Win64\bin"
52+
try {
53+
Invoke-WebRequest -Uri $url -OutFile $output -UseBasicParsing
54+
Write-Host "Installing Win32OpenSSL..."
55+
Start-Process -FilePath $output -ArgumentList "/SILENT", "/VERYSILENT", "/SP-", "/SUPPRESSMSGBOXES" -Wait
56+
Remove-Item $output -Force
57+
Write-Host "Win32OpenSSL installation completed"
58+
} catch {
59+
Write-Host "Win32OpenSSL download failed, falling back to chocolatey..."
60+
choco install openssl -y
61+
}
5262
53-
# Verify installation and directories exist
54-
if (Test-Path "C:\Program Files\OpenSSL-Win64\lib") {
55-
Write-Host "OpenSSL lib directory found"
56-
} else {
57-
Write-Host "OpenSSL lib directory not found, checking alternate locations..."
58-
if (Test-Path "C:\Program Files\OpenSSL\lib") {
59-
Write-Host "Found OpenSSL at C:\Program Files\OpenSSL\"
60-
echo "OPENSSL_DIR=C:\Program Files\OpenSSL" | Out-File -FilePath $env:GITHUB_ENV -Append
61-
echo "OPENSSL_LIB_DIR=C:\Program Files\OpenSSL\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
62-
echo "OPENSSL_INCLUDE_DIR=C:\Program Files\OpenSSL\include" | Out-File -FilePath $env:GITHUB_ENV -Append
63-
} else {
64-
Write-Host "OpenSSL installation failed or directories not found"
65-
exit 1
63+
# Define possible OpenSSL installation paths
64+
$possiblePaths = @(
65+
"C:\Program Files\OpenSSL-Win64",
66+
"C:\Program Files\OpenSSL",
67+
"C:\OpenSSL-Win64",
68+
"C:\OpenSSL"
69+
)
70+
71+
$opensslPath = $null
72+
foreach ($path in $possiblePaths) {
73+
if (Test-Path "$path\lib") {
74+
$opensslPath = $path
75+
Write-Host "Found OpenSSL at: $path"
76+
break
6677
}
6778
}
6879
69-
# Set environment variables for the standard location
70-
if (Test-Path "C:\Program Files\OpenSSL-Win64\lib") {
71-
echo "OPENSSL_DIR=C:\Program Files\OpenSSL-Win64" | Out-File -FilePath $env:GITHUB_ENV -Append
72-
echo "OPENSSL_LIB_DIR=C:\Program Files\OpenSSL-Win64\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
73-
echo "OPENSSL_INCLUDE_DIR=C:\Program Files\OpenSSL-Win64\include" | Out-File -FilePath $env:GITHUB_ENV -Append
80+
if (-not $opensslPath) {
81+
Write-Host "ERROR: OpenSSL installation not found in any expected location"
82+
Write-Host "Searched paths:"
83+
foreach ($path in $possiblePaths) {
84+
Write-Host " - $path"
85+
}
86+
exit 1
7487
}
7588
76-
# Also set OPENSSL_ROOT_DIR for compatibility
77-
if (Test-Path "C:\Program Files\OpenSSL-Win64") {
78-
echo "OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL-Win64" | Out-File -FilePath $env:GITHUB_ENV -Append
79-
} elseif (Test-Path "C:\Program Files\OpenSSL") {
80-
echo "OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL" | Out-File -FilePath $env:GITHUB_ENV -Append
89+
# Set environment variables for cargo and the linker
90+
echo "OPENSSL_DIR=$opensslPath" | Out-File -FilePath $env:GITHUB_ENV -Append
91+
echo "OPENSSL_LIB_DIR=$opensslPath\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
92+
echo "OPENSSL_INCLUDE_DIR=$opensslPath\include" | Out-File -FilePath $env:GITHUB_ENV -Append
93+
echo "OPENSSL_ROOT_DIR=$opensslPath" | Out-File -FilePath $env:GITHUB_ENV -Append
94+
95+
# Add OpenSSL bin directory to PATH for DLL resolution during linking
96+
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "Process")
97+
$newPath = "$opensslPath\bin;$currentPath"
98+
echo "PATH=$newPath" | Out-File -FilePath $env:GITHUB_ENV -Append
99+
100+
# Verify all required files exist
101+
$requiredFiles = @(
102+
"$opensslPath\lib\libssl.lib",
103+
"$opensslPath\lib\libcrypto.lib",
104+
"$opensslPath\bin\libssl-3-x64.dll",
105+
"$opensslPath\bin\libcrypto-3-x64.dll"
106+
)
107+
108+
$missingFiles = @()
109+
foreach ($file in $requiredFiles) {
110+
if (-not (Test-Path $file)) {
111+
$missingFiles += $file
112+
}
81113
}
114+
115+
if ($missingFiles.Count -gt 0) {
116+
Write-Host "WARNING: Some OpenSSL files are missing:"
117+
foreach ($file in $missingFiles) {
118+
Write-Host " - $file"
119+
}
120+
} else {
121+
Write-Host "All required OpenSSL files found"
122+
}
123+
124+
# Display environment for debugging
125+
Write-Host "OpenSSL configuration:"
126+
Write-Host " OPENSSL_DIR: $opensslPath"
127+
Write-Host " OPENSSL_LIB_DIR: $opensslPath\lib"
128+
Write-Host " OPENSSL_INCLUDE_DIR: $opensslPath\include"
82129
83130
- name: Install Perl dependencies for OpenSSL (Windows fallback)
84131
if: runner.os == 'Windows'
@@ -103,6 +150,28 @@ jobs:
103150
- name: Build
104151
timeout-minutes: 15
105152
run: |
153+
# On Windows, display OpenSSL environment for debugging
154+
if [ "${{ runner.os }}" = "Windows" ]; then
155+
echo "=== OpenSSL Environment Debug Info ==="
156+
echo "OPENSSL_DIR: $OPENSSL_DIR"
157+
echo "OPENSSL_LIB_DIR: $OPENSSL_LIB_DIR"
158+
echo "OPENSSL_INCLUDE_DIR: $OPENSSL_INCLUDE_DIR"
159+
echo "PATH (first 500 chars): ${PATH:0:500}"
160+
161+
# List OpenSSL library files if directory exists
162+
if [ -d "$OPENSSL_LIB_DIR" ]; then
163+
echo "OpenSSL lib directory contents:"
164+
ls -la "$OPENSSL_LIB_DIR" || true
165+
fi
166+
167+
# Check if OpenSSL DLLs are accessible
168+
if [ -d "$OPENSSL_DIR/bin" ]; then
169+
echo "OpenSSL bin directory contents:"
170+
ls -la "$OPENSSL_DIR/bin" || true
171+
fi
172+
echo "=== End OpenSSL Debug Info ==="
173+
fi
174+
106175
cargo build --release --target ${{ matrix.target }}
107176
108177
- name: Check for dependency drift

.github/workflows/release.yml

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,41 +50,88 @@ jobs:
5050
if: runner.os == 'Windows'
5151
shell: powershell
5252
run: |
53-
# Install OpenSSL via chocolatey
54-
choco install openssl -y
53+
# Download and install Win32OpenSSL for better compatibility
54+
Write-Host "Downloading Win32OpenSSL..."
55+
$url = "https://slproweb.com/download/Win64OpenSSL-3_2_1.exe"
56+
$output = "$env:TEMP\Win64OpenSSL.exe"
5557
56-
# Add OpenSSL to PATH
57-
$env:Path += ";C:\Program Files\OpenSSL-Win64\bin"
58+
try {
59+
Invoke-WebRequest -Uri $url -OutFile $output -UseBasicParsing
60+
Write-Host "Installing Win32OpenSSL..."
61+
Start-Process -FilePath $output -ArgumentList "/SILENT", "/VERYSILENT", "/SP-", "/SUPPRESSMSGBOXES" -Wait
62+
Remove-Item $output -Force
63+
Write-Host "Win32OpenSSL installation completed"
64+
} catch {
65+
Write-Host "Win32OpenSSL download failed, falling back to chocolatey..."
66+
choco install openssl -y
67+
}
5868
59-
# Verify installation and directories exist
60-
if (Test-Path "C:\Program Files\OpenSSL-Win64\lib") {
61-
Write-Host "OpenSSL lib directory found"
62-
} else {
63-
Write-Host "OpenSSL lib directory not found, checking alternate locations..."
64-
if (Test-Path "C:\Program Files\OpenSSL\lib") {
65-
Write-Host "Found OpenSSL at C:\Program Files\OpenSSL\"
66-
echo "OPENSSL_DIR=C:\Program Files\OpenSSL" | Out-File -FilePath $env:GITHUB_ENV -Append
67-
echo "OPENSSL_LIB_DIR=C:\Program Files\OpenSSL\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
68-
echo "OPENSSL_INCLUDE_DIR=C:\Program Files\OpenSSL\include" | Out-File -FilePath $env:GITHUB_ENV -Append
69-
} else {
70-
Write-Host "OpenSSL installation failed or directories not found"
71-
exit 1
69+
# Define possible OpenSSL installation paths
70+
$possiblePaths = @(
71+
"C:\Program Files\OpenSSL-Win64",
72+
"C:\Program Files\OpenSSL",
73+
"C:\OpenSSL-Win64",
74+
"C:\OpenSSL"
75+
)
76+
77+
$opensslPath = $null
78+
foreach ($path in $possiblePaths) {
79+
if (Test-Path "$path\lib") {
80+
$opensslPath = $path
81+
Write-Host "Found OpenSSL at: $path"
82+
break
7283
}
7384
}
7485
75-
# Set environment variables for the standard location
76-
if (Test-Path "C:\Program Files\OpenSSL-Win64\lib") {
77-
echo "OPENSSL_DIR=C:\Program Files\OpenSSL-Win64" | Out-File -FilePath $env:GITHUB_ENV -Append
78-
echo "OPENSSL_LIB_DIR=C:\Program Files\OpenSSL-Win64\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
79-
echo "OPENSSL_INCLUDE_DIR=C:\Program Files\OpenSSL-Win64\include" | Out-File -FilePath $env:GITHUB_ENV -Append
86+
if (-not $opensslPath) {
87+
Write-Host "ERROR: OpenSSL installation not found in any expected location"
88+
Write-Host "Searched paths:"
89+
foreach ($path in $possiblePaths) {
90+
Write-Host " - $path"
91+
}
92+
exit 1
8093
}
8194
82-
# Also set OPENSSL_ROOT_DIR for compatibility
83-
if (Test-Path "C:\Program Files\OpenSSL-Win64") {
84-
echo "OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL-Win64" | Out-File -FilePath $env:GITHUB_ENV -Append
85-
} elseif (Test-Path "C:\Program Files\OpenSSL") {
86-
echo "OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL" | Out-File -FilePath $env:GITHUB_ENV -Append
95+
# Set environment variables for cargo and the linker
96+
echo "OPENSSL_DIR=$opensslPath" | Out-File -FilePath $env:GITHUB_ENV -Append
97+
echo "OPENSSL_LIB_DIR=$opensslPath\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
98+
echo "OPENSSL_INCLUDE_DIR=$opensslPath\include" | Out-File -FilePath $env:GITHUB_ENV -Append
99+
echo "OPENSSL_ROOT_DIR=$opensslPath" | Out-File -FilePath $env:GITHUB_ENV -Append
100+
101+
# Add OpenSSL bin directory to PATH for DLL resolution during linking
102+
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "Process")
103+
$newPath = "$opensslPath\bin;$currentPath"
104+
echo "PATH=$newPath" | Out-File -FilePath $env:GITHUB_ENV -Append
105+
106+
# Verify all required files exist
107+
$requiredFiles = @(
108+
"$opensslPath\lib\libssl.lib",
109+
"$opensslPath\lib\libcrypto.lib",
110+
"$opensslPath\bin\libssl-3-x64.dll",
111+
"$opensslPath\bin\libcrypto-3-x64.dll"
112+
)
113+
114+
$missingFiles = @()
115+
foreach ($file in $requiredFiles) {
116+
if (-not (Test-Path $file)) {
117+
$missingFiles += $file
118+
}
87119
}
120+
121+
if ($missingFiles.Count -gt 0) {
122+
Write-Host "WARNING: Some OpenSSL files are missing:"
123+
foreach ($file in $missingFiles) {
124+
Write-Host " - $file"
125+
}
126+
} else {
127+
Write-Host "All required OpenSSL files found"
128+
}
129+
130+
# Display environment for debugging
131+
Write-Host "OpenSSL configuration:"
132+
Write-Host " OPENSSL_DIR: $opensslPath"
133+
Write-Host " OPENSSL_LIB_DIR: $opensslPath\lib"
134+
Write-Host " OPENSSL_INCLUDE_DIR: $opensslPath\include"
88135
89136
- name: Install Perl dependencies for OpenSSL (Windows fallback)
90137
if: runner.os == 'Windows'
@@ -99,6 +146,28 @@ jobs:
99146

100147
- name: Build
101148
run: |
149+
# On Windows, display OpenSSL environment for debugging
150+
if [ "${{ runner.os }}" = "Windows" ]; then
151+
echo "=== OpenSSL Environment Debug Info ==="
152+
echo "OPENSSL_DIR: $OPENSSL_DIR"
153+
echo "OPENSSL_LIB_DIR: $OPENSSL_LIB_DIR"
154+
echo "OPENSSL_INCLUDE_DIR: $OPENSSL_INCLUDE_DIR"
155+
echo "PATH (first 500 chars): ${PATH:0:500}"
156+
157+
# List OpenSSL library files if directory exists
158+
if [ -d "$OPENSSL_LIB_DIR" ]; then
159+
echo "OpenSSL lib directory contents:"
160+
ls -la "$OPENSSL_LIB_DIR" || true
161+
fi
162+
163+
# Check if OpenSSL DLLs are accessible
164+
if [ -d "$OPENSSL_DIR/bin" ]; then
165+
echo "OpenSSL bin directory contents:"
166+
ls -la "$OPENSSL_DIR/bin" || true
167+
fi
168+
echo "=== End OpenSSL Debug Info ==="
169+
fi
170+
102171
cargo build --release --target ${{ matrix.target }}
103172
104173
- name: Prepare asset

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ tokio-tungstenite = "0.27"
3737
futures-util = "0.3"
3838
# Security fix: Replace atty with is-terminal to fix unmaintained dependency
3939
is-terminal = "0.4"
40+
# Explicit OpenSSL dependencies for better Windows compatibility
41+
openssl = "0.10"
42+
openssl-sys = "0.9"
4043

4144
[dev-dependencies]
4245
tokio-test = "0.4"

0 commit comments

Comments
 (0)