Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mac OS X target #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: Gradle build

on:
push:
branches: [ dev, master ]
pull_request:
types: [opened, edited]

jobs:
build:
strategy:
matrix:
os: [ ubuntu-20.04, windows-latest ]
os: [ ubuntu-20.04, windows-2019, macos-10.15 ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand All @@ -18,12 +18,12 @@ jobs:
graalvm: 21.1.0
java: java11
arch: amd64
- if: matrix.os == 'windows-latest'
- if: matrix.os == 'windows-2019'
uses: msys2/setup-msys2@v2
with:
release: false
path-type: inherit
- if: matrix.os == 'windows-latest'
- if: matrix.os == 'windows-2019'
shell: msys2 {0}
run: pacman --noconfirm -S mingw-w64-x86_64-gsl
- uses: actions/cache@v2
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
publish:
strategy:
matrix:
os: [ ubuntu-20.04, windows-latest ]
os: [ ubuntu-20.04, windows-2019, macos-10.15 ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand All @@ -18,12 +18,12 @@ jobs:
graalvm: 21.1.0
java: java11
arch: amd64
- if: matrix.os == 'windows-latest'
- if: matrix.os == 'windows-2019'
uses: msys2/setup-msys2@v2
with:
release: false
path-type: inherit
- if: matrix.os == 'windows-latest'
- if: matrix.os == 'windows-2019'
shell: msys2 {0}
run: pacman --noconfirm -S mingw-w64-x86_64-gsl
- uses: actions/cache@v2
Expand All @@ -46,9 +46,14 @@ jobs:
-Ppublishing.github=false
-Ppublishing.space.user=${{ secrets.PUBLISHING_SPACE_USER }}
-Ppublishing.space.token=${{ secrets.PUBLISHING_SPACE_TOKEN }}
- if: matrix.os == 'windows-latest'
- if: matrix.os == 'windows-2019'
shell: cmd
run: >
gradlew release --no-daemon -Ppublishing.enabled=true -Ppublishing.platform=mingwX64
-Ppublishing.space.user=${{ secrets.PUBLISHING_SPACE_USER }}
-Ppublishing.space.token=${{ secrets.PUBLISHING_SPACE_TOKEN }}
- if: matrix.os == 'macos-10.15'
run: >
gradlew release --no-daemon -Ppublishing.enabled=true -Ppublishing.platform=macosX64
-Ppublishing.space.user=${{ secrets.PUBLISHING_SPACE_USER }}
-Ppublishing.space.token=${{ secrets.PUBLISHING_SPACE_TOKEN }}
120 changes: 68 additions & 52 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@file:Suppress("UNUSED_VARIABLE")

import de.undercouch.gradle.tasks.download.Download
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
import ru.mipt.npm.gradle.Maturity
import org.jetbrains.kotlin.konan.target.HostManager
import space.kscience.kmath.gsl.codegen.matricesCodegen
import space.kscience.kmath.gsl.codegen.vectorsCodegen
import java.net.URL
Expand All @@ -20,23 +20,25 @@ version = "0.3.0-dev-3"
repositories {
mavenCentral()
maven("https://repo.kotlin.link")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
}

kotlin {
explicitApi()

data class DownloadLinks(val gsl: String?)

val osName = System.getProperty("os.name")
val isWindows = osName.startsWith("Windows")
val nativeTargets = setOf(linuxX64(), mingwX64(), macosX64())

val (nativeTarget, downloadLinks) = when {
osName == "Linux" -> linuxX64() to DownloadLinks(
val downloadLinks = when(HostManager.hostOs()) {
"linux" -> DownloadLinks(
gsl = "https://anaconda.org/conda-forge/gsl/2.7/download/linux-64/gsl-2.7-he838d99_0.tar.bz2",
)

isWindows -> mingwX64() to DownloadLinks(
gsl = null,
"windows" -> DownloadLinks(gsl = null)

"osx" -> DownloadLinks(
gsl = "https://anaconda.org/conda-forge/gsl/2.7/download/osx-64/gsl-2.7-h93259b0_0.tar.bz2"
)

else -> {
Expand All @@ -48,55 +50,14 @@ kotlin {
val thirdPartyDir =
File("${System.getProperty("user.home")}/.konan/third-party/kmath-gsl-${project.property("version")}")

val main by nativeTarget.compilations.getting

val test by nativeTarget.compilations.getting {
defaultSourceSet.dependsOn(main.defaultSourceSet)
}

val libgsl by main.cinterops.creating

sourceSets {
all {
with(languageSettings) {
progressiveMode = true
useExperimentalAnnotation("kotlin.time.ExperimentalTime")
}
}

commonMain {
dependencies {
api("space.kscience:kmath-complex:0.3.0-dev-12")
}
}

val nativeMain by creating {
val codegen by tasks.creating {
matricesCodegen(kotlin.srcDirs.first().absolutePath + "/_Matrices.kt")
vectorsCodegen(kotlin.srcDirs.first().absolutePath + "/_Vectors.kt")
}

kotlin.srcDirs(files().builtBy(codegen))
dependsOn(commonMain.get())
}

val nativeTest by creating {
dependsOn(nativeMain)
dependsOn(commonTest.get())
}

main.defaultSourceSet.dependsOn(nativeMain)
test.defaultSourceSet.dependsOn(nativeTest)
}

val downloadGsl by tasks.creating(Download::class) {
if (downloadLinks.gsl == null) {
enabled = false
return@creating
}

src(downloadLinks.gsl)
dest(File(thirdPartyDir, "libgsl.tar.bz2"))
dest(thirdPartyDir.resolve("libgsl.tar.bz2"))
overwrite(false)
}

Expand All @@ -112,7 +73,7 @@ kotlin {
}

val writeDefFile by tasks.creating {
val file = libgsl.defFile
val file = projectDir.resolve("src/nativeInterop/cinterop/libgsl.def")
file.parentFile.mkdirs()
if (!file.exists()) file.createNewFile()

Expand All @@ -125,6 +86,11 @@ kotlin {
staticLibraries.linux=libgsl.a libgslcblas.a
compilerOpts.linux=-I${thirdPartyDir}/include/
libraryPaths.linux=${thirdPartyDir}/lib/

linkerOpts.osx=-L/opt/local/lib -L/usr/local/lib -lblas
staticLibraries.osx=libgsl.a libgslcblas.a
compilerOpts.osx=-I${thirdPartyDir}/include/
libraryPaths.osx=${thirdPartyDir}/lib/

linkerOpts.mingw=-LC:/msys64/mingw64/lib/ -LC:/msys64/mingw64/bin/
staticLibraries.mingw=libgsl.a libgslcblas.a
Expand All @@ -141,7 +107,43 @@ kotlin {
dependsOn(extractGsl)
}

tasks[libgsl.interopProcessingTaskName].dependsOn(writeDefFile)
sourceSets {
all {
with(languageSettings) {
progressiveMode = true
useExperimentalAnnotation("kotlin.time.ExperimentalTime")
}
}

commonMain {
dependencies {
api("space.kscience:kmath-complex:0.3.0-dev-12")
}
}

val nativeMain by creating {
val codegen by tasks.creating {
matricesCodegen(kotlin.srcDirs.first().resolve("_Matrices.kt"))
vectorsCodegen(kotlin.srcDirs.first().resolve("_Vectors.kt"))
}

kotlin.srcDirs(files().builtBy(codegen))
dependsOn(commonMain.get())
}

val nativeTest by creating {
dependsOn(commonTest.get())
}

configure(nativeTargets) {
val main by compilations.getting
val test by compilations.getting
main.defaultSourceSet.dependsOn(nativeMain)
test.defaultSourceSet.dependsOn(nativeTest)
val libgsl by main.cinterops.creating
tasks[libgsl.interopProcessingTaskName].dependsOn(writeDefFile)
}
}

targets.all {
compilations.all {
Expand All @@ -150,6 +152,20 @@ kotlin {
}
}

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.CInteropProcess> {
onlyIf {
konanTarget == HostManager.host
}
}

withType<AbstractKotlinNativeCompile<*, *>> {
onlyIf {
compilation.konanTarget == HostManager.host
}
}
}

readme {
description = "Linear Algebra classes implemented with GNU Scientific Library"
maturity = Maturity.PROTOTYPE
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/matricesCodegen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private fun Appendable.createMatrixClass(
/**
* Generates matrices source code for kmath-gsl.
*/
fun matricesCodegen(outputFile: String): Unit = File(outputFile).run {
fun matricesCodegen(outputFile: File): Unit = outputFile.run {
parentFile.mkdirs()
writer().use {
it.appendLine("package space.kscience.kmath.gsl")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/vectorsCodegen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private fun Appendable.createVectorClass(
/**
* Generates vectors source code for kmath-gsl.
*/
fun vectorsCodegen(outputFile: String): Unit = File(outputFile).run {
fun vectorsCodegen(outputFile: File): Unit = outputFile.run {
parentFile.mkdirs()

writer().use { w ->
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
kotlin.code.style=official
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.stability.nowarn=true
kotlin.native.enableDependencyPropagation=false
kotlin.native.ignoreDisabledTargets=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
org.gradle.parallel=true
systemProp.org.gradle.internal.publish.checksums.insecure=true
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
maven("https://repo.kotlin.link")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
}

plugins {
id("ru.mipt.npm.gradle.project") version "0.10.1"
id("de.undercouch.download") version "4.1.2"
kotlin("multiplatform") version "1.5.21"
kotlin("multiplatform") version "1.5.30-RC-161"
}
}

Expand Down