|
2 | 2 | * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * Specifies what subset of Native targets to build |
7 |
| - * |
8 |
| - * ALL — all possible for compilation |
9 |
| - * HOST — host-specific ones, without cross compilation (e.g. do not build linuxX64 on macOS host) |
10 |
| - * SINGLE — only for current OS (to import into IDEA / quickly run tests) |
11 |
| - * DISABLED — disable all Native targets (useful with Kotlin compiler built from sources) |
12 |
| - * |
13 |
| - * For HOST mode, all targets are still listed in .module file, so HOST mode is useful for release process. |
14 |
| - */ |
15 |
| -enum NativeState { |
16 |
| - ALL, HOST, SINGLE, DISABLED |
17 |
| -} |
18 |
| - |
19 |
| -def getNativeState(String description) { |
20 |
| - if (description == null) return NativeState.SINGLE |
21 |
| - switch (description.toLowerCase()) { |
22 |
| - case 'all': |
23 |
| - case 'true': |
24 |
| - return NativeState.ALL |
25 |
| - case 'host': |
26 |
| - return NativeState.HOST |
27 |
| - case 'disabled': |
28 |
| - return NativeState.DISABLED |
29 |
| - // 'single', 'false', etc |
30 |
| - default: |
31 |
| - return NativeState.SINGLE |
32 |
| - } |
33 |
| -} |
34 |
| - |
35 |
| -project.ext.ideaActive = System.getProperty('idea.active') == 'true' |
36 |
| -project.ext.nativeState = getNativeState(property('native.deploy')) |
37 |
| -project.ext.singleTargetMode = project.ext.ideaActive || (project.ext.nativeState == NativeState.SINGLE) |
38 |
| - |
39 |
| -project.ext.nativeMainSets = [] |
40 |
| -project.ext.nativeTestSets = [] |
41 |
| - |
42 |
| -/** |
43 |
| - * Disables compilation but leaves the target in .module file |
44 |
| - */ |
45 |
| -def disableCompilation(targets) { |
46 |
| - configure(targets) { |
47 |
| - compilations.all { |
48 |
| - cinterops.all { project.tasks[interopProcessingTaskName].enabled = false } |
49 |
| - compileKotlinTask.enabled = false |
50 |
| - } |
51 |
| - binaries.all { linkTask.enabled = false } |
52 |
| - |
53 |
| - mavenPublication { publicationToDisable -> |
54 |
| - tasks.withType(AbstractPublishToMaven).all { |
55 |
| - onlyIf { publication != publicationToDisable } |
56 |
| - } |
57 |
| - tasks.withType(GenerateModuleMetadata).all { |
58 |
| - onlyIf { publication.get() != publicationToDisable } |
59 |
| - } |
60 |
| - } |
61 |
| - } |
62 |
| -} |
63 |
| - |
64 |
| -def getHostName() { |
65 |
| - def target = System.getProperty("os.name") |
66 |
| - if (target == 'Linux') return 'linux' |
67 |
| - if (target.startsWith('Windows')) return 'windows' |
68 |
| - if (target.startsWith('Mac')) return 'macos' |
69 |
| - return 'unknown' |
70 |
| -} |
71 |
| - |
72 | 5 | static def doesNotDependOnOkio(project) {
|
73 | 6 | return !project.name.contains("json-okio") && !project.name.contains("json-tests")
|
74 | 7 | }
|
75 | 8 |
|
76 | 9 | kotlin {
|
77 | 10 | targets {
|
78 |
| - def manager = project.ext.hostManager |
79 |
| - def linuxEnabled = manager.isEnabled(presets.linuxX64.konanTarget) |
80 |
| - def macosEnabled = manager.isEnabled(presets.macosX64.konanTarget) |
81 |
| - def winEnabled = manager.isEnabled(presets.mingwX64.konanTarget) |
82 |
| - |
83 |
| - def ideaPreset = presets.linuxX64 |
84 |
| - if (macosEnabled) ideaPreset = presets.macosX64 |
85 |
| - if (winEnabled) ideaPreset = presets.mingwX64 |
86 |
| - project.ext.ideaPreset = ideaPreset |
87 |
| - } |
88 |
| - |
89 |
| - targets { |
90 |
| - delegate.metaClass.addTarget = { preset -> |
91 |
| - def target = delegate.fromPreset(preset, preset.name) |
92 |
| - project.ext.nativeMainSets.add(target.compilations['main'].kotlinSourceSets.first()) |
93 |
| - project.ext.nativeTestSets.add(target.compilations['test'].kotlinSourceSets.first()) |
94 |
| - } |
95 |
| - } |
96 |
| - |
97 |
| - targets { |
98 |
| - if (project.ext.nativeState == NativeState.DISABLED) return |
99 |
| - |
100 |
| - String[] versionComponents = (~/[.-]/).split(compilerVersion, 4) |
101 |
| - String[] versionComponents1920 = ["1", "9", "20"] |
102 |
| - def isAtLeast1920 = Arrays.compare(versionComponents, versionComponents1920) { lhs, rhs -> |
103 |
| - (lhs as int) <=> (rhs as int) |
104 |
| - } >= 0 |
105 |
| - |
106 |
| - if (project.ext.singleTargetMode) { |
107 |
| - fromPreset(project.ext.ideaPreset, 'native') |
108 |
| - } else { |
109 |
| - // According to https://kotlinlang.org/docs/native-target-support.html |
110 |
| - // Tier 1 |
111 |
| - addTarget(presets.linuxX64) |
112 |
| - addTarget(presets.macosX64) |
113 |
| - addTarget(presets.macosArm64) |
114 |
| - addTarget(presets.iosSimulatorArm64) |
115 |
| - addTarget(presets.iosX64) |
116 |
| - |
117 |
| - // Tier 2 |
118 |
| - if (doesNotDependOnOkio(project)) { |
119 |
| - addTarget(presets.linuxArm64) |
120 |
| - } |
121 |
| - addTarget(presets.watchosSimulatorArm64) |
122 |
| - addTarget(presets.watchosX64) |
123 |
| - addTarget(presets.watchosArm32) |
124 |
| - addTarget(presets.watchosArm64) |
125 |
| - addTarget(presets.tvosSimulatorArm64) |
126 |
| - addTarget(presets.tvosX64) |
127 |
| - addTarget(presets.tvosArm64) |
128 |
| - addTarget(presets.iosArm64) |
129 |
| - |
130 |
| - // Tier 3 |
131 |
| - if (doesNotDependOnOkio(project)) { |
132 |
| - addTarget(presets.androidNativeArm32) |
133 |
| - addTarget(presets.androidNativeArm64) |
134 |
| - addTarget(presets.androidNativeX86) |
135 |
| - addTarget(presets.androidNativeX64) |
136 |
| - addTarget(presets.watchosDeviceArm64) |
137 |
| - } |
138 |
| - |
139 |
| - addTarget(presets.mingwX64) |
140 |
| - |
141 |
| - // Deprecated, but were provided by kotlinx.serialization; can be removed only in 1.9.20 release. |
142 |
| - if (!isAtLeast1920) { |
143 |
| - addTarget(presets.watchosX86) |
144 |
| - |
145 |
| - if (doesNotDependOnOkio(project)) { |
146 |
| - addTarget(presets.iosArm32) |
147 |
| - addTarget(presets.linuxArm32Hfp) |
148 |
| - addTarget(presets.mingwX86) |
149 |
| - } |
150 |
| - } |
151 |
| - |
152 |
| - } |
153 |
| - |
154 |
| - if (project.ext.nativeState == NativeState.HOST) { |
155 |
| - // linux targets that can cross-compile on all three hosts |
156 |
| - def linuxCrossCompileTargets = isAtLeast1920 ? [presets.linuxX64] : [presets.linuxX64, presets.linuxArm32Hfp, presets.linuxArm64] |
157 |
| - if (getHostName() != "linux") { |
158 |
| - disableCompilation(linuxCrossCompileTargets) |
159 |
| - } |
160 |
| - } |
161 |
| - } |
162 |
| - |
163 |
| - |
164 |
| - sourceSets { |
165 |
| - nativeMain { dependsOn commonMain } |
166 |
| - // Empty source set is required in order to have native tests task |
167 |
| - nativeTest { dependsOn commonTest } |
168 |
| - |
169 |
| - if (!project.ext.singleTargetMode) { |
170 |
| - configure(project.ext.nativeMainSets) { |
171 |
| - dependsOn nativeMain |
172 |
| - } |
173 |
| - |
174 |
| - configure(project.ext.nativeTestSets) { |
175 |
| - dependsOn nativeTest |
176 |
| - } |
| 11 | + targetHierarchy.default() |
| 12 | + |
| 13 | + // According to https://kotlinlang.org/docs/native-target-support.html |
| 14 | + // Tier 1 |
| 15 | + linuxX64() |
| 16 | + macosX64() |
| 17 | + macosArm64() |
| 18 | + iosSimulatorArm64() |
| 19 | + iosX64() |
| 20 | + |
| 21 | + // Tier 2 |
| 22 | + watchosSimulatorArm64() |
| 23 | + watchosX64() |
| 24 | + watchosArm32() |
| 25 | + watchosArm64() |
| 26 | + tvosSimulatorArm64() |
| 27 | + tvosX64() |
| 28 | + tvosArm64() |
| 29 | + iosArm64() |
| 30 | + linuxArm64() |
| 31 | + |
| 32 | + // Tier 3 |
| 33 | + mingwX64() |
| 34 | + // https://github.com/square/okio/issues/1242#issuecomment-1759357336 |
| 35 | + if (doesNotDependOnOkio(project)) { |
| 36 | + androidNativeArm32() |
| 37 | + androidNativeArm64() |
| 38 | + androidNativeX86() |
| 39 | + androidNativeX64() |
| 40 | + watchosDeviceArm64() |
177 | 41 | }
|
178 | 42 | }
|
179 | 43 | }
|
0 commit comments