Skip to content

Commit

Permalink
Use our own libffi repository on Windows CI (crystal-lang#14998)
Browse files Browse the repository at this point in the history
I forked the libffi upstream and wrote [my own `CMakeLists.txt`](https://github.com/crystal-lang/libffi/blob/441390ce33ae2d9bf2916184fe6b7207b306dd3e/CMakeLists.txt). It only handles x64 MSVC, but we could easily extend it to support ARM64 in the near future.
Note that the Windows CI already uses libffi since there are interpreter tests and stdlib tests running with the interpreter.
  • Loading branch information
HertzDevil authored Sep 19, 2024
1 parent edfe1f4 commit 6254169
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: .\etc\win-ci\build-iconv.ps1 -BuildTree deps\iconv -Version 1.17
- name: Build libffi
if: steps.cache-libs.outputs.cache-hit != 'true'
run: .\etc\win-ci\build-ffi.ps1 -BuildTree deps\ffi -Version 3.3
run: .\etc\win-ci\build-ffi.ps1 -BuildTree deps\ffi -Version 3.4.6
- name: Build zlib
if: steps.cache-libs.outputs.cache-hit != 'true'
run: .\etc\win-ci\build-z.ps1 -BuildTree deps\z -Version 1.3.1
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
run: .\etc\win-ci\build-iconv.ps1 -BuildTree deps\iconv -Version 1.17 -Dynamic
- name: Build libffi
if: steps.cache-dlls.outputs.cache-hit != 'true'
run: .\etc\win-ci\build-ffi.ps1 -BuildTree deps\ffi -Version 3.3 -Dynamic
run: .\etc\win-ci\build-ffi.ps1 -BuildTree deps\ffi -Version 3.4.6 -Dynamic
- name: Build zlib
if: steps.cache-dlls.outputs.cache-hit != 'true'
run: .\etc\win-ci\build-z.ps1 -BuildTree deps\z -Version 1.3.1 -Dynamic
Expand Down
43 changes: 10 additions & 33 deletions etc/win-ci/build-ffi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,26 @@ param(
. "$(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/winlibs/libffi.git -Ref libffi-$Version
Setup-Git -Path $BuildTree -Url https://github.com/crystal-lang/libffi.git -Ref v$Version

Run-InDirectory $BuildTree {
$args = "-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF"
if ($Dynamic) {
Replace-Text win32\vs16_x64\libffi\libffi.vcxproj 'StaticLibrary' 'DynamicLibrary'
$args = "-DBUILD_SHARED_LIBS=ON $args"
} else {
$args = "-DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded $args"
}

echo '<Project>
<PropertyGroup>
<ForceImportAfterCppTargets>$(MsbuildThisFileDirectory)\Override.props</ForceImportAfterCppTargets>
</PropertyGroup>
</Project>' > 'Directory.Build.props'

echo "<Project>
<PropertyGroup>
<WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
$(if ($Dynamic) {
'<PreprocessorDefinitions>FFI_BUILDING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>'
} else {
'<RuntimeLibrary>MultiThreaded</RuntimeLibrary>'
})
<DebugInformationFormat>None</DebugInformationFormat>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
</Project>" > 'Override.props'

MSBuild.exe /p:PlatformToolset=v143 /p:Platform=x64 /p:Configuration=Release win32\vs16_x64\libffi-msvc.sln -target:libffi:Rebuild
& $cmake . $args.split(' ')
& $cmake --build . --config Release
if (-not $?) {
Write-Host "Error: Failed to build libffi" -ForegroundColor Red
Exit 1
}
}

if ($Dynamic) {
mv -Force $BuildTree\win32\vs16_x64\x64\Release\libffi.lib libs\ffi-dynamic.lib
mv -Force $BuildTree\win32\vs16_x64\x64\Release\libffi.dll dlls\
mv -Force $BuildTree\Release\libffi.lib libs\ffi-dynamic.lib
mv -Force $BuildTree\Release\libffi.dll dlls\
} else {
mv -Force $BuildTree\win32\vs16_x64\x64\Release\libffi.lib libs\ffi.lib
mv -Force $BuildTree\Release\libffi.lib libs\ffi.lib
}

0 comments on commit 6254169

Please sign in to comment.