Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What targets are available for the swiftc -target and -target-cpu option?

Tags:

swift

swift3

this question is about cross compilation.

What kind of different targets are available using the -target or -target-cpu option of the swift compiler? Where can I find an overview?

Is it only there to create iOS/watchOS apps or can I use it to create linux programs (regular x86-64 processor) on macOS?

I tried searching the github repository and found 'x86_64-unknown-linux-gnu' as a target. However when I try to compile a simple "hello world" program (swiftc -target x86_64-unknown-linux-gnu test.swift) I get this error:

<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-linux-gnu'

Edit: I agree with CristiFati. The last part of this question is rather about how to properly include/reference the glibc (?!?).

like image 957
Zapnuk Avatar asked Mar 24 '17 19:03

Zapnuk


People also ask

What is SWIFT and how does it work?

SWIFT, today, is the largest and most streamlined method for international payments and settlements. SWIFT works by assigning each member institution a unique ID code (a BIC number) that identifies not only the bank name but the country, city, and branch.

What is SWIFT payment method?

What is the SWIFT Payment System? SWIFT (Society for Worldwide Interbank Financial Telecommunications) is a payment system that allows banks across the globe to send messages and communicate securely and instantly about cross-border payments.

Who owns SWIFT system?

SWIFT is a cooperative company under Belgian law and is owned and controlled by its shareholders (financial institutions) representing approximately 2,400 Shareholders from across the world.

What is a target in Swift?

A target, the basic building block of a Swift package. Each target contains a set of source files that are compiled into a module or test suite. You can vend targets to other packages by defining products that include the targets. A target may depend on other targets within the same package and on products vended by the package’s dependencies.

What does the swiftc command do?

The swiftc command calls the "real Swift compiler" (swift -frontend) to turn every single swift file into an object file (.o). Every command, function, (class, object etc.) that you write when you create a Swift file needs to be resolved.

How do I bundle resources with a Swift Package?

A resource to bundle with the Swift package. If a Swift package declares a Swift tools version of 5.3 or later, it can include resource files. Similar to source code, the Swift Package Manager scopes resources to a target, so you must put them into the folder that corresponds to the target they belong to.

What is the configuration of a Swift Package?

The configuration of a Swift package. Pass configuration options as parameters to your package’s initializer statement to provide the name of the package, its targets, products, dependencies, and other configuration options.


1 Answers

If you look at Swift repository on Github (Exact location: swift/utils/swift_build_support/swift_build_support/targets.py) You will see all host targets at line 149-192 in target.py.

Supports:

def host_target():
    """
    Return the host target for the build machine, if it is one of
    the recognized targets. Otherwise, throw a NotImplementedError.
    """
    system = platform.system()
    machine = platform.machine()

    if system == 'Linux':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.Linux.x86_64
        elif machine.startswith('armv7'):
            # linux-armv7* is canonicalized to 'linux-armv7'
            return StdlibDeploymentTarget.Linux.armv7
        elif machine.startswith('armv6'):
            # linux-armv6* is canonicalized to 'linux-armv6'
            return StdlibDeploymentTarget.Linux.armv6
        elif machine == 'aarch64':
            return StdlibDeploymentTarget.Linux.aarch64
        elif machine == 'ppc64':
            return StdlibDeploymentTarget.Linux.powerpc64
        elif machine == 'ppc64le':
            return StdlibDeploymentTarget.Linux.powerpc64le
        elif machine == 's390x':
            return StdlibDeploymentTarget.Linux.s390x

    elif system == 'Darwin':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.OSX.x86_64

    elif system == 'FreeBSD':
        if machine == 'amd64':
            return StdlibDeploymentTarget.FreeBSD.x86_64

    elif system == 'CYGWIN_NT-10.0':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.Cygwin.x86_64

    elif system == 'Windows':
        if machine == "AMD64":
            return StdlibDeploymentTarget.Windows.x86_64

    raise NotImplementedError('System "%s" with architecture "%s" is not '
                              'supported' % (system, machine))
like image 69
Brian Nezhad Avatar answered Oct 11 '22 21:10

Brian Nezhad