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

Fixed build on Windows. Refactored Gradle scripts. #621

Closed
wants to merge 11 commits into from
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 0 additions & 19 deletions base-portable/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ?: "<anonymous>")
}
}
37 changes: 37 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 0 additions & 19 deletions plot-base-portable/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
22 changes: 4 additions & 18 deletions plot-builder-portable/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand Down
19 changes: 0 additions & 19 deletions plot-common-portable/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
19 changes: 0 additions & 19 deletions plot-config-portable/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions python-extension/build.gradle
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
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 {
staticLib {
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
}
Expand Down
8 changes: 7 additions & 1 deletion python-package-build/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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}"
}


Expand Down
19 changes: 14 additions & 5 deletions python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading