Cross-Compiling macOS to Linux

@spevans
On the linux box, the output of readelf -aW bm | grep RUNPATH is:
Library runpath: [/usr/lib/swift/linux:/usr/lib/swift:$ORIGIN].

When you say run with LD_LIBRARY_PATH=<swift install dir>/usr/lib/swift/linux <executable> -- there's no swift on the linux box. Will I need to install swift on the linux machine to run the binary?

Yes you will need swift to be installed on the Ubunutu host as your executable needs to load the shared libraries. Try downloading the same version of swift you compiled against and untar it into the / directory

No, you do not need Swift installed.

You only need to supply the necessary shared libraries alongside your executable. Those are the .so files in [...].sdk/usr/lib/swift. You can find the SDK itself by looking inside the JSON file you supplied to --destination. You can simply copy the libraries into the same directory as the executable, because the $ORIGIN entry in the RUNPATH will find them there.

Alternatively, some of the libraries support static linking instead by building with --static-swift-stdlib. If that covers all the libraries you need, then you won’t need to copy anything.

1 Like

@spevans
Yes, this worked. Thanks!

@SDGGiesbrecht
the sdk path is /Library/Developer/SDKs/amd64-5.1.1-RELEASE.sdk Inside the sdk, I see usr/lib/swift/libswiftSwiftOnoneSupport.dylib but not libswiftSwiftOnoneSupport.so. I am not familiar with the internals, but a quick google search suggets .dylib could be renamed to .so for this purpose?

(by the way, Installing swift on linux worked, and then running the executable worked)

(by the way, Installing swift on linux worked, and then running the executable worked)

Yes, by installing Swift, you provided those libraries along with a whole lot of unnecessary things.

The risk in that is that you provided them in global paths. Since you cannot have two versions of Swift installed in the same place, and Swift is not API‐stable on Linux, your binary will be version‐locked with Swift and unable to coexist on the same machine as another binary installed the same way but locked to a different version of Swift.

sdk path is /Library/Developer/SDKs/amd64-5.1.1-RELEASE.sdk Inside the sdk, I see usr/lib/swift/libswiftSwiftOnoneSupport.dylib

If the toolchain/SDK combination links an .so but provides a .dylib, then it wasn’t assembled correctly. Maybe whoever assembled it was lazy because he or she never expected anyone to build without --static-swift-stdlib.

Instead, you could pull the libraries out of the .tar of Swift that you would otherwise have installed (they would be at roughly the same relative path). Then you could bundle those with your executable instead of the broken ones from the cross‐compilation toolchain.

@SDGGiesbrecht

I am sorry, I gave the incorrect path. After cd'ing into the sdk, I did an on ls on /usr/lib/swift, instead of usr/lib/swift.

Inside the sdk/usr/lib there are gcc, llvm-6.0, sasl2, ssl, and x86_64-linux-gnu dirs, but no swift directory. However, I did find .so files in usr/lib/x86_64-linux-gnu

In any case, I am happy to tar the libraries and package the binary with it. It's a good enough solution. I am sure static binary is in the works at swift.

Thanks,

I have this working for a simple executable project. It seems that my dependency on SwiftNIO is the first place where this falls down for cross-compilation:

/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
Full Build Log
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h"
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/CNIOZlib/include/CNIOZlib.h:17:10: error: 'zlib.h' file not found
#include <zlib.h>
         ^
/Users/jeff/Projects/EmojiClubServer/.build/checkouts/swift-nio/Sources/NIOHTTP1/HTTPResponseCompressor.swift:15:8: error: could not build C module 'CNIOZlib'
import CNIOZlib
       ^

This may be as simple as finding a Linux version of zlib and making sure that that C flag is set, but I’m not sure where to set it.

I was able to get zlib imports working by adding zlib1g-dev to the list of packages that the script looks for. Updating as I go in case this is useful to anyone. The next part of building Vapor that fails is this:

/Users/jeff/Projects/Open-Source/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8: error: missing required module 'CFURLSessionInterface'
import FoundationNetworking

This one I’m not as sure how to proceed with.

Yeah that's going to be a problem :confused:

You'll need a Linux Foundation to build against, I have no idea how you'll get around that without building it yourself and pointing swift build to it

1 Like

Oof, OK. I guess for now building through Docker isn't so bad… :smiley:

@SlaunchaMan this sounds like a bug in one of the tools. How did you create the cross-compilation toolchain?

It could be missing dependencies (eg. OpenSSL) in the cross compilation toolchain too, we can debug this here.

I used the script in the swiftpm repository, modified to include zlib. Then I compiled my project with swift build --destination /path/to/destination.json. I’ll share the modification to the script as a PR in case it’s useful to anyone.

Here”s the PR: Add zlib to package names by SlaunchaMan · Pull Request #2614 · apple/swift-package-manager · GitHub

To build this, first I generate the toolchain like this (using my patched version):

./swiftpm/Utilities/build_ubuntu_cross_compilation_toolchain /tmp/ ~/Downloads/swift-5.1.4-RELEASE-osx.pkg ~/Downloads/swift-5.1.4-RELEASE-ubuntu18.04.tar.gz

Then I run this to build:

swift build --destination /tmp/cross-toolchain/ubuntu-xenial-destination.json

Here’s the output from that command in a fresh Vapor install (created using vapor new):

Build Log
VaporTest jeff$ swift build --destination /tmp/cross-toolchain/ubuntu-xenial-destination.json

Fetching https://github.com/vapor/core.git

Fetching https://github.com/vapor/database-kit.git

Fetching https://github.com/vapor/sql.git

Fetching https://github.com/vapor/validation.git

Fetching https://github.com/vapor/crypto.git

Fetching https://github.com/vapor/sqlite.git

Fetching https://github.com/vapor/routing.git

Fetching https://github.com/vapor/service.git

Fetching https://github.com/vapor/fluent.git

Fetching https://github.com/apple/swift-nio-zlib-support.git

Fetching https://github.com/vapor/websocket.git

Fetching https://github.com/apple/swift-nio-ssl.git

Fetching https://github.com/vapor/multipart.git

Fetching https://github.com/apple/swift-nio-ssl-support.git

Fetching https://github.com/vapor/console.git

Fetching https://github.com/apple/swift-nio.git

Fetching https://github.com/vapor/vapor.git

Fetching https://github.com/vapor/template-kit.git

Fetching https://github.com/vapor/fluent-sqlite.git

Fetching https://github.com/vapor/http.git

Fetching https://github.com/vapor/url-encoded-form.git

Completed resolution in 14.86s

Cloning https://github.com/vapor/crypto.git

Resolving https://github.com/vapor/crypto.git at 3.3.3

Cloning https://github.com/vapor/template-kit.git

Resolving https://github.com/vapor/template-kit.git at 1.4.0

Cloning https://github.com/vapor/sqlite.git

Resolving https://github.com/vapor/sqlite.git at 3.2.1

Cloning https://github.com/vapor/fluent.git

Resolving https://github.com/vapor/fluent.git at 3.2.0

Cloning https://github.com/vapor/console.git

Resolving https://github.com/vapor/console.git at 3.1.1

Cloning https://github.com/vapor/service.git

Resolving https://github.com/vapor/service.git at 1.0.2

Cloning https://github.com/vapor/validation.git

Resolving https://github.com/vapor/validation.git at 2.1.1

Cloning https://github.com/vapor/websocket.git

Resolving https://github.com/vapor/websocket.git at 1.1.2

Cloning https://github.com/apple/swift-nio-ssl-support.git

Resolving https://github.com/apple/swift-nio-ssl-support.git at 1.0.0

Cloning https://github.com/vapor/url-encoded-form.git

Resolving https://github.com/vapor/url-encoded-form.git at 1.0.6

Cloning https://github.com/vapor/database-kit.git

Resolving https://github.com/vapor/database-kit.git at 1.3.3

Cloning https://github.com/vapor/vapor.git

Resolving https://github.com/vapor/vapor.git at 3.3.1

Cloning https://github.com/apple/swift-nio-ssl.git

Resolving https://github.com/apple/swift-nio-ssl.git at 1.4.0

Cloning https://github.com/vapor/sql.git

Resolving https://github.com/vapor/sql.git at 2.3.2

Cloning https://github.com/vapor/core.git

Resolving https://github.com/vapor/core.git at 3.9.2

Cloning https://github.com/apple/swift-nio.git

Resolving https://github.com/apple/swift-nio.git at 1.14.1

Cloning https://github.com/vapor/routing.git

Resolving https://github.com/vapor/routing.git at 3.1.0

Cloning https://github.com/vapor/http.git

Resolving https://github.com/vapor/http.git at 3.2.1

Cloning https://github.com/vapor/multipart.git

Resolving https://github.com/vapor/multipart.git at 3.0.4

Cloning https://github.com/vapor/fluent-sqlite.git

Resolving https://github.com/vapor/fluent-sqlite.git at 3.0.0

Cloning https://github.com/apple/swift-nio-zlib-support.git

Resolving https://github.com/apple/swift-nio-zlib-support.git at 1.0.0

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:163:17:** **warning:** **'launchPath' is deprecated: renamed to 'executableURL'**

process.launchPath = path

**^**

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:163:17:** **note:** **use 'executableURL' instead**

process.launchPath = path

**^~~~~~~~~~**

executableURL

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:167:17:** **warning:** **'launch()' is deprecated: renamed to 'run'**

process.launch()

**^**

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:167:17:** **note:** **use 'run' instead**

process.launch()

**^~~~~~**

run

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:163:17:** **warning:** **'launchPath' is deprecated: renamed to 'executableURL'**

process.launchPath = path

**^**

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:163:17:** **note:** **use 'executableURL' instead**

process.launchPath = path

**^~~~~~~~~~**

executableURL

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:167:17:** **warning:** **'launch()' is deprecated: renamed to 'run'**

process.launch()

**^**

**/Users/jeff/VaporTest/.build/checkouts/core/Sources/Core/Process+Execute.swift:167:17:** **note:** **use 'run' instead**

process.launch()

**^~~~~~**

run

**/Users/jeff/VaporTest/.build/checkouts/websocket/Sources/WebSocket/WebSocketHandler.swift:37:13:** **warning:** **variable 'frame' was never mutated; consider changing to 'let' constant**

var frame = self.unwrapInboundIn(data)

**~~~ ^**

let

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

**/Users/jeff/VaporTest/.build/checkouts/vapor/Sources/Vapor/Client/FoundationClient.swift:2:8:** **error:** **missing required module 'CFURLSessionInterface'**

import FoundationNetworking

**^**

Okay, so the first thing that occurs to me is that the script aims to build a "Xenial" aka 16.04 toolchain but you're trying to build a 18.04 one. Probably, that's not the only issue however.

To build all of Vapor, you'll need to add at least openssl (and its development libraries) to the toolchain builder script. Unfortunately, the toolchain builder script you're using doesn't resolve the dependencies automatically, so you'll have to add them all manually :frowning:. I do apologise, the script is really only a demonstration and should be much better but at the time where I wrote it, it did the job for me. These days I think the folks from the SwiftCrossCompilers project know best how to use and drive the Swift cross compilation support.

Does a simple project work for you? So if you tried

cd /tmp && mkdir supersimple && swift package init --type=executable
swift build --destination /tmp/...destination.json

Does that work? Because if not, please report back and we can start filing bugs :).

Yes, the executable Swift package does work. Thanks, this is more of a curiosity than anything, so it’s interesting to see what needs to be built up.

1 Like

My current error message is similar to this Swift bug which was fixed.

1 Like

Here is how we are building for Android without using --destination flag (armv7 example):

  1. Create a shell script which contains needed flags for Android armv7 target:

    #!/bin/bash
    
    # File: swiftc-arm-linux-androideabi
    
    /PathToSwitCompilerBuiltForAndroid/swift-android-toolchain/usr/bin/swiftc \
    -v -Xcc -v \
    -swift-version 5 \
    -target armv7-none-linux-androideabi \
    -tools-directory /usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64/bin \
    -Xclang-linker --sysroot=/usr/local/ndk/20.1.5948944/platforms/android-24/arch-arm \
    -Xclang-linker --gcc-toolchain=/usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64 \
    -Xcc -I/usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include \
    -Xcc -I/usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/arm-linux-androideabi \
    -L /usr/local/ndk/20.1.5948944/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a \
    -L /usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x \
    -L /usr/local/ndk/20.1.5948944/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/arm-linux-androideabi/24 \
    -L /PathToLibrariesBuiltForAndroid/swift-android-toolchain/usr/lib/swift/android/armv7 \
    $@
    
  2. Pass this shell script as an argument for swift build to build a package.

    SWIFT_EXEC=/PathToThisFileShownAbove/bin/swiftc-arm-linux-androideabi swift build \
    -c release \
    -Xswiftc -sdk -Xswiftc /PathToToolchainWhichBuiltForAndroid/swift-android-toolchain
    

    As result, swift package manager will produce binaries for armv7 target. Dynamic libraries will have a so extension.

1 Like

Um, Is this still so bad in 2022?

Related thread: Cross compiling from macOS to Linux