-
Notifications
You must be signed in to change notification settings - Fork 361
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
Cross compilation to Windows - link time evaluation #3851
Comments
I am not sure we support cross compile well based on some of my knowledge about the In general, you need to install windows tools on Linux so your compiler can have all the windows headers and libraries available. When the Scala Native tools is using the correct tools it should take the correct branch above. Here is something I grabbed that may help - https://swarminglogic.com/article/2014_11_crosscompile |
Thank you for your quick response!
Yes, I do have a toolchain and the headers available that is able to target Windows (I am using zig cc). And compilation is not the problem... linking the final executable is. I thought that link time evaluation is carried out by scala-native, before producing LLVM assembly which is later compiled by clang to machine code. So it should only depend on the targetTriple setting and emit Windows specific code, right? A small experiment: import scala.scalanative.meta.LinktimeInfo.isWindows
import scalanative.unsafe.*
package foo {
@extern
object system:
@name("foo_system_is_windows")
def win: CInt = extern
@name("foo_system_is_unix")
def unix: CInt = extern
}
object Main {
def main(args: Array[String]): Unit =
if isWindows then
println(foo.system.win)
else
println(foo.system.unix)
} Trying to nativeLink that program fails with:
I would expect it to fail with an undefined symbol It seems that link time evaluation is somewhat broken here. $ rg foo_system_is_
generated/494ee56d.ll
746:declare i32 @"foo_system_is_unix"()
760: %_4000003 = call i32 @"foo_system_is_unix"() As you can see, it took the second branch, not the first one. |
That is correct then I think. I don't know what your C helper functions look like. Your C helper function This is the glue code issue as far as I understand. See this and the next section - https://scala-native.org/en/latest/user/native.html#experimental-deployment-descriptor-for-passing-settings-to-the-compiler |
Hah, i just found this comment:
I'll try with a four parts triplet when I'm at my computer again. |
I'd be curious to see your configuration once you get to that point. I think @lolgab tried |
OK, using $ rg foo_system_is_
generated/494ee56d.ll
772:declare i32 @"foo_system_is_windows"()
786: %_4000003 = call i32 @"foo_system_is_windows"() There is no mention of The only complication is that zig cc does not support this sort of triplet... 😄 but I can work around that.
Currently it's quite a hack. I'll give an update when I have something to share. However, I do cross compile my project to arm64 Linux and x86_64 and arm64 Darwin; see https://github.com/avdv/scalals/blob/main/.github/crosscompile |
Since this is windows |
Hi.
I am trying to compile my project on Linux to Windows, arch is the same: x86_64.
I have set the target triplet to
x86_64-windows-gnu
.I get linker error about
scalanative__sc_nprocessors_onln
,sysconf
andsched_yield
:(there are more, but I save these for another day ;-))
I am using scala-native 0.5.2-RC2 currently.
Looking at
javalib/src/main/scala/java/lang/Runtime.scala
:my understanding is that it should take the first branch and call
GetSystemInfo
. Apparently it takes the second branch which leads to the errors.Any help would be much appreciated.
The text was updated successfully, but these errors were encountered: