-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
347 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...s/Miscellaneous/TargetConditionals/ExecutableTargetContainsPlatformConditional/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
56 changes: 56 additions & 0 deletions
56
...iscellaneous/TargetConditionals/ExecutableTargetContainsPlatformConditional/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// swift-tools-version: 6.1 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ExecutableTargetWhen", | ||
products: [ | ||
.executable( | ||
name: "test", | ||
targets: ["ExecutableTargetWhen"] | ||
) | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.executableTarget( | ||
name: "ExecutableTargetWhen", | ||
dependencies: [ | ||
.target(name:"LinuxOnly", condition: .when(platforms:[.linux])), | ||
.target(name:"MacOSOnly", condition: .when(platforms:[.macOS])), | ||
.target(name:"WindowsOnly", condition: .when(platforms:[.windows])), | ||
.target(name:"AllPlatforms") | ||
] | ||
), | ||
.target( | ||
name: "AllPlatforms" | ||
), | ||
.target( | ||
name: "LinuxOnly", | ||
dependencies: [ | ||
"CLibArchive", | ||
"AllPlatforms" | ||
] | ||
), | ||
.target( | ||
name: "MacOSOnly", | ||
dependencies: [ | ||
"AllPlatforms" | ||
] | ||
), | ||
.target( | ||
name: "WindowsOnly", | ||
dependencies: [ | ||
"AllPlatforms" | ||
] | ||
), | ||
.systemLibrary( | ||
name: "CLibArchive", | ||
pkgConfig: "libarchive", | ||
providers: [ | ||
.apt(["libarchive-dev"]), | ||
] | ||
), | ||
] | ||
) |
20 changes: 20 additions & 0 deletions
20
...onals/ExecutableTargetContainsPlatformConditional/Sources/AllPlatforms/AllPlatforms.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public func getPlatform() throws -> String { | ||
#if os(Windows) | ||
return "Windows" | ||
#else | ||
#if os(macOS) | ||
return "macOS" | ||
#else | ||
#if os(linux) | ||
return "Linux" | ||
#else | ||
return "Unknown platform" | ||
#endif | ||
#endif | ||
#endif | ||
} | ||
|
||
|
||
public protocol MyProtocol { | ||
static var name: String { get } | ||
} |
5 changes: 5 additions & 0 deletions
5
...itionals/ExecutableTargetContainsPlatformConditional/Sources/CLibArchive/module.modulemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module CLibArchive [system] { | ||
header "shim.h" | ||
link "archive" | ||
export * | ||
} |
2 changes: 2 additions & 0 deletions
2
...TargetConditionals/ExecutableTargetContainsPlatformConditional/Sources/CLibArchive/shim.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "archive.h" | ||
#include "archive_entry.h" |
19 changes: 19 additions & 0 deletions
19
...onals/ExecutableTargetContainsPlatformConditional/Sources/ExecutableTargetWhen/main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// The Swift Programming Language | ||
// https://docs.swift.org/swift-book | ||
|
||
import AllPlatforms | ||
|
||
#if os(Windows) | ||
import WindowsOnly | ||
#else | ||
#if os(macOS) | ||
import MacOSOnly | ||
#else | ||
#if os(linux) | ||
import LinuxOnly | ||
#endif | ||
#endif | ||
#endif | ||
|
||
let platform = try getPlatform() | ||
print("Hello, world on \(platform)! OSplatform: \(OSPlatform.name)") |
11 changes: 11 additions & 0 deletions
11
...getConditionals/ExecutableTargetContainsPlatformConditional/Sources/LinuxOnly/Linux.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import CLibArchive | ||
|
||
import AllPlatforms | ||
|
||
public struct OSPlatform: MyProtocol { | ||
|
||
public static var name: String { | ||
return "Linux" | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...getConditionals/ExecutableTargetContainsPlatformConditional/Sources/MacOSOnly/MacOS.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import AllPlatforms | ||
public struct OSPlatform: MyProtocol { | ||
|
||
public static var name: String { | ||
return "macOS" | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...onditionals/ExecutableTargetContainsPlatformConditional/Sources/WindowsOnly/Windows.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AllPlatforms | ||
|
||
public struct OSPlatform: MyProtocol { | ||
|
||
public static var name: String { | ||
return "Windows" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.