Skip to content

Commit ec6e582

Browse files
ekgameromainguy
andauthored
Multiplatform support. (#31)
* Replace build.gradle with build.gradle.kts. * Move project files to appropriate modules. * Clean up the test, use common test library. * Disable explicit API mode. * Use Kotlin common power function. * Fix test cases to properly run in JS and Native environments. JS doesn't allow spaces in identifiers. Native treats NaN as not equal to itself. * Remove unnecessary dependencies. * Remove unnecessary code from build.gradle.kts. * Updated test identifiers to camel case. * Make the array equality assertion actually assert. * Make the array equality assertion more lenient. The tests fail in JS with 0.0001f delta. * Added more build targets. Used https://github.com/benasher44/uuid/blob/master/build.gradle.kts as an example. * Added publishing support. Used https://github.com/benasher44/uuid/blob/master/publish.gradle as an example. * Fix publishing Co-authored-by: Romain Guy <[email protected]>
1 parent d864604 commit ec6e582

File tree

13 files changed

+588
-502
lines changed

13 files changed

+588
-502
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ build/
1010
!**/src/**/build
1111
!**/test/**/build
1212
*.iml
13+
.idea/artifacts/
1314
.idea/libraries/
1415
.idea/modules
1516
.idea/modules.xml

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ val v = Float3(1.0f, 3.0f, 4.0f)
1515
val n = normalize(v)
1616
```
1717

18+
This project supports multi-platform thanks to [ekgame](https://github.com/ekgame).
19+
1820
## Maven
1921

2022
```gradle
@@ -24,7 +26,7 @@ repositories {
2426
}
2527
2628
dependencies {
27-
implementation 'dev.romainguy:kotlin-math:1.0.1'
29+
implementation 'dev.romainguy:kotlin-math:1.1.0'
2830
}
2931
```
3032

build.gradle

-106
This file was deleted.

build.gradle.kts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import org.jetbrains.kotlin.konan.target.HostManager
2+
3+
plugins {
4+
kotlin("multiplatform") version "1.6.0"
5+
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
6+
id("org.jetbrains.dokka") version "1.6.0"
7+
id("maven-publish")
8+
id("signing")
9+
}
10+
11+
val GROUP: String by project
12+
val VERSION_NAME: String by project
13+
14+
group = GROUP
15+
version = VERSION_NAME
16+
17+
repositories {
18+
mavenCentral()
19+
}
20+
21+
dependencies {
22+
dokkaGfmPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.0")
23+
}
24+
25+
kotlin {
26+
targets {
27+
jvm()
28+
js(BOTH) {
29+
compilations.all {
30+
kotlinOptions {
31+
sourceMap = true
32+
moduleKind = "umd"
33+
metaInfo = true
34+
}
35+
}
36+
browser()
37+
nodejs()
38+
}
39+
if (HostManager.hostIsMac) {
40+
macosX64()
41+
macosArm64()
42+
iosX64()
43+
iosArm64()
44+
iosArm32()
45+
iosSimulatorArm64()
46+
watchosArm32()
47+
watchosArm64()
48+
watchosX86()
49+
watchosSimulatorArm64()
50+
tvosArm64()
51+
tvosX64()
52+
tvosSimulatorArm64()
53+
}
54+
55+
if (HostManager.hostIsMingw || HostManager.hostIsMac) {
56+
mingwX64 {
57+
binaries.findTest(DEBUG)!!.linkerOpts = mutableListOf("-Wl,--subsystem,windows")
58+
}
59+
}
60+
61+
if (HostManager.hostIsLinux || HostManager.hostIsMac) {
62+
linuxX64()
63+
linuxArm32Hfp()
64+
}
65+
}
66+
67+
sourceSets {
68+
commonMain {
69+
dependencies {
70+
implementation(kotlin("stdlib-common"))
71+
}
72+
}
73+
commonTest {
74+
dependencies {
75+
implementation(kotlin("test"))
76+
}
77+
}
78+
}
79+
}
80+
81+
apply(from = "publish.gradle")

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=dev.romainguy
2-
VERSION_NAME=1.0.1
2+
VERSION_NAME=1.1.0
33

44
POM_DESCRIPTION=Graphics oriented math library for Kotlin
55

publish.gradle

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
group GROUP
2+
version VERSION_NAME
3+
4+
// Publish and release with:
5+
// ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
6+
// Both tasks must be executed in one pass
7+
// https://github.com/gradle-nexus/publish-plugin/
8+
nexusPublishing {
9+
repositories {
10+
sonatype {
11+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
12+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
13+
username = SONATYPE_NEXUS_USERNAME
14+
password = SONATYPE_NEXUS_PASSWORD
15+
}
16+
}
17+
}
18+
19+
publishing {
20+
publications.all {
21+
pom {
22+
description = POM_DESCRIPTION
23+
name = POM_NAME
24+
url = POM_URL
25+
}
26+
pom.licenses {
27+
license {
28+
name = POM_LICENCE_NAME
29+
url = POM_LICENCE_URL
30+
distribution = POM_LICENCE_DIST
31+
}
32+
}
33+
pom.scm {
34+
url = POM_SCM_URL
35+
connection = POM_SCM_CONNECTION
36+
developerConnection = POM_SCM_DEV_CONNECTION
37+
}
38+
pom.developers {
39+
developer {
40+
id = POM_DEVELOPER_ID
41+
name = POM_DEVELOPER_NAME
42+
}
43+
}
44+
}
45+
}
46+
47+
def isReleaseBuild() {
48+
return !VERSION_NAME.contains('SNAPSHOT')
49+
}
50+
51+
def getReleaseRepositoryUrl() {
52+
return hasProperty('RELEASE_REPOSITORY_URL')
53+
? RELEASE_REPOSITORY_URL
54+
: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
55+
}
56+
57+
def getSnapshotRepositoryUrl() {
58+
return hasProperty('SNAPSHOT_REPOSITORY_URL')
59+
? SNAPSHOT_REPOSITORY_URL
60+
: 'https://oss.sonatype.org/content/repositories/snapshots/'
61+
}
62+
63+
signing {
64+
required { isReleaseBuild() }
65+
sign(publishing.publications)
66+
}
67+
68+
tasks.withType(Sign) {
69+
onlyIf { isReleaseBuild() }
70+
}
71+
72+
tasks.register('publishMac') {
73+
dependsOn 'publishIosArm32PublicationToMavenRepository'
74+
dependsOn 'publishIosArm64PublicationToMavenRepository'
75+
dependsOn 'publishIosSimulatorArm64PublicationToMavenRepository'
76+
dependsOn 'publishIosX64PublicationToMavenRepository'
77+
dependsOn 'publishTvosArm64PublicationToMavenRepository'
78+
dependsOn 'publishTvosSimulatorArm64PublicationToMavenRepository'
79+
dependsOn 'publishTvosX64PublicationToMavenRepository'
80+
dependsOn 'publishWatchosArm32PublicationToMavenRepository'
81+
dependsOn 'publishWatchosArm64PublicationToMavenRepository'
82+
dependsOn 'publishWatchosSimulatorArm64PublicationToMavenRepository'
83+
dependsOn 'publishWatchosX86PublicationToMavenRepository'
84+
dependsOn 'publishMacosArm64PublicationToMavenRepository'
85+
dependsOn 'publishMacosX64PublicationToMavenRepository'
86+
dependsOn 'publishJvmPublicationToMavenRepository'
87+
dependsOn 'publishJsPublicationToMavenRepository'
88+
dependsOn 'publishKotlinMultiplatformPublicationToMavenRepository'
89+
}
90+
91+
tasks.register('publishWindows') {
92+
dependsOn 'publishMingwX64PublicationToMavenRepository'
93+
}
94+
95+
tasks.register('publishLinux') {
96+
dependsOn 'publishLinuxX64PublicationToMavenRepository'
97+
dependsOn 'publishLinuxArm32HfpPublicationToMavenRepository'
98+
}

src/main/kotlin/dev/romainguy/kotlin/math/Scalar.kt renamed to src/commonMain/kotlin/dev/romainguy/kotlin/math/Scalar.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package dev.romainguy.kotlin.math
2020

21+
import kotlin.math.pow
22+
2123
const val PI = 3.1415926536f
2224
const val HALF_PI = PI * 0.5f
2325
const val TWO_PI = PI * 2.0f
@@ -40,4 +42,4 @@ inline fun fract(v: Float) = v % 1
4042

4143
inline fun sqr(v: Float) = v * v
4244

43-
inline fun pow(x: Float, y: Float) = StrictMath.pow(x.toDouble(), y.toDouble()).toFloat()
45+
inline fun pow(x: Float, y: Float) = (x.toDouble().pow(y.toDouble())).toFloat()

0 commit comments

Comments
 (0)