diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index de121fe..894c4a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b48ee11..0be1744 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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 @@ -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 }} diff --git a/build.gradle.kts b/build.gradle.kts index f3f3a5a..92635f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -20,6 +20,7 @@ version = "0.3.0-dev-3" repositories { mavenCentral() maven("https://repo.kotlin.link") + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") } kotlin { @@ -27,16 +28,17 @@ kotlin { 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 -> { @@ -48,47 +50,6 @@ 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 @@ -96,7 +57,7 @@ kotlin { } src(downloadLinks.gsl) - dest(File(thirdPartyDir, "libgsl.tar.bz2")) + dest(thirdPartyDir.resolve("libgsl.tar.bz2")) overwrite(false) } @@ -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() @@ -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 @@ -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 { @@ -150,6 +152,20 @@ kotlin { } } +tasks { + withType { + onlyIf { + konanTarget == HostManager.host + } + } + + withType> { + onlyIf { + compilation.konanTarget == HostManager.host + } + } +} + readme { description = "Linear Algebra classes implemented with GNU Scientific Library" maturity = Maturity.PROTOTYPE diff --git a/buildSrc/src/main/kotlin/matricesCodegen.kt b/buildSrc/src/main/kotlin/matricesCodegen.kt index 5c65cce..5318485 100644 --- a/buildSrc/src/main/kotlin/matricesCodegen.kt +++ b/buildSrc/src/main/kotlin/matricesCodegen.kt @@ -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") diff --git a/buildSrc/src/main/kotlin/vectorsCodegen.kt b/buildSrc/src/main/kotlin/vectorsCodegen.kt index dfebc8f..9f5955f 100644 --- a/buildSrc/src/main/kotlin/vectorsCodegen.kt +++ b/buildSrc/src/main/kotlin/vectorsCodegen.kt @@ -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 -> diff --git a/gradle.properties b/gradle.properties index 3109acd..d0d3b35 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/settings.gradle.kts b/settings.gradle.kts index 1109539..e91a95c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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" } }