diff --git a/.gitignore b/.gitignore index 4cf1c4c4f84..f255b385971 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,10 @@ build_settings.yml # Autogenerated folder with yarn.lock file kotlin-js-store + +# intermediate build files on Windows +python-package/kotlin-bridge/*.def +python-package/kotlin-bridge/lets_plot_kotlin_bridge.o + +# VSCode service directiry +.vscode diff --git a/base-portable/build.gradle b/base-portable/build.gradle index bc3c7e0ed91..c747434f222 100644 --- a/base-portable/build.gradle +++ b/base-portable/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -17,23 +15,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies { diff --git a/base-portable/src/linuxArm64Main/kotlin/jetbrains/datalore/base/logging/PortableLogging.kt b/base-portable/src/linuxArm64Main/kotlin/jetbrains/datalore/base/logging/PortableLogging.kt new file mode 100644 index 00000000000..a1508e9c463 --- /dev/null +++ b/base-portable/src/linuxArm64Main/kotlin/jetbrains/datalore/base/logging/PortableLogging.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2020. JetBrains s.r.o. + * Use of this source code is governed by the MIT license that can be found in the LICENSE file. + */ + +package jetbrains.datalore.base.logging + +import kotlin.reflect.KClass + +actual object PortableLogging { + actual fun logger(cl: KClass<*>): Logger { + return PrintlnLogger(cl.simpleName ?: "") + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index c538de808c8..21d73c36637 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,8 @@ plugins { id "io.codearte.nexus-staging" } +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform + project.ext.letsPlotTaskGroup = 'lets-plot' def include_sources_letsPlotJvmCommon = [ @@ -177,7 +179,42 @@ task publishKotlinApiDependenciesToMavenRepository { group project.letsPlotTaskGroup } + subprojects { + // Configure Kotlin Native build. + if (name in [ + 'base-portable', + 'plot-base-portable', + 'plot-builder-portable', + 'plot-common-portable', + 'plot-config-portable', + 'test-common', + 'vis-svg-portable', + ]) { + apply plugin: "org.jetbrains.kotlin.multiplatform" + + def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() + def currentOsArch = DefaultNativePlatform.getCurrentArchitecture() + + kotlin{ + if (project.buildSettings.build_python_extension) { + if (currentOs.macOsX & currentOsArch.amd64) { + macosX64() + } else if (currentOs.macOsX & currentOsArch.arm) { + macosArm64() + } else if (currentOs.linux & currentOsArch.amd64) { + linuxX64() + } else if (currentOs.linux & currentOsArch.arm) { + linuxArm64() + } else if (currentOs.windows) { + mingwX64() + } else { + throw new Exception("Unsupported platform.") + } + } + } + } + // Configure publishing for projects which "Lets-Plot Kotlin API" depends on. if (name in [ 'plot-base-portable', diff --git a/gradle.properties b/gradle.properties index 9a383f5eade..cace1b4cc0b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -39,3 +39,5 @@ org.gradle.jvmargs=-Xmx2g kotlin.js.compiler=both kotlin.mpp.stability.nowarn=true kotlin.jvm.target.validation.mode=error +# Switched to legacy memory manager to prevent runtime errors on Windows. +kotlin.native.binary.memoryModel=strict diff --git a/plot-base-portable/build.gradle b/plot-base-portable/build.gradle index 54ee1ec3c54..019b19daa64 100644 --- a/plot-base-portable/build.gradle +++ b/plot-base-portable/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -16,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies { diff --git a/plot-builder-portable/build.gradle b/plot-builder-portable/build.gradle index 14841179dd2..029ad60a1df 100644 --- a/plot-builder-portable/build.gradle +++ b/plot-builder-portable/build.gradle @@ -1,4 +1,7 @@ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform +/* + * Copyright (c) 2019. JetBrains s.r.o. + * Use of this source code is governed by the MIT license that can be found in the LICENSE file. + */ plugins { id "org.jetbrains.kotlin.multiplatform" @@ -11,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies { diff --git a/plot-common-portable/build.gradle b/plot-common-portable/build.gradle index 377758bed13..d330e2f90f2 100644 --- a/plot-common-portable/build.gradle +++ b/plot-common-portable/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -16,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies { diff --git a/plot-config-portable/build.gradle b/plot-config-portable/build.gradle index d939f0b9149..77b97639c47 100644 --- a/plot-config-portable/build.gradle +++ b/plot-config-portable/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -16,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies { diff --git a/plot-config-portable/src/commonTest/kotlin/plot/PlotSvgHelperTest.kt b/plot-config-portable/src/commonTest/kotlin/plot/PlotSvgHelperTest.kt index d7f6f7952cf..acfcbb111d7 100644 --- a/plot-config-portable/src/commonTest/kotlin/plot/PlotSvgHelperTest.kt +++ b/plot-config-portable/src/commonTest/kotlin/plot/PlotSvgHelperTest.kt @@ -5,7 +5,6 @@ package jetbrains.datalore.plot -import jetbrains.datalore.base.annotation.IgnoreJs import jetbrains.datalore.base.geometry.DoubleVector import jetbrains.datalore.plot.testing.EXPECTED_BUNCH_SVG import jetbrains.datalore.plot.testing.EXPECTED_SINGLE_PLOT_SVG @@ -14,14 +13,12 @@ import kotlin.test.assertEquals internal class PlotSvgHelperTest { @Test - @IgnoreJs fun svgSizeFromSinglePlotSvg() { val sizeFromSvg = PlotSvgHelper.fetchPlotSizeFromSvg(EXPECTED_SINGLE_PLOT_SVG) assertEquals(DoubleVector(400.0, 300.0), sizeFromSvg) } @Test - @IgnoreJs fun svgSizeFromGGBunchSvg() { val sizeFromSvg = PlotSvgHelper.fetchPlotSizeFromSvg(EXPECTED_BUNCH_SVG) assertEquals(DoubleVector(300.0, 150.0), sizeFromSvg) diff --git a/python-extension/build.gradle b/python-extension/build.gradle index 0488b5a279e..4476268384a 100644 --- a/python-extension/build.gradle +++ b/python-extension/build.gradle @@ -1,34 +1,33 @@ -plugins { - id "org.jetbrains.kotlin.multiplatform" - id "org.jetbrains.gradle.plugin.idea-ext" -} - - /* * Copyright (c) 2019. JetBrains s.r.o. * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.gradle.plugin.idea-ext" +} + import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() +def currentOsArch = DefaultNativePlatform.getCurrentArchitecture() kotlin { if (project.buildSettings.build_python_extension) { def target - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - target = macosArm64("native") - } else { - target = macosX64("native") - } - } else if (currentOs.isLinux()) { + if (currentOs.macOsX & currentOsArch.amd64) { + target = macosX64("native") + } else if (currentOs.macOsX & currentOsArch.arm) { + target = macosArm64("native") + } else if (currentOs.linux & currentOsArch.amd64) { target = linuxX64("native") - } else if (currentOs.isWindows()) { + } else if (currentOs.linux & currentOsArch.arm) { + target =linuxArm64("native") + } else if (currentOs.windows) { target = mingwX64("native") } else { - throw "Unsupported platform " + currentOs.displayName + throw new Exception("Unsupported platform.") } target.binaries { @@ -36,12 +35,12 @@ kotlin { baseName = "lets-plot-${project.name}" } } - target.compilations.main.cinterops { python { compilerOpts "-I${project.buildSettings.python.include_path}" } } + } else { jvm() // at least one target is required by MPP - dummy jvm target will work just fine } diff --git a/python-package-build/build.gradle b/python-package-build/build.gradle index ef6889d6d9e..b4ada18cb94 100644 --- a/python-package-build/build.gradle +++ b/python-package-build/build.gradle @@ -14,6 +14,8 @@ plugins { // ---------------------------------------- def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() +def currentOsArch = DefaultNativePlatform.getCurrentArchitecture() + //def task_group = 'lets plot' def tools_dir = "${rootDir}/tools" def python_package_dir = "${rootDir}/python-package" @@ -25,6 +27,10 @@ clean { delete python_package_dist_dir delete "${python_package_dir}/lets_plot/package_data" delete "${python_package_dir}/lets_plot.egg-info" + delete "${python_package_dir}/kotlin-bridge/kotlin_bridge.o" + delete fileTree("${python_package_dir}/kotlin-bridge/"){ + include "*.def" + } } if (project.buildSettings.enable_python_package) { @@ -59,7 +65,7 @@ if (project.buildSettings.enable_python_package) { description = 'Builds lets-plot wheel distribution with Manylinux platform for publication(python)' workingDir tools_dir - commandLine "./run_manylinux_docker.sh", "${rootDir}" + commandLine "./run_manylinux_docker.sh", "${rootDir}", "${currentOsArch}" } diff --git a/python-package/setup.py b/python-package/setup.py index 58374572948..5a874e3f6b2 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -55,18 +55,27 @@ def run(self): with open(os.path.join(root_dir, 'README.md'), encoding='utf-8') as f: long_description = f.read() -if this_system == 'Windows': - import distutils.cygwinccompiler - - distutils.cygwinccompiler.get_msvcr = lambda: [] if this_system == 'Darwin': stdcpp_lib = 'c++' # fix for "ImportError: dlopen(...) Symbol not found: _NSGenericException" on macOS extra_link = ['-framework', 'Foundation'] -else: + +elif this_system == 'Windows': + stdcpp_lib = 'stdc++' + # fix python package build with Kotlin v1.7.20 (and later) on Windows. + extra_link = ['-lbcrypt'] + # fix for "cannot find -lmsvcr140: No such file or directory" compiler error on Windows. + import distutils.cygwinccompiler + distutils.cygwinccompiler.get_msvcr = lambda: [] + +elif this_system == 'Linux': stdcpp_lib = 'stdc++' extra_link = [] + +else: + raise ValueError("Unsupported platform.") + setup(name='lets-plot', license="MIT", diff --git a/test-common/build.gradle b/test-common/build.gradle index 96acdc6ab70..46cb412daf9 100644 --- a/test-common/build.gradle +++ b/test-common/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -16,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64("native") - } else { - macosX64("native") - } - } else if (currentOs.isLinux()) { - linuxX64("native") - } else if (currentOs.isWindows()) { - mingwX64("native") - } - } - sourceSets { commonMain { dependencies { diff --git a/test-common/src/commonMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt b/test-common/src/commonMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt deleted file mode 100644 index cf059916010..00000000000 --- a/test-common/src/commonMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2020. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -expect annotation class IgnoreJs() \ No newline at end of file diff --git a/test-common/src/jsMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt b/test-common/src/jsMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt deleted file mode 100644 index aa408b7fdb0..00000000000 --- a/test-common/src/jsMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2020. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -actual typealias IgnoreJs = kotlin.test.Ignore \ No newline at end of file diff --git a/test-common/src/jvmMain/kotlin/base/annotation/IgnoreTarget.kt b/test-common/src/jvmMain/kotlin/base/annotation/IgnoreTarget.kt deleted file mode 100644 index 9e9e8585e06..00000000000 --- a/test-common/src/jvmMain/kotlin/base/annotation/IgnoreTarget.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2020. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -actual annotation class IgnoreJs \ No newline at end of file diff --git a/test-common/src/macosArm64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt b/test-common/src/macosArm64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt deleted file mode 100644 index cbeecced935..00000000000 --- a/test-common/src/macosArm64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2022. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -actual annotation class IgnoreJs actual constructor() \ No newline at end of file diff --git a/test-common/src/macosX64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt b/test-common/src/macosX64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt deleted file mode 100644 index cbeecced935..00000000000 --- a/test-common/src/macosX64Main/kotlin/jetbrains/datalore/base/annotation/IgnoreJs.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2022. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -actual annotation class IgnoreJs actual constructor() \ No newline at end of file diff --git a/test-common/src/nativeMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt b/test-common/src/nativeMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt deleted file mode 100644 index 9e9e8585e06..00000000000 --- a/test-common/src/nativeMain/kotlin/jetbrains/datalore/base/annotation/IgnoreTarget.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2020. JetBrains s.r.o. - * Use of this source code is governed by the MIT license that can be found in the LICENSE file. - */ - -package jetbrains.datalore.base.annotation - -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -actual annotation class IgnoreJs \ No newline at end of file diff --git a/vis-canvas/src/commonTest/kotlin/jetbrains/datalore/vis/canvas/CssStyleUtilTest.kt b/vis-canvas/src/commonTest/kotlin/jetbrains/datalore/vis/canvas/CssStyleUtilTest.kt index 849e1274d97..8e8f5839d26 100644 --- a/vis-canvas/src/commonTest/kotlin/jetbrains/datalore/vis/canvas/CssStyleUtilTest.kt +++ b/vis-canvas/src/commonTest/kotlin/jetbrains/datalore/vis/canvas/CssStyleUtilTest.kt @@ -5,13 +5,12 @@ package jetbrains.datalore.vis.canvas -import jetbrains.datalore.base.annotation.IgnoreJs import jetbrains.datalore.vis.canvas.CssStyleUtil.extractStyleFont import jetbrains.datalore.vis.canvas.CssStyleUtil.scaleFont import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull - +import kotlin.test.assertTrue class CssStyleUtilTest { @@ -28,18 +27,19 @@ class CssStyleUtilTest { } @Test - @IgnoreJs fun scaleSimpleFont() { + val commonExpected = "24.0px arial" + val jsExpected = "24px arial" val actual = scaleFont("12px arial", TEST_SCALE) - assertEquals("24.0px arial", actual) + assertTrue((commonExpected == actual) || (jsExpected == actual)) } @Test - @IgnoreJs fun scaleFontWithSlash() { - assertEquals("24.0px/20.0px sans-serif", scaleFont("12px/10px sans-serif", - TEST_SCALE - )) + val commonExpected = "24.0px/20.0px sans-serif" + val jsExpected = "24px/20px sans-serif" + val actual = scaleFont("12px/10px sans-serif", TEST_SCALE) + assertTrue((commonExpected == actual) || (jsExpected == actual)) } @Test diff --git a/vis-svg-portable/build.gradle b/vis-svg-portable/build.gradle index f3b0688901e..e97d5f2eab9 100644 --- a/vis-svg-portable/build.gradle +++ b/vis-svg-portable/build.gradle @@ -3,8 +3,6 @@ * Use of this source code is governed by the MIT license that can be found in the LICENSE file. */ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.gradle.plugin.idea-ext" @@ -16,23 +14,6 @@ kotlin { browser() } - if (project.buildSettings.build_python_extension) { - def currentOs = DefaultNativePlatform.getCurrentOperatingSystem() - - if (currentOs.isMacOsX()) { - def currentArch = DefaultNativePlatform.getCurrentArchitecture() - if (currentArch.displayName.contains("arm-v8")) { - macosArm64() - } else { - macosX64() - } - } else if (currentOs.isLinux()) { - linuxX64() - } else if (currentOs.isWindows()) { - mingwX64() - } - } - sourceSets { commonMain { dependencies {