Skip to content

Commit

Permalink
[windows] use bundled libtom{crypt,math} libs
Browse files Browse the repository at this point in the history
Using more recent versions seems to be a dead end; the legacy is too strong on this one.

Download and build just `zlib`.
  • Loading branch information
nil4 committed Oct 23, 2024
1 parent c5da3be commit 37df921
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
21 changes: 19 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@ let linkerSettings: [LinkerSetting]? = [
])
]

let libtommathTarget = Target.systemLibrary(name: "libtommath", path: "Sources/libtommath-win")
let libtomcryptTarget = Target.systemLibrary(name: "libtomcrypt", path: "Sources/libtomcrypt-win")
let libtommathTarget = Target.target(name: "libtommath", cSettings: [
.unsafeFlags([
// silence
// Sources\libtommath\bignumshim.c:28:10: warning: 'mp_read_unsigned_bin' is deprecated: replaced by mp_from_ubin [-Wdeprecated-declarations]
"-Wno-deprecated-declarations"
])
])
let libtomcryptTarget = Target.target(name: "libtomcrypt", cSettings: [
.unsafeFlags([
"-Wno-shorten-64-to-32",
// silence
// Sources\libtomcrypt\include\tomcrypt_cfg.h:27:28: warning: 'malloc' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
// Sources\libtomcrypt\include\tomcrypt_cfg.h:28:28: warning: 'realloc' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
"-Wno-inconsistent-dllimport",
// silence
// Sources\libtomcrypt\mac\xcbc\xcbc_file.c:55:9: warning: 'fopen' is deprecated: This function or variable may be unsafe. Consider using fopen_s instead. [-Wdeprecated-declarations]
"-Wno-deprecated-declarations"
])
])
let zTarget = Target.systemLibrary(name: "Z", path: "Sources/Z-win")
#else
let cSettings: [CSetting]? = []
Expand Down
37 changes: 2 additions & 35 deletions Scripts/windows/dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ Set-StrictMode -Version Latest

$cmake = (Get-Command cmake.exe -ErrorAction Stop)
$ninja = (Get-Command ninja.exe -ErrorAction Stop)
$nmake = (Get-Command nmake.exe -ErrorAction Stop)
$swift = (Get-Command swift.exe -ErrorAction Stop)

$cmake,$ninja,$nmake,$swift | Format-Table -AutoSize -HideTableHeaders -Property Source
$cmake,$ninja,$swift | Format-Table -AutoSize -HideTableHeaders -Property Source

exec { cmake --version }
exec { ninja --version }
Expand All @@ -30,43 +29,11 @@ function download_and_extract([string]$releaseFile, [string]$localName) {
return $dirname
}

$mathDir = download_and_extract 'libtom/libtommath/releases/download/v1.3.0/ltm-1.3.0.zip' 'libtommath-1.3.0'
$cryptDir = download_and_extract 'libtom/libtomcrypt/releases/download/v1.18.2/crypt-1.18.2.zip' 'libtomcrypt-1.18.2'
$zlibDir = download_and_extract 'zlib-ng/zlib-ng/archive/refs/tags/2.2.2.zip' 'zlib-ng-2.2.2'

function nmake_build([string]$dir, [string]$makefile, [string[]]$nmakeArgs) {
Write-Host "Building ${dir} with nmake" -ForegroundColor Cyan

Push-Location $dir
try {
exec { nmake.exe /nologo -f $makefile $nmakeArgs "" }
} finally {
Pop-Location
}
}

[string]$cryptArm64flags = ''
if ($HOST_MSVC_ARCH -eq 'arm64') {
# Needed because the endian detection macros do not work on arm64 in a released version.
# This is now fixed but no new release was made since. Avoid warnings on x64 by not overriding there.
# ref. https://github.com/libtom/libtomcrypt/commit/c4d22b904604f2f49c717ffc9bf86678658117b0#diff-2db5eece44c5b2ec42c2e2a08d847e6b0e3723d7d11bf7d5bda16f20fe795ff9R83
$cryptArm64flags = '/DENDIAN_LITTLE /DENDIAN_64BITWORD /DLTC_FAST'
}
$zlibDir = download_and_extract 'zlib-ng/zlib-ng/archive/refs/tags/2.2.2.zip' 'zlib-ng-2.2.2'

[string]$BUNDLE_DIR = "${BIN_DIR}\deps-windows"
clean_dir $BUNDLE_DIR

nmake_build $mathDir "makefile.msvc" @(
"PREFIX=${BUNDLE_DIR}"
'install'
)
nmake_build $cryptDir "makefile.msvc" @(
"CFLAGS=/DUSE_LTM /DLTM_DESC ${cryptArm64flags} /I${mathDir}"
"EXTRALIBS=${mathDir}\tommath.lib"
"PREFIX=${BUNDLE_DIR}"
'install'
)

function cmake_build_install([string]$dir, [string[]]$cmakeArgs) {
Write-Host "Building ${dir} with cmake" -ForegroundColor Cyan

Expand Down

0 comments on commit 37df921

Please sign in to comment.