Windows equivalent of binaryTarget?

I'm experimenting with a cross platform swift project that needs to link a 3rd party library. On macOS I've converted the headers and dylib into an xcframework and included it as a binaryTarget. This works great.

However, it doesn't seem as though xcframework supports windows targets, and binaryTarget doesn't support .lib/.dll directly.

What is the best way to create an executableTarget on windows that links to this dll?

Thanks,
mike

1 Like

IMO this should be an important area for SwiftPM to grow, and for now you may use a systemLibrary, and then configure the headers and linker options using a modulemap file. I suspect that an absolute lib path may be required for a portable 3rd-party library.

For DLLs you can add them to %Path% or manually copy them besides the product. This is currently not handled by SwiftPM.

I would like to see this was well. Godot swift binaries take about 13 minutes to build on my 16 core Ryzen. Are there any developments on this?

If you can deal with the unsafe flags (which will only be run if specifically building that target, I believe?)

.executableTarget(
    name: "MyGreatExecutable",
    linkerSettings: [
        .linkedLibrary("somelibrary", .when(platforms: [.windows])),
        .unsafeFlags(["-Xlinker", "-Lpath\\to\\somelibrary\\lib\\directory"], .when(platforms: [.windows])),
    ]
)

Then make sure to include the 3rd party DLL or lib "side-by-side" with the exe when distributing your executable.

2 Likes