使用 scala-native 构建 iOS 应用程序

Posted

技术标签:

【中文标题】使用 scala-native 构建 iOS 应用程序【英文标题】:Building an iOS application with scala-native 【发布时间】:2017-04-22 13:19:00 【问题描述】:

我正在尝试使用 scala-native 在 os x 上构建一个 ios 应用程序,并且在进行 sbt 构建时遇到了许多问题。欢迎任何有关如何操作的提示。

我设置build.sbt,使用Xcode目录存放iOS文件,如下:

    nativeCompileOptions := Seq("-v",  
    "-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk")

    nativeLinkingOptions := Seq("-v",
    "-I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include",
    "-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib",
    "-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk")

当对 nativelib 中包含的 c 文件(例如,wrap、time、dyndispatch、gc、posix、eh (c++)、unwind 和 target)进行初始编译时,我看不到添加选项的方法sbt 编译命令行。由于这些编译创建 .o 文件(不是 .ll),因此目标 一旦这些编译完成,平台就已经设置好了。 编译示例如下:

/Users/nnovod/tools/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang  
-I/usr/local/include  
-I/Users/nnovod/tools/clang+llvm-4.0.0-x86_64-apple-darwin/include  
-c  
/Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/posix.c  
-o
/Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/posix.c.o  

在编译 scala-native 代码时,我可以通过 nativeCompileOptions 添加选项并将 xcode 模拟器 sdk 目录添加为系统根目录 (-isysroot .../iPhoneSimulator.10.3.sdk) 似乎可以解决问题,尽管有关于“使用 x86_64-apple-ios10.3.0 覆盖模块目标三元组”的警告

链接时有两个问题:a)找不到 gc 库(我需要为 iOS 构建一个吗?Boehm 的交叉构建?) b)为 MacOS 完成的初始编译,现在与那些冲突为 iOS 完成。以下是 sbt 生成的链接命令:

"/usr/bin/ld" -demangle -lto_library /Users/nnovod/tools/clang+llvm-4.0.0-x86_64-apple-darwin/lib/libLTO.dylib -dynamic -arch x86_64 -ios_simulator_version_min 10.3.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk -o /Users/nnovod/projects/scalaNative/target/scala-2.11/scalanative-out -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -lgc /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__const.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__dispatch.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__empty.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__extern.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__instance.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/__main.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/example.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.io.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.lang.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.lang.reflect.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.nio.charset.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.nio.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/java.util.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/niocharset.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.collection.generic.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.collection.immutable.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.collection.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.collection.mutable.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.collection.script.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.compat.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.io.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.math.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.reflect.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.runtime.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.scalanative.native.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.scalanative.runtime.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.util.control.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.util.hashing.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/ll/scala.util.ll.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/dyndispatch.c.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/eh.cpp.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/gc.c.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/posix.c.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/time.c.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/unwind.c.o /Users/nnovod/projects/scalaNative/target/scala-2.11/nativelib/wrap.c.o -lc++ -lSystem /Users/nnovod/tools/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../lib/clang/4.0.0/lib/darwin/libclang_rt.ios.a

这一切都错了吗?我不是 sbt 专家,但我需要对 scala-native sbt 代码进行重大修改吗?

谢谢。

【问题讨论】:

你有没有解决过这个问题,还是放弃了? 【参考方案1】:

从 LLVM IR 的角度来看,这应该是可能的并且实际上几乎得到了支持(假设是豚鼠通过平滑粗糙边缘的调试而苦苦挣扎)。但是从让您可以从 Scala Native 调用的 Apple 框架的角度来看,您将无法从 Scala Native 中使用这些 Apple 框架,这意味着在使用 Scala Native其当前的生态系统是一种在 iPhone、iPad、Apple Watch、Apple TV 或 Mac 上编写 iOS/iPadOS/MacOS 应用程序的方式。

【讨论】:

以上是关于使用 scala-native 构建 iOS 应用程序的主要内容,如果未能解决你的问题,请参考以下文章

指向 scala-native 中的指针的指针

scala-native 中的布尔字符串解析行为

如何使用 Flutter 构建 iOS AdHoc 应用

使用 VSTS 构建 ionic 应用并将其部署到 android 和 IOS

Codemagic IOS 构建 - 无法构建 iOS 应用程序 - 是啥原因?

无法使用 phonegap 构建 iOS 应用程序