見出し画像

Swiftコマンド「swift package」

helpの私家版和訳です。

Finder上で、Swift Packageとして構築したいディレクトリを作成するとします。

Terminalで上記フォルダに cd して、そこで下記コマンドを実行するとします。

swift package init --type library
(ここで、生成されたPackage.swiftを弄る)
swift package generate-xcodeproj

1行目のコマンドを実行すると、下記の様にして、ファイルが生成されます。

Creating library package: パッケージ名
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/パッケージ名/パッケージ名.swift
Creating Tests/
Creating Tests/LinuxMain.swift
Creating Tests/パッケージ名Tests/
Creating Tests/パッケージ名Tests/パッケージ名Tests.swift
Creating Tests/パッケージ名Tests/XCTestManifests.swift

生成されたPackage.swiftは、下記の様なもの

// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package: Package = Package.init(
	name: "パッケージ名",
	products: [
		// Products define the executables and libraries produced by a package, and make them visible to other packages.
		.library(name: "パッケージ名", targets: [ "パッケージ名" ]),
	],
	dependencies: [
		// Dependencies declare other packages that this package depends on.
		// .package(url: "https://github.com/stein2nd/TransparentScroller", from: "0.0.1"),
	],
	targets: [
		// Targets are the basic building blocks of a package. A target can define a module or a test suite.
		// Targets can depend on other targets in this package, and on products in packages which this package depends on.
		.target(name: "パッケージ名", dependencies: []),
		.testTarget(name: "パッケージ名Tests", dependencies: [ "パッケージ名" ]),
	]
)

発端は、bashで「swift package init --type library」「swift package generate-xcodeproj」を用いた「Swift Package Manager」向けの「XcodeProject」ファイルを生成する際に、「Swift 5」以下しか対応してないバージョンで生成されてしまうので、細かいコントロールができないものか知りたかったので。

※ま、このhelpには載ってなかったんですけど。

以下、本文です。

概要:

Swiftパッケージに関する操作を実行する

使用法:

swift package [options] subcommand

オプション:

--build-path

ビルド/キャッシュ・ディレクトリを指定する デフォルト:./.build

--configuration
-c

指定構成(デバグ / リリース)でビルドする  デフォルト:debug

--disable-automatic-resolution

Package.resolvedファイルが古い場合に、自動解決を無効にする

--disable-index-store

indexing-while-building機能を無効にする

--enable-index-store

indexing-while-building機能を有効にする

--disable-package-manifest-caching

Package.swiftマニフェストのキャッシュを無効にする

--disable-prefetching
--disable-sandbox

サブプロセスの実行時に、サンドボックス使用を無効にする

--enable-pubgrub-resolver

新しいPubgrub依存関係リゾルバを有効にする

--use-legacy-resolver

従来の依存関係リゾルバを使用する

--enable-test-discovery

Objective-Cランタイムのないプラットフォームでの、テスト検出を有効にする

--jobs
-j

ビルドプロセス中に並行して生成されるジョブの数

--no-static-swift-stdlib

Swiftの標準ライブラリを静的にリンクしない default

--static-swift-stdlib

Swiftの標準ライブラリを静的にリンクする

--package-path

他の操作の前に作業ディレクトリを変更する

--sanitize

誤動作に対するランタイムチェックをONにする

--skip-update

解決中にリモートからの依存関係の更新をスキップする

--verbose
-v

情報出力の詳細度を高める

-Xcc

すべてのCコンパイラ呼び出しにフラグを渡す

-Xcxx

すべてのC++コンパイラ呼び出しにフラグを渡す

-Xlinker

すべてのリンカ呼び出しにフラグを渡す

-Xswiftc

すべてのSwiftコンパイラ呼び出しにフラグを渡す

--help

利用可能なオプションを表示する

サブコマンド:

clean

ビルド成果物を削除する

completion-tool

補完ツール(シェル補完用)

config

パッケージの構成を操作する

describe

現在のパッケージを説明する

dump-package

解析されたPackage.swiftをJSONとして出力する

edit

パッケージを編集可能モードにする

unedit

編集可能モードからパッケージを削除する

generate-xcodeproj

Xcodeプロジェクトを生成する

init

新しいパッケージを初期化する

reset

キャッシュ/ビルドディレクトリを完全にリセットする

resolve

パッケージの依存関係を解決する

update

パッケージの依存関係を更新する

show-dependencies

解決された依存関係グラフを出力する

tools-version

現在のパッケージのツールバージョンを操作する

参照:

swift build
swift run
swift test

この記事が気に入ったらサポートをしてみませんか?