Skip to content

Commit 65aa6b5

Browse files
pcbeardctreffs
andauthored
Use Foundation versions of math functions (#6)
* Use Foundation versions of math functions If neither Darwin, nor Glibc are available, use Foundation to import math functions. Use dynamic library target on Windows since ar tool doesn't seem to exist. * Fix test_asinh() by adding accuracy parameter * Reduce accuracy for testQuatFromEulerAngles_0_(n)90_0 * Remove WASM CI * Use Swift 5.5 in on Windows CI * Update Windows CI * Update ci-windows.yml * Update CI trigger Co-authored-by: Christian Treffs <[email protected]>
1 parent 126cdc2 commit 65aa6b5

38 files changed

+397
-54
lines changed

.github/workflows/ci-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
workflow_dispatch:
89

910
jobs:
1011
linux-test-build-release:

.github/workflows/ci-macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
workflow_dispatch:
89

910
jobs:
1011
macos-test-build-release-xcode:

.github/workflows/ci-wasm.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/ci-windows.yml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,43 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
workflow_dispatch:
89

910
jobs:
1011
windows-test-build-release:
1112
runs-on: windows-latest
12-
env:
13-
SNAPSHOT: "https://swift.org/builds/swift-5.4.1-release/windows10/swift-5.4.1-RELEASE/swift-5.4.1-RELEASE-windows10.exe"
13+
strategy:
14+
matrix:
15+
include:
16+
- tag: 5.5-RELEASE
17+
branch: swift-5.5-release
1418
steps:
15-
- uses: actions/checkout@master
16-
- uses: seanmiddleditch/gha-setup-vsdevenv@master
17-
18-
- name: Install Swift
19-
run: |
20-
Install-Binary -Url "${env:SNAPSHOT}" -Name "installer.exe" -ArgumentList ("-q")
21-
- name: Set Environment Variables
22-
run: |
23-
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
24-
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
25-
- name: Adjust Paths
26-
run: |
27-
echo "C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
28-
echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
29-
- name: Install Supporting Files
30-
run: |
31-
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
32-
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
33-
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
34-
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
35-
- name: Test
36-
run: swift test -v --skip-update --parallel --enable-test-discovery
37-
- name: Build Release
38-
run: swift build -c release
19+
- uses: actions/checkout@master
20+
with:
21+
fetch-depth: 1
22+
23+
- uses: seanmiddleditch/gha-setup-vsdevenv@master
24+
25+
- name: Install Swift ${{ matrix.tag }}
26+
run: |
27+
Install-Binary -Url "https://swift.org/builds/${{ matrix.branch }}/windows10/swift-${{ matrix.tag }}/swift-${{ matrix.tag }}-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")
28+
- name: Set Environment Variables
29+
run: |
30+
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
31+
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
32+
- name: Adjust Paths
33+
run: |
34+
echo "C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
35+
echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
36+
- name: Install Supporting Files
37+
run: |
38+
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
39+
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
40+
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
41+
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
42+
43+
- name: Test
44+
run: swift test -v --skip-update --parallel --enable-test-discovery
45+
46+
- name: Build Release
47+
run: swift build -c release

.github/workflows/markdown-link-check.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Check markdown links
22

3-
on: push
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
49

510
jobs:
611
markdown-link-check:

Package.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ swiftSettings.append(.define("FRB_MATH_USE_SIMD"))
1313

1414
#if canImport(Darwin)
1515
swiftSettings.append(.define("FRB_MATH_DARWIN"))
16+
#elseif canImport(Glibc)
17+
swiftSettings.append(.define("FRB_MATH_GLIBC"))
18+
#elseif canImport(Foundation)
19+
swiftSettings.append(.define("FRB_MATH_FOUNDATION"))
1620
#endif
1721

18-
#if canImport(Glibc)
19-
swiftSettings.append(.define("FRB_MATH_GLIBC"))
22+
#if os(Windows)
23+
let libraryType : Product.Library.LibraryType = .dynamic
24+
#else
25+
let libraryType : Product.Library.LibraryType = .static
2026
#endif
2127

2228
let package = Package(
2329
name: "FirebladeMath",
2430
products: [
2531
.library(
2632
name: "FirebladeMath",
27-
type: .static,
33+
type: libraryType,
2834
targets: ["FirebladeMath"])
2935
],
3036
targets: [

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![macOS](https://github.com/fireblade-engine/math/actions/workflows/ci-macos.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-macos.yml)
55
[![Linux](https://github.com/fireblade-engine/math/actions/workflows/ci-linux.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-linux.yml)
66
[![Windows](https://github.com/fireblade-engine/math/actions/workflows/ci-windows.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-windows.yml)
7-
[![WASM](https://github.com/fireblade-engine/math/actions/workflows/ci-wasm.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-wasm.yml)
87
[![swift-version-compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/fireblade-engine/math)
98
[![platform-compatilibilty](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/fireblade-engine/math)
109
<!--[![platform-webassembly](https://img.shields.io/badge/Platform-WebAssembly-blue.svg)](https://github.com/swiftwasm/swift#swiftwasm)-->

Sources/FirebladeMath/Functions/abs.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if FRB_MATH_FOUNDATION
2+
import Foundation
3+
#endif
4+
15
#if FRB_MATH_DARWIN
26
import Darwin.C.math
37
#endif
@@ -26,4 +30,8 @@ public func abs(_ double: Double) -> Double {
2630
#if FRB_MATH_GLIBC
2731
return Glibc.fabs(double)
2832
#endif
33+
34+
#if FRB_MATH_FOUNDATION
35+
return Foundation.fabs(double)
36+
#endif
2937
}

Sources/FirebladeMath/Functions/acos.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if FRB_MATH_FOUNDATION
2+
import Foundation
3+
#endif
4+
15
#if FRB_MATH_DARWIN
26
import Darwin.C.math
37
#endif
@@ -20,6 +24,10 @@ public func acos(_ float: Float) -> Float {
2024
#if FRB_MATH_GLIBC
2125
return Glibc.acosf(float)
2226
#endif
27+
28+
#if FRB_MATH_FOUNDATION
29+
return Foundation.acosf(float)
30+
#endif
2331
}
2432

2533
/// Computes the principal value of the arc cosine of arg.
@@ -36,4 +44,8 @@ public func acos(_ double: Double) -> Double {
3644
#if FRB_MATH_GLIBC
3745
return Glibc.acos(double)
3846
#endif
47+
48+
#if FRB_MATH_FOUNDATION
49+
return Foundation.acos(double)
50+
#endif
3951
}

Sources/FirebladeMath/Functions/acosh.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if FRB_MATH_FOUNDATION
2+
import Foundation
3+
#endif
4+
15
#if FRB_MATH_DARWIN
26
import Darwin.C.math
37
#endif
@@ -20,6 +24,10 @@ public func acosh(_ double: Double) -> Double {
2024
#if FRB_MATH_GLIBC
2125
return Glibc.acosh(double)
2226
#endif
27+
28+
#if FRB_MATH_FOUNDATION
29+
return Foundation.acosh(double)
30+
#endif
2331
}
2432

2533
/// Computes the inverse hyperbolic cosine of arg.
@@ -36,4 +44,8 @@ public func acosh(_ float: Float) -> Float {
3644
#if FRB_MATH_GLIBC
3745
return Glibc.acoshf(float)
3846
#endif
47+
48+
#if FRB_MATH_FOUNDATION
49+
return Foundation.acoshf(float)
50+
#endif
3951
}

0 commit comments

Comments
 (0)