-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Cygwin to build libiconv on Windows CI (#14999)
This uses the official releases and build instructions. To compile code with this patch using a Windows Crystal compiler without this patch, either the new library files (`lib\iconv.lib`, `lib\iconv-dynamic.lib`, `iconv-2.dll`) shall be copied to that existing Crystal installation, or `CRYSTAL_LIBRARY_PATH` shall include the new `lib` directory so that the `@[Link]` annotation will pick up the new `iconv-2.dll` on program builds. Otherwise, compiled programs will continue to look for the old `libiconv.dll`, and silently break if it is not in `%PATH%` (which is hopefully rare since most of the time Crystal itself is also in `%PATH%`). Cygwin's location is currently hardcoded to `C:\cygwin64`, the default installation location for 64-bit Cygwin. Cygwin itself doesn't have native ARM64 support, but cross-compilation should be possible by simply using the x64-to-ARM64 cross tools MSVC developer prompt on an ARM64 machine.
- Loading branch information
1 parent
9134f9f
commit 5c18900
Showing
5 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,29 @@ | ||
param( | ||
[Parameter(Mandatory)] [string] $BuildTree, | ||
[Parameter(Mandatory)] [string] $Version, | ||
[switch] $Dynamic | ||
) | ||
|
||
. "$(Split-Path -Parent $MyInvocation.MyCommand.Path)\setup.ps1" | ||
|
||
[void](New-Item -Name (Split-Path -Parent $BuildTree) -ItemType Directory -Force) | ||
Setup-Git -Path $BuildTree -Url https://github.com/pffang/libiconv-for-Windows.git -Ref 1353455a6c4e15c9db6865fd9c2bf7203b59c0ec # master@{2022-10-11} | ||
Invoke-WebRequest "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${Version}.tar.gz" -OutFile libiconv.tar.gz | ||
tar -xzf libiconv.tar.gz | ||
mv libiconv-* $BuildTree | ||
rm libiconv.tar.gz | ||
|
||
Run-InDirectory $BuildTree { | ||
Replace-Text libiconv\include\iconv.h '__declspec (dllimport) ' '' | ||
|
||
echo '<Project> | ||
<PropertyGroup> | ||
<ForceImportAfterCppTargets>$(MsbuildThisFileDirectory)\Override.props</ForceImportAfterCppTargets> | ||
</PropertyGroup> | ||
</Project>' > 'Directory.Build.props' | ||
|
||
echo "<Project> | ||
<PropertyGroup> | ||
<WholeProgramOptimization>false</WholeProgramOptimization> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup> | ||
<ClCompile> | ||
<DebugInformationFormat>None</DebugInformationFormat> | ||
<WholeProgramOptimization>false</WholeProgramOptimization> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>false</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition=`"'`$(Configuration)'=='Release'`"> | ||
<ClCompile> | ||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> | ||
</ClCompile> | ||
</ItemDefinitionGroup> | ||
</Project>" > 'Override.props' | ||
|
||
if ($Dynamic) { | ||
MSBuild.exe /p:Platform=x64 /p:Configuration=Release libiconv.vcxproj | ||
} else { | ||
MSBuild.exe /p:Platform=x64 /p:Configuration=ReleaseStatic libiconv.vcxproj | ||
} | ||
$env:CHERE_INVOKING = 1 | ||
& 'C:\cygwin64\bin\bash.exe' --login "$PSScriptRoot\cygwin-build-iconv.sh" "$Version" "$(if ($Dynamic) { 1 })" | ||
if (-not $?) { | ||
Write-Host "Error: Failed to build libiconv" -ForegroundColor Red | ||
Exit 1 | ||
} | ||
} | ||
|
||
if ($Dynamic) { | ||
mv -Force $BuildTree\output\x64\Release\libiconv.lib libs\iconv-dynamic.lib | ||
mv -Force $BuildTree\output\x64\Release\libiconv.dll dlls\ | ||
mv -Force $BuildTree\iconv\lib\iconv.dll.lib libs\iconv-dynamic.lib | ||
mv -Force $BuildTree\iconv\bin\iconv-2.dll dlls\ | ||
} else { | ||
mv -Force $BuildTree\output\x64\ReleaseStatic\libiconvStatic.lib libs\iconv.lib | ||
mv -Force $BuildTree\iconv\lib\iconv.lib libs\ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
set -eo pipefail | ||
|
||
Version=$1 | ||
Dynamic=$2 | ||
|
||
export PATH="$(pwd)/build-aux:$PATH" | ||
export CC="$(pwd)/build-aux/compile cl -nologo" | ||
export CXX="$(pwd)/build-aux/compile cl -nologo" | ||
export AR="$(pwd)/build-aux/ar-lib lib" | ||
export LD="link" | ||
export NM="dumpbin -symbols" | ||
export STRIP=":" | ||
export RANLIB=":" | ||
if [ -n "$Dynamic" ]; then | ||
export CFLAGS="-MD" | ||
export CXXFLAGS="-MD" | ||
enable_shared=yes | ||
enable_static=no | ||
else | ||
export CFLAGS="-MT" | ||
export CXXFLAGS="-MT" | ||
enable_shared=no | ||
enable_static=yes | ||
fi | ||
export CPPFLAGS="-D_WIN32_WINNT=_WIN32_WINNT_WIN7 -I$(pwd)/iconv/include" | ||
export LDFLAGS="-L$(pwd)/iconv/lib" | ||
|
||
./configure --host=x86_64-w64-mingw32 --prefix="$(pwd)/iconv" --enable-shared="${enable_shared}" --enable-static="${enable_static}" | ||
make | ||
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters