Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Preliminary tvOS support #3303

Merged
merged 1 commit into from
Sep 7, 2019
Merged

Preliminary tvOS support #3303

merged 1 commit into from
Sep 7, 2019

Conversation

sbogolepov
Copy link
Contributor

No description provided.

contents.append(when (target.family) {
Family.IOS -> """
| <key>MinimumOSVersion</key>
| <string>$minimumOsVersion</string>
| <key>UIDeviceFamily</key>
| <array>
| <integer>1</integer>
| <integer>2</integer>
| $uiDeviceFamilyValues
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this emit proper indent for second uiDeviceFamilyValues line?

| </array>

""".trimMargin()
Family.OSX -> ""
else -> error(target)
})

if (target == KonanTarget.IOS_ARM64) {
if (target.architecture == Architecture.ARM64) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Xcode emit UIRequiredDeviceCapabilities with arm64 for tvOS arm64 device framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's incorrect. 👍


private val KonanConfig.bitcodeEmbeddingMode: Mode
get() = when {
shouldForceBitcodeEmbedding() -> if (debug) Mode.MARKER else Mode.FULL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if CLI compiler driver should do this.
Does clang enforce bitcode for tvOS?

Copy link
Contributor Author

@sbogolepov sbogolepov Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, it's a responsibility of a build system.

Does clang enforce bitcode for tvOS?

No.

@@ -18,6 +19,13 @@ internal fun determineLinkerOutput(context: Context): LinkerOutputKind =
else -> TODO("${context.config.produce} should not reach native linker stage")
}

// TODO: Move to a more appropriate place.
internal val KonanTarget.isAppleTarget: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name doesn't reflect the actual conditions that need to be checked on its use sites.
This is generally more like IsThisParticularKindOfObjCInteropEnabled.
I would prefer using old target-family-based approach for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you have short-term plans to add more relevant target families of course.

Copy link
Contributor Author

@sbogolepov sbogolepov Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should introduce Family.TVOS, Family.WATCHOS because different flavours of iOS have different platform libs and runtime libraries (compiler_rt.*). And when over all Apple targets is getting kinda cumbersome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean platform libraries are deduced from the family in

file("src/platform/${getVisibleName(target.family)}")
? This could be worked around (like hack for MIPS zlib), but indeed may be a good idea to use OS family as identity for the set of platform libs.

Copy link
Contributor Author

@sbogolepov sbogolepov Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's one of the reasons.

internal val KonanTarget.isAppleTarget: Boolean
get() = family == Family.IOS || family == Family.OSX

internal val KonanTarget.isTvOs: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTvOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to isTvOsBased. Will be removed with introduction of Family.TVOS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, isTvOS is good. I mean that s should probably be capital.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Anyway, isTvOsBased feels a bit better since target is not an OS :)

@@ -131,9 +150,10 @@ open class FrameworkTest : DefaultTask() {
val bitcodeBuildTool = "${configurables.absoluteAdditionalToolsDir}/bin/bitcode-build-tool"
val ldPath = "${configurables.absoluteTargetToolchain}/usr/bin/ld"
val sdk = when (testTarget) {
KonanTarget.IOS_X64 -> return // bitcode-build-tool doesn't support iPhone Simulator.
KonanTarget.IOS_X64, KonanTarget.TVOS_X64 -> return // bitcode-build-tool doesn't support iPhone Simulator.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should be updated too.

@@ -69,6 +69,12 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
KonanTarget.IOS_ARM64 ->
listOf("-stdlib=libc++", "-arch", "arm64", "-isysroot", absoluteTargetSysRoot, "-miphoneos-version-min=9.0.0")

KonanTarget.TVOS_ARM64 ->
listOf("-stdlib=libc++", "-arch", "arm64", "-isysroot", absoluteTargetSysRoot, "-mtvos-version-min=12.2")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use older version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have osVersionMin.tvos_x64 and such?

if (version1[index] < version2[index]) return -1;
if (version1[index] > version2[index]) return 1;
}
return when {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it different from

return version1.size.compareTo(version2.size)

?

@@ -136,19 +136,22 @@ open class MacOSBasedLinker(targetProperties: AppleConfigurables)
private val dsymutil = "$absoluteLlvmHome/bin/llvm-dsymutil"

private fun provideCompilerRtLibrary(libraryName: String): String? {
val suffix = if (libraryName.isNotEmpty() && target == KonanTarget.IOS_X64) {
"iossim"
val prefix = when (val family = target.family) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have when over targets?
This would be simpler and more discoverable.


linkerNoDebugFlags.tvos_arm64 = -S
linkerDynamicFlags.tvos_arm64 = -dylib
linkerKonanFlags.tvos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 11.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different SDK versions for tvos_arm64 and tvos_x64.

@@ -247,15 +248,15 @@ internal val ObjCContainer.classOrProtocol: ObjCClassOrProtocol
*/
internal fun Type.isStret(target: KonanTarget): Boolean {
val unwrappedType = this.unwrapTypedefs()
return when (target) {
KonanTarget.IOS_ARM64 ->
return when (target.architecture) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking only architecture here is wrong, as targets with same architecture can have different ABIs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, guess current approach with explicit selection seems better fitting.

val sourceFileExtension = when (target.family) {
Family.OSX, Family.IOS -> {
val sourceFileExtension = when {
target.isAppleTarget -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess previous version was readable enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we introduce Family.TVOS, Family.WATCHOS then it will be replaced with something like target.family.isAppleFamily/ isDarwinBased.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TVOS and WATCHOS are pretty much the same as IOS, so why not just stick this way.

@@ -0,0 +1,63 @@
package org.jetbrains.kotlin

import kotlinx.serialization.Serializable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is it indeed a good idea to depend on kotlinx.serialization. here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have dependencies on it in build-utils (see ExternalReportUtils.kt) and I don't think it can cause any trouble.

@olonho
Copy link
Contributor

olonho commented Sep 3, 2019

What about platform libs?

@sbogolepov
Copy link
Contributor Author

I suggest to add them separately to make review easier.

version1.size == version2.size -> 0
version1.size < version2.size -> -1
else -> 1
if (version1[index] < version2[index]) return -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use compareTo here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we want to continue iteration in case of equality.


KonanTarget.IOS_ARM32 ->
listOf("-stdlib=libc++", "-arch", "armv7", "-isysroot", absoluteTargetSysRoot, "-miphoneos-version-min=9.0.0")
listOf("-stdlib=libc++", "-arch", "armv7", "-isysroot", absoluteTargetSysRoot, "-miphoneos-version-min=$osVersionMin")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't osVersionMin actually differ from "9.0.0"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's 9.0. What kind of problem may it cause?

// 1 - iPhone
// 2 - iPad
// 3 - AppleTV
val uiDeviceFamilyValues = if (target.isTvOsBased) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will anyway turn into when over target (or target family) after adding watchOS, making isTvOsBased unnecessary. Then why not just use this fact?

| $uiDeviceFamilyValues
${uiDeviceFamilyValues.joinToString(separator = "\n") {
"| <integer>$it</integer>"
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indent?

@@ -16,6 +16,7 @@

package org.jetbrains.kotlin.native.interop.gen

import org.jetbrains.kotlin.konan.target.Architecture
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import.

@@ -248,19 +249,24 @@ internal val ObjCContainer.classOrProtocol: ObjCClassOrProtocol
internal fun Type.isStret(target: KonanTarget): Boolean {
val unwrappedType = this.unwrapTypedefs()
return when (target) {
KonanTarget.IOS_ARM64 ->
KonanTarget.IOS_ARM64,
KonanTarget.TVOS_ARM64 ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, have you verified that tvOS arm64 ABI doesn't use stret too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

KonanTarget.IOS_X64,
KonanTarget.MACOS_X64,
KonanTarget.WATCHOS_X64,
KonanTarget.TVOS_X64 -> when (unwrappedType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that watchOS and tvOS simulators use regular macOS x86_64 ABI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@sbogolepov sbogolepov force-pushed the tvos_support branch 3 times, most recently from 9245a93 to a47d3c6 Compare September 5, 2019 12:23
| <key>MinimumOSVersion</key>
| <string>$minimumOsVersion</string>
| <key>UIDeviceFamily</key>
| <array>
| <integer>1</integer>
| <integer>2</integer>
|$xmlValues
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second line doesn't have | prefix. Does this work properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

addEmptyMarker(llvm, "konan_llvm_cmdline", "__LLVM,__cmdline")
private val KonanConfig.bitcodeEmbeddingMode: Mode
get() = configuration.get(KonanConfigKeys.BITCODE_EMBEDDING_MODE)!!.also {
// TODO: We cannot produce programs due to `-alias` linked flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so why not fix alias with LLVM API call as suggested in #3288?

@sbogolepov sbogolepov merged commit 237b7ef into master Sep 7, 2019
@sbogolepov sbogolepov deleted the tvos_support branch September 7, 2019 05:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants