Hi Everyone! After years using mac and Linux I hav...
# ktor
s
Hi Everyone! After years using mac and Linux I have stepped in to a new role with a windows box. Have not used windows in years! It's been nice in some places. Windows Terminal has been good and powershell looks really interesting(not that I was not able to use it before). I will be using ktor for the first time too. I was wondering if anyone had any luck building from source on windows? Works on Windows Subsystem for Linux however in windows there are some platform deps in utils io that require posix. Have I missed something to setup the build for native windows or is this not supported at this stage? If not supported is there some work that could be done to support native windows or is too much built around posix API's?
b
You need cygwin or msys2 with posix libs installed i think
👍 2
Basically build on mingw, rather than plain old windows
👍 2
s
Thanks @Big Chungus I have never used either so I will check them out. WSL is working ok but there are file sharing issues between the host and linux. Will have a look at these today as it looks like they don't require an emulation layer
m
AFAIK from WSL Kotlin builds Linux apps, not native Windows. If you want posix shell - install MSYS2 and run in their shell. And in it -
pacman
as package manager. As for examples - https://github.com/msink/hello-curl builds static app for both 32 and 64 bit native Windows, locally and on GitHub CI.
In fact K/N Windows sysroot itself is built from MSYS2, so compatibility with anything built or installed from MSYS2 shell is maximal.
s
Hey Mike, Thanks for the reply. I have downloaded and installed MSYS2. I get the same result there as I get in cygwin as I get in native powershell which is as follows.
Copy code
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\errors\PosixErrors.kt: (11, 30): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (78, 27): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (78, 27): Type mismatch: inferred type is KX_SOCKET /* = SOCKET */ but Int was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (93, 17): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (93, 17): Type mismatch: inferred type is KX_SOCKET /* = SOCKET */ but Int was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (98, 12): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (98, 17): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (174, 27): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (174, 27): Type mismatch: inferred type is KX_SOCKET /* = SOCKET */ but Int was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (196, 31): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (196, 31): Type mismatch: inferred type is KX_SOCKET /* = SOCKET */ but Int was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (196, 94): Type mismatch: inferred type is CValuesRef<IntVarOf<KX_SOCKADDR_LEN /* = Int */>> but CValuesRef<socklen_tVar /* = UIntVarOf<UInt> */>? was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (218, 29): Cannot access class 'platform.posix.SOCKET'. Check your module classpath for missing or conflicting dependencies
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (218, 29): Type mismatch: inferred type is KX_SOCKET /* = SOCKET */ but Int was expected
e: C:\Users\StewartMatheson\Documents\NotInventedHere\ktor\ktor-io\posix\src\io\ktor\utils\io\streams\PosixIo.kt: (218, 91): Type mismatch: inferred type is KX_SOCKADDR_LEN /* = Int */ but socklen_t /* = UInt */ was expected
I tried building your hello-curl repo too
I get the following
Copy code
> Task :cinteropLibcurlMingw32 FAILED
Exception in thread "main" java.lang.Error: C:\Users\STEWAR~1\AppData\Local\Temp\1473305343316438614.c:1:10: fatal error: 'curl/curl.h' file not found
        at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
        at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:1003)
        at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:992)
        at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:268)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:76)
        at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
        at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:38)
        at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:60)
So I'm wondering if there is some extra paths I have to setup perhaps.
m
Did you install mingw-w64-x86_64-curl and mingw-w64-i686-curl?
pacman -S mingw-w64-x86_64-curl mingw-w64-i686-curl
in MSYS2 shell.
And you need to add -L parameter to them in your linkerOpts.
includeDirs too
s
Hey @msink installing the two packages got the hello curl example compiling. Thanks. I did not have to tell the compiler about any extra paths either. Issue persists with ktor though. I will dig a little deeper today. At this point I suspect its something to do with c interop not binding correctly as the classes that are erroring are all as I understand provided by a
.def
file in kotlin native. Perhaps the cinterops are not even running. This might happen if
nativeTargets
in
build.gradle.kts
in the ktor-io project is not set. I will start debugging that today. Any other suggests are more than welcome.
Copy code
nativeTargets.forEach {
        it.compilations {
            val main by getting {
                cinterops {
                    val bits by creating { defFile = file("posix/interop/bits.def") }
                    val sockets by creating { defFile = file("posix/interop/sockets.def") }
                }
            }
            val test by getting {
                cinterops {
                    val testSockets by creating { defFile = file("posix/interop/testSockets.def") }
                }
            }
        }
    }
m
Seems that building Ktor on windows is just broken.
Cloned from github, on
main
and
1.6.0
- build failed with exactly same errors, on tag
1.5.4
- build passed.
Wonder how
1.6.0
for windows was published...
Well, I was wrong
:ktor-io:compilePosixMainKotlinMetadata
failed on
1.5.4
too, but after 30 minutes of various tests.