swift package pin 廃止案らしい https://github.com/rballard/swift-evolution/blob/e5e7ce76f29c855aa7162ed3733b09e701d662d6/proposals/NNNN-package-manager-revised-dependency-resolution.mdPackage.pin が Package.resolved に名前が変わって、ビルド時に自動更新されるみたいなイメージかな。products, dependencies, targets はデフォルト引数付けられなかったのかなぁ・・・。Package.swiftを置けます。Package@swift-4.swiftってのがあるとswift 4.0のtoolchainはそっちを使ってくれます。swift package init で生成されるのが新しい方なんですよね?それだとわざわざ古いマニフェスト使う理由もない気がします。が、自動生成されるものが一見してごちゃっとするのが嫌だなぁと。swiftLanguageVersionsをPackage.swiftに書くとSwift 3.0.2でエラーになるのですが、Package.swiftにはswiftLanguageVersionsを書かずPackage@swift-4.swiftを使うことで、Swift 3.0.2からSwift 4までビルド可能にできます。 (edited)-Xswiftc -static-stdlibを使うとSwift Standard Libraryをスタティックリンクできるので、実行時にlibswift*.dylibが不要になる。 (edited)swift package generate-xcodeproj ではライブラリを参照まではしてくれなかったりしますか?// swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "Sandbox", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "Sandbox", targets: ["Sandbox"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/Alamofire/Alamofire.git", .branch("swift4")) ], 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: "Sandbox", dependencies: []), .testTarget( name: "SandboxTests", dependencies: ["Sandbox"]), ] )swift build ⏎ Compile Swift Module 'Alamofire' (17 sources) Compile Swift Module 'Sandbox' (1 sources)SPMでビルド済みのC static libraryをswiftとリンクする時に ソースツリーに配置したstatic libraryを相対パスで指定することってできますか? http://qiita.com/shingt/items/08c726f968dd8508b1e2 Qiita Swift Package Manager経由でSwiftからCのライブラリを利用する - Qiita # 概要 Swiftがオープンソース化されると同時に[Swift Package Manager](https://github.com/apple/swift-package-manager)(以下SPMと略記)も公開されました。... この記事の例だとシステムにインストールされた libhiredis をリンクしているようなんですが これをリポジトリローカルでやりたい https://clang.llvm.org/docs/Modules.html#link-declaration module map の link 命令は -l オプションになるっぽいのです あ、 $ swift build に -Xlinker があるな。$ swift build -Xlinker -LSources/PbClib/lib てなかんじで。let package = Package() package.name = "FooBar" package.products = [...] みたいに書いていった方が楽かもしれん。cStandard を削除する– Support Build Settings The package manager has no way to provide specific settings, such as compiler flags, for building the targets in a package. Some settings are critical for production code, such as the "deployment target" (the minimum OS version that the built code will run on). We need to provide a way to set at least the most important settings which users will need control over.PackageDescription.PackageをCodable対応にして、Package.swiftへエンコードするEncoderを作る…
(edited)PackageDescriptionをインポートできる様にして、雛形を作る的なイメージ。Hi, We have an unofficial slack team to aid the development of Swift Package Manager. All the major discussion happens on the mailing list but it is useful to have a quick communication channel to discuss something small or to bounce off some random ideas. You can get an invite to join the slack team by entering your email id here: https://swift-package-manager.herokuapp.com/ Team ID: http://swiftpm.slack.com More info on slack: https://slack.com -- AnkitPackageDescriptionをインポートできるといいね!」ってことで要望を出しておいた。 http://www.openradar.me/radar?id=5057232672653312moduleをframework moduleに書き換える必要があるようです。$ swift build -v でxcodeprojの再生成もたびたびするのでうまいxcodeprojを作ってくれるとありがたいのですが何か方法はないでしょうか。 Cのモジュールを含む場合、再生成は全くお勧めできないかな。 (edited)Sources/Cxorswift/include/Cxorswift.h を追加することで Sources/Cxorswift/include/module.modulemap を削除したりもしてる。module.modulemap は使わない様に変えました。xorswift.h はフレームワークのXorswift.hとかぶるので、xorshift.h xorshift.cpp へ名前を変えました。module.modulemap を自動で生成する機能を持ってるので、SwiftPMもそれを活かす様にしてくれれば良いのですが、活かしてくれず。SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGEと設定されているのが疑問に思いAnkitさんに聞いてみたら、swift package generate-xcodeprojはswift buildによるビルドをXcodeで再現するために存在するためらしい。Range 関連で UnboundRange が Proposal のどこにもない(ようだ)という話を @rintaro さんに聞きました。dev が気になってるんですが、ちゃんとインストールできてないでしょうか? $ swift package --version Apple Swift Package Manager - Swift 4.0.0-dev (swiftpm-13126)Apple Swift Package Manager - Swift 4.0.0-dev (swiftpm-13126) 同じく。isDevelopment が取れたコミットは swift-4.0-branch にもないので、忘れ去られているだけなのかと。➜ ~ swift package --version Apple Swift Package Manager - Swift 4.0.0-dev (swiftpm-13126) # ついでに ➜ ~ DEVELOPER_DIR=/Applications/Xcode-8.3.app/Contents/Developer swift package --version Apple Swift Package Manager - Swift 3.1.0 (swiftpm-12084)swift package init で生成されるテンプレート。 BEFORE import PackageDescription let package = Package( name: "Swiftor" ) AFTER // swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "Swiftor", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "Swiftor", targets: ["Swiftor"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), ], 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: "Swiftor", dependencies: []), .testTarget( name: "SwiftorTests", dependencies: ["Swiftor"]), ] )targets 省略でも、デフォルトとして解釈してくれてもいい気がするんですけどねぇ・・・。carthage update 相当のことをするにはどうすればいいんだと思って↓見たらまだ pinning とか書いてあってがっかりしてたけど普通に swift package update でできた。 https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md $ rm Package.resolved でごまかして生きてるimport PackageDescription を Cmd + Click するとextension Dependency { public static func target(name: String) -> PackageDescription.Target.Dependency public static func product(name: String, package: String? = default) -> PackageDescription.Target.Dependency public static func byName(name: String) -> PackageDescription.Target.Dependency }PackageDescription.Target.Dependency となるべくところが Dependency になっていてPackageDescription.Package.Dependency も存在するのでよくわからなくなっているimport PackageDescriptionで Module compiled with Swift 4.0 cannot be imported in Swift 4.0.1: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4/PackageDescription.swiftmodule って言われて定義をひらけなかった。canImport って SwiftPM で管理された二つの独立した(別リポジトリの)パッケージ間で利用することはできるんでしょうか?canImport(B) が書いてあって extension が生やされていて、 C が A と B の両方に依存している場合にはその extension が使えるけど、 A にしか依存していない場合はその extension が使えないとか。canImport(B) とはいえ A が B に依存していないといけない気がしていて、そうすると常に canImport(B) が真になる気がします。 optional な dependency が記述できないと実現できなさそう。canImport(B) の内部を解決する方法がないし、依存してるなら C も間接的に B に依存することになって常に canImport(B) が満たされそう。swift test でテストすることすらできないってこと?#if os(iOS) は OS を切り替えてテストできるけど#if canImport(B) はどうやっても A のリポジトリ単体でテストできなくなっちゃうよ。canImport の Proposal は swift-evolution に出てるよPackage.swiftの記述に関するものは、全てswift-evolutionに出てる気がします。swift runみたいなサブコマンド?レベルの追加は出てる。swift test --filter <test pattern>みたいなオプションとかはSlackとかで話されて追加されてる気がする。canImportはswiftpmのSlackで話された形跡がないですね。canImportの運用について気づいて(気にして)ないんじゃないかな? (edited)Package.swift内でcanImportを使う?というのも考えたけど、swift test -vの出力を見る限りPackage.swiftのパースでは最低限のimport pathしか設定されていない。canImport 、なんかメタでヤバそうな感じだ・・・canImport の実装読んでみても良さそうですね。 canImport 自体は SwiftPM と独立に動きそうなので、 canImport の厳密な判定条件がわかれば実際にどういう挙動をするのか理解できそうです。swift package generate-completion-script zsh > ~/.oh-my-zsh/custom/plugins/swift/_swiftしてzshがswiftのコマンドラインオプションを補完できる様にした。 $ swift build -- build sources into binary products package -- perform operations on Swift packages run -- build and run an executable product test -- build and run tests (edited)Int?が返るのでflatMapが正しいのでは?swift build [1/1] Compile CYaml src/writer.c Compile CYaml src/reader.c Compile CYaml src/scanner.c Compile CYaml src/parser.c Compile CYaml src/emitter.c Compile CYaml src/api.c Compile Swift Module 'Yams' (15 sources) Compile Swift Module 'render0' (1 sources) Linking ./.build/x86_64-apple-macosx10.10/debug/render0 Fetching https://github.com/jpsim/Yams.git Cloning https://github.com/jpsim/Yams.git Resolving https://github.com/jpsim/Yams.git at 0.5.0 swift build end$ touch a.txt $ tail -f a.txt $ swift build >> a.txt これだけでも再現したFetching https://github.com/jpsim/Yams.git Cloning https://github.com/jpsim/Yams.gitSwift.print()にバッファが効いてるのかな?>リダイレクトで入れ替わる。Swift.print()が出力先をflockしてるっぽいのも気になってるけど、再現実装が必要かな。swift buildで成果物が置かれるディレクトリのパスを取得: $ swift build --configuration release --show-bin-path /Users/norio/github/gysb/.build/x86_64-apple-macosx10.10/releasesetlinebuf(Darwin.stdout)をすると直る。> swift buildの出力をキャプチャすると順序が入れ替わる。 (edited)setlinebuf()の利用自体が正しいのかはよくわかっていません。これについて、僕自身ではSwiftPMへPRを出すモチベーションは低いです。omochiさんのところで動作確認出来て、その気があるならPRを書かれると良いのではないかと思います。-Xswiftc -static-stdlibを使ってビルドしたバイナリになりそうです。 https://github.com/realm/SwiftLint/pull/1951 https://github.com/jpsim/SourceKitten/pull/443swift-buildをXcodeでデバッグ実行した時に"could not find llbuild"エラーになる不具合を修正しました。 https://bugs.swift.org/browse/SR-6371 (edited)0.1.0のバージョンタグがついて、Dependencyとして利用できる様になったぽい。https://github.com/apple/swift-package-manager/releases/tag/0.1.0swift build したり swift package update したりするとエラーになるんですが、そういうものなのでしょうか? B -> C のブランチによる依存とは、 B の Package.swift に↓ように書いた場合のことです。 .package(url: "https://github.com/foo/C.git", .branch("master"))swift package update するか、もしくは Package.resolved を削除および swift package reset してから swift build すると再現します。 A = swtws, B = TweetupKit, C = OAuthSwift です。 https://github.com/swift-tweets/swtws.branch は使えないですね・・・。使った瞬間に他のライブラリがそのライブラリに依存できなくなってしまうswift package edit Bを使ったら、開発途中のBを使えませんかね? (edited).branch じゃなくて .revision なら大丈夫ですか?swift package edit Cでは?swift package edit OAuthSwiftかswift package update ではなく) swift build してもうまくいかないことですね・・・。swift build しても依存解決のための何かが実行されるんですっけ??単に clone/fetch してビルドするだけかと思ってました。swift package edit Bだった。 $ git reset --hard HEAD is now at 66ed003 Update TweetupKit $ swift package edit TweetupKit Fetching https://github.com/swift-tweets/tweetup-kit.git Fetching https://github.com/swift-tweets/OAuthSwift.git Fetching https://github.com/kylef/Commander.git Fetching https://github.com/koher/PromiseK.git Fetching https://github.com/kylef/Spectre.git Cloning https://github.com/swift-tweets/tweetup-kit.git Resolving https://github.com/swift-tweets/tweetup-kit.git at 0.2.1 Cloning https://github.com/koher/PromiseK.git Resolving https://github.com/koher/PromiseK.git at 3.0.0-alpha.4 Cloning https://github.com/kylef/Spectre.git Resolving https://github.com/kylef/Spectre.git at 0.8.0 Cloning https://github.com/swift-tweets/OAuthSwift.git Resolving https://github.com/swift-tweets/OAuthSwift.git at 2.0.0-beta Cloning https://github.com/kylef/Commander.git Resolving https://github.com/kylef/Commander.git at 0.8.0 swift package edit TweetupKit 3.07s user 2.89s system 53% cpu 11.056 total $ (cd Packages/TweetupKit;git checkout master) Previous HEAD position was 71f0117... Merge pull request #11 from swift-tweets/dev-0.2.1 Switched to branch 'master' Your branch is up to date with 'origin/master'. $ swift build Updating https://github.com/koher/PromiseK.git Updating https://github.com/swift-tweets/OAuthSwift.git Updating https://github.com/kylef/Commander.git Updating https://github.com/kylef/Spectre.git Updating https://github.com/swift-tweets/tweetup-kit.git Fetching https://github.com/OAuthSwift/OAuthSwift.git Cloning https://github.com/OAuthSwift/OAuthSwift.git Resolving https://github.com/OAuthSwift/OAuthSwift.git at master Compile Swift Module 'PromiseK' (2 sources) Compile Swift Module 'Commander' (9 sources) Compile Swift Module 'OAuthSwift' (24 sources) … (edited)swift package reset してから swift build するとエラーになりませんか?swift package resetするとeditモードから外れるので、その後にswift buildしてエラーになるのは当然かな。swift package edit TweetupKit --revision 0.2.2すれば(cd Packages/…; git checkout …)とかしなくて良いのか。swift build では -fmodule が有効化するのに swift package generate-xcodeproj の xcode では Build Settings > Enable Modules = NO になっているために モジュール対応モードでコンパイルされないため、 そのモジュール自身が @import を使っているとコンパイルできない というトラブルを踏んでるんですが、何か知見のある人いますか? 該当のリポジトリで立ってるissueでは手動設定が言及されているけど https://github.com/stephencelis/SQLite.swift/issues/691#issuecomment-339612232 (edited)@import じゃなくて #import に書き換えてモジュール=NOのままやってみたら、今度は libsqlite3の自動探索がされなくなって(モジュールじゃないから) modulemapのlinkパラメータがxcodeprojに反映されないから駄目だった・・・Package.swiftとは別のSwiftWorkspace.jsonを導入しようというモノらしい。 https://forums.swift.org/t/package-manager-workspace/10667llbuildにswift-compilerプラグインを組み込んだ外部実行ファイルswift-build-toolでビルドしているのを、llbuildのSwiftバインディングを使ってSwiftPM内から直接呼び出す様に変えることでswift-compiler以外のプラグインを使える様にし、PackageExtension.swiftでカスタムプラグインとそれを利用したルールを定義できる様な仕組みになるぽい? (edited)swift test --generate-linuxmainなんて出来るようになってたのね。swift -I .build/debug/ -L .build/debug/ こういう風にすれば、import するとこまではできたのですが、実際に使おうとすると中身がないというようなことを言われてしまいます。 (edited)products が .library( type: .dynamic ) であることを確認して、 import PackageDescription let package = Package( name: "MyPMLib", products: [ .library( name: "MyPMLib", type: .dynamic, // < HERE targets: ["MyPMLib"]), ], ... (edited)-l{モジュール名}
$ swift build Compile Swift Module 'MyPMLib' (1 sources) Linking ./.build/x86_64-apple-macosx10.10/debug/libMyPMLib.dylib $ swift -I .build/debug/ -L .build/debug/ -lMyPMLib Welcome to Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.39.1). Type :help for assistance. 1> import MyPMLib 2> hello() Hello? 3> GTMNSString+HTML.h as Swift Packageif filename:Package.swift path:/ NOT "os(" のほうが正確っぽい。.Sを含むライブラリをSwiftPMでビルドしたかったのだけど、.Sはサポートされてなかった。.Sを.cppの中に埋め込むとか出来ないかな…swift package generate-xcodeprojには、Debug Build ConfigurationのSWIFT_ACTIVE_COMPILATION_CONDITIONSにSWIFT_PACKAGEを設定しないバグがある。 https://bugs.swift.org/browse/SR-7965swift package generate-xcodeprojがC言語系のターゲットを生成する際module.modulemapにフルパスでヘッダが記載されるため生成されたXcodeプロジェクトがポータブルにならない、を改善するパッチがマージされました。 https://github.com/apple/swift-package-manager/pull/1602module.modulemapを生成せず、Xcodeが自動生成する仕組みを利用する様になります。swift package generate-xcodeproj で生成されるInfo.plistのBundle identifierがcom.yyy.Xxxxみたいなのじゃなくて、パッケージ名Xxxxだけになるようになってしまったような感じしてるのですが、どこで変わったか分かる人いないですかねswift-4.0-RELEASEで既にそうなってますね。
swift-4.0-RELEASEでなってるんですね…Xcode 9.2の時はリバースドメインになってた気がしてるんですが、勘違いかな Bundle Identifierがパッケージ名になるのって、意図した挙動なんですかね?iOSのイメージだとリバースドメインの形式な気がしてるswift-3.0-RELEASEでもターゲット名になってました。DIKitに限っていえば、generate-xcodeprojを使わなければいけない理由がCYamlのmodule.modulemap内のパスが問題であるなら、CYamlターゲットをDIKit自身で持つ様にすれば解決可能です。 (edited)Yamsでやってるので。 https://github.com/jpsim/Yamsgenerate-xcodeprojした際CYamlターゲットのmodule.modulemapにフルパスが含まれる問題、Swift 4.2のスナップショットでswift package generate-xcodeprojするだけで解決する様になりました。GeneratedModuleMap/CYaml/module.modulemapを削除してくれませんが、生成されたXcodeプロジェクトはmodule.modulemapを使わなくなるので、リポジトリから削除可能になります。Stencilには含まれていないのがネックかな。 https://github.com/ishkawa/DIKit/blob/master/Package.swiftswift-DEVELOPMENT-SNAPSHOT-2018-07-11-aでPackageDescription API v3が削除されたため、いくつかのパッケージがビルド出来なくなった… https://github.com/apple/swift-package-manager/commit/d9ae3a84d4860cd601ff2f336859a46f11cccc0cswift test 2>&1 | xcprettyとすればxcpretty使えるらしい。 https://forums.swift.org/t/swift-test-output-format/14702/13binary サポートの挙動が微妙だ・・・carthage update した時点では /Users/omochi/Library/Caches/org.carthage.CarthageKit に zip ファイルがダウンロードされるだけでcarthage build してはじめて、 Carthage/Build/iOS に zip の中身が展開されるcarthage update --no-build だと zipの展開が行われない (edited)swift-tools-version:4.0 の状態で swift build すると #if swift(>=4.2) が正しく動かないみたい。これはバグ?#if !swift(>=4.2) print("<4.2") #endif print(CountableRange<Int>.self)$ swift --version Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44) Target: x86_64-apple-darwin17.7.0 $ swift run <4.2 Range<Int>CountableRange<Int>.self は Range<Int> になってるから中身は Swift 4.2 らしく、正しく分岐できずに困ったことになりそう。 (edited)CountableRange になってる。 $ swift --version Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2) Target: x86_64-apple-darwin17.7.0 $ swift run <4.2 CountableRange<Int> (edited)#if swift(>=4.1.50)を使いましょう。 @swift-4.2.4 -swift-version 4 #if swift(>=4.1.50) print("4.1.50") #endif (edited)norio_nomura06/06/2018 > 話かわりますけど、Xcode 10 BetaはSwift4.1.50になるw Swift 4.2コンパイラに-swift-version 4を渡すと4.1.50になります。swift-tools-version:4.0 の問題じゃなくて、コンパイラの -swift-version 4 時の挙動なんですね。CountableRange は typealias なんですね。そうじゃないと 4.2 と混ぜれないから当たり前か。なるほどー。.testTarget を作ることはできるのでしょうか? @testable import がリリースビルドだと出来ないので、public なAPIをテストする テストターゲットと、internal なユニットテストを分けて、 swift test -c release のときには後者は実行しないようにしたいのです。 (edited)#if DEBUG は使えるのかな@testable 使わないから気づかなかったimport Foundation して ProcessInfo.processInfo.environment でどうにかするとか-enable-testingを指定したら@testable importできません?@testable有効にしてテストするのはありかも。Xcodeでのテストで同じようなことはしています https://github.com/ReactiveCocoa/ReactiveSwift/blob/2463d83d0c896ac046c2b85377e583b72373b831/script/build#L35-Xswiftc -enable-testing で @testable import はできるのですが、リリースビルドの成果物はそのままリリースに回したいので、、、というところで。/Users/omochi/temp/spmdb/Tests/zooTests/spmdbTests.swift:2:18: error: module 'zoo' was not compiled for testing @testable import zoo ^-c release のときだけここでこけますね、そのままやると。public APIテストのみ) をクリーンに回す方法が現状ないということ?#if DEBUG で囲んでしまえば、きれいではないけどいける気はする#if DEBUG は出来るのですね。#If DEBUG @testable import zoo #else import zoo #endif ^ これと、それぞれInternalにアクセスするテストを囲う感じですね。@testable import するテストはファイルを分けて、ファイル全体を #if DEBUG で囲う方向でやってみます。 (-D DEBUG が渡っていることは確認しました) (edited)#if canTestableImport(…) とかあれば良いのに。swift package generate-xcodeproj の出力が、実行毎に変わるようになったのって、Swift 4.2からで合ってますかね?xcodeprojを手動でメンテナンスしたくない理由って何なのだろう?swift build でビルドできる必要があるのでxcodeprojをリポジトリに入れても使えないよね。Package.swift内のdependenciesの事。 生成されたxcodeprojには.build/checkouts下のパスが含まれるから、Xcodeでビルドする前にSwiftPMでもビルドしないといけないから、都度generate-xcodeprojするのと変わらない。.build/checkoutsを用意する為にはSwiftPMを使わないといけない。それならgit submoduleで管理した方が良いのでは、と思えてしまう。SWIFT_DETERMINISTIC_HASHING=1xcodeproj入れるのをやめた方が良い気が….xcworkspaceでもいける?xcodeprojではCarthageでビルド出来ないのでは。.build/checkoutsはどの様に用意してたのですか?DIKitを使うDIGenKitが使うのですね。.build/checkoutsが無くてもCarthageでビルド出来ていたって事ならば、.build/checkouts以下のパスに再現性が無くても構わないという事になりそうな気が….build/checkouts内のパスも変わるし、project.pbxproj内の要素の順番とかも変わりますね。xcodeprojからDIKit.framework以外の要素を手動で削除してしまえば良いのかも。Set 使っていてこの PackageGraph から諸々生成しているので、ランダムシードの影響受けるのは必至なのですが、手元で試した限り env SWIFT_DETERMINISTIC_HASHING=1 swift package generate-xcodeproj でも阻止できないので、やっかいですね。SWIFT_DETERMINISTIC_HASHING 試したら name = "Products"; の箇所だけなぜか順番が変わるけど、そこ以外は安定してる "OBJ_162" = { isa = "PBXGroup"; children = ( "Yams::Yams::Product", "DIKit::dikitgen::Product", "Yams::CYaml::Product", "PathKit::PathKit::Product", "DIKit::DIGenKit::Product", "Stencil::Stencil::Product", "DIKit::DIGenKitTests::Product", "Spectre::Spectre::Product", "DIKit::DIKit::Product", "SWXMLHash::SWXMLHash::Product", "SourceKitten::SourceKittenFramework::Product" ); name = "Products"; path = ""; sourceTree = "BUILT_PRODUCTS_DIR"; }; - there is no good way to control the ordering of the `Products` group in the main group; it needs to be added last in order to appear after the other references (edited)env SWIFT_DETERMINISTIC_HASHING=1 swift package generate-xcodeproj で実行すると、hashは固定されるけど、根本的にだめな気がしてきた... (edited)generate-xcodeprojで生成したproject.pbxprojの.build/checkouts/*をCarthage/Checkouts/*へ書き換え。Package.swiftへの参照は、親グループの複数パターンに対応できない為にリンク切れになってるけど、ビルドに影響ないので放置。CartfileではなくCartfile.privateを使うべきなのかも。// swift-tools-version:4.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription var targets: [Target] = [ .target( name: "Foo", dependencies: []), .testTarget( name: "FooTests", dependencies: ["Foo"]), ] assert({ targets.append( .testTarget( name: "FooDebugTests", dependencies: ["Foo"]) ) return true }())
DEBUG が渡らないだけじゃなくて、 -c が Package.swift を debug/release のどちらで実行するかに影響を与えるわけではない( -c release でも debug っぽい)みたいでダメだった。Package.swift のロード(実行)のコマンドは https://github.com/apple/swift-package-manager/blob/106115d356f750223dbd4419c3f39f8fc2da66f7/Sources/PackageLoading/ManifestLoader.swift#L310-L329 この辺だと思っていて、そこでconfigurationを渡していないようなので。渡すようにしたPR出すのはありやなしや。-c は Package.swift についてではないよなぁという気もしますね。それよりも DEBUG 等が Package.swift にも渡される方が良さそう?-c debugの時は-D DEBUGも指定、くらいが妥当そうvar disableWhenDebug: Bool があってスイッチできる、みたいな感じで。error: 'iso8601' is only available on OS X 10.12 or newer public static let dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .iso8601 ↓でいちおうビルドできるんですが、もっと Swift PM 的に良い方法はないかなと。 swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.12" if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) { を使わずに?dateDecodingStrategy にアクセスした箇所全部で分岐が必要になってしまうので・・・。extension JSONDecoder.DateDecodingStrategy { @available(OSX, obsoleted: 10.11) static var iso8601 = JSONDecoder.DateDecodingStrategy.formatted({ let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" formatter.timeZone = TimeZone(secondsFromGMT: 0) return formatter }()) } とかやってみたけど、候補を探すときに@availableを考慮してくれなくてダメだった。 Compile Swift Module 'Foo' (1 sources) /Users/norio/github/Foo/Sources/Foo/Foo.swift:17:37: error: ambiguous use of 'iso8601' decoder.dateDecodingStrategy = .iso8601 ^ Foundation.JSONDecoder:7:14: note: found this candidate case iso8601 ^ /Users/norio/github/Foo/Sources/Foo/Foo.swift:5:16: note: found this candidate static var iso8601 = JSONDecoder.DateDecodingStrategy.formatted({ ^swift-DEVELOPMENT-SNAPSHOT-2018-10-01-aでswift run --replが出来る様になりました。 https://github.com/apple/swift-package-manager/pull/1793.spm.shellEscaped 式にできそうだねswift test --parallel --xunit-output result.xmlとか出来る様になってたの知らなかった。 https://github.com/apple/swift-package-manager/commit/047df6464ab15e27ab19b9a8263caeaf32127065--xunit-outputを使うには--parallelが必要。--xunit-outputは未完成の機能だから--helpには出てこないらしい。xcpretty -r junitとかで生成してるのが不要になる。dlopenで動的にロードする事は頑張れば出来そうな気もしますが、試した事は無いです。dlopenも無理かな。swift-DEVELOPMENT-SNAPSHOT-2019-03-04-aには含まれてるみたいですよ。POSIXモジュールを削除するPR https://github.com/apple/swift-package-manager/pull/2053master にも swift-5.0-branch にも PackageDescriptionV5.md がない? https://github.com/apple/swift-package-manager/tree/swift-5.0-branch/DocumentationSources/${target}/include/${target}.h が置いてあり、かつ、 modulemapが置いてない ときに限ってswift package generate-xcodeproj の挙動ならば、僕が提案したモノですね。module.modulemapを生成して、それ経由でリンクしていたはずです。 https://github.com/apple/swift-package-manager/pull/1406 .library(name: "PaperDynamic", type: .dynamic, targets: ["Paper"]),Leave this parameter unspecified to let to let the Swift Package Manager choose between static or dynamic linking (recommended). オススメはSwiftPMに任せる、なんですね。$ swift test --generate-linuxmain warning: can't discover tests on Linux; please use this option on macOS instead #if os(macOS)でmac専用のテストを書いている場合、mac上でgenerate-linuxmainするとそれらも含まれてしまうので微妙……Load command 20 cmd LC_RPATH cmdsize 120 path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx (offset 12)Load command 20 cmd LC_RPATH cmdsize 32 path /usr/lib/swift (offset 12) Load command 21 cmd LC_RPATH cmdsize 40 path @executable_path/../lib (offset 12)DYLD_LIBRARY_PATHをチェックして、rpathへ設定するパッチ。 @@ -0,0 +1,35 @@ diff --git a/Package.swift b/Package.swift index 8234442cbb68248f8c541e8af979c538c72df0a6..abf133e63098c7bf46cb28bb971e21afae5e462b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.0 //===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// import PackageDescription +import Foundation let package = Package( name: "swift-format", @@ -64,7 +65,15 @@ let package = Package( "SwiftFormatConfiguration", "SwiftFormatCore", "SwiftSyntax", - ] + ], + linkerSettings: { () -> [LinkerSetting] in + if let DYLD_LIBRARY_PATH = ProcessInfo.processInfo.environment["DYLD_LIBRARY_PATH"]? + .components(separatedBy: ":") { + let flags = DYLD_LIBRARY_PATH.flatMap { ["-rpath", $0] } + return [.unsafeFlags(flags)] + } + return [] + }() ), .testTarget( name: "SwiftFormatRulesTests",from: ではなく .branch("...") でレポジトリを指定してあるとして、branch のコミットが進んだときに「そのブランチの最新コミットを fetch し直す」ってできるんでしょうか?( .build と Package.resolved を消して swift build し直せばできるのですが…) (edited). ├── Package.swift └── Sources ├── App │ └── main.swift ├── ClibB │ ├── Greeting.cpp │ └── include │ └── Greeting.hpp └── ClibBWrapper ├── HelloCpp.mm └── include └── HelloCpp.h 1つのPackage.swiftでやると、 ^ C++のコードをObjC++でラップしたモジュールを使うSwiftのパッケージ構成はこんな感じで、 Package.swiftは // swift-tools-version:4.0 import PackageDescription let package = Package( name: "Hello", targets: [.target(name: "App", dependencies:["ClibBWrapper"]), .target(name: "ClibBWrapper", dependencies:["ClibB"]), .target(name: "ClibB"),] ) こう。-emit-objc-header 付きで呼び出してFooの分のヘッダを作成して、そのヘッダを参照できるだけのCモジュールもFoo側に作って、AppではそのCモジュールを参照するようにしたんですが。├── Package.swift └── Sources ├── Foo │ ├── Foo1.swift │ ├── Foo2.swift │ └── FooN.swift └── CFoo ├── Foo.m └── include └── Foo-swift.h// swift-tools-version:5.0 import PackageDescription let package = Package( name: "Foo", products: [ .library(name: "Foo", targets: ["Foo"]), .library(name: "CFoo", targets: ["CFoo"]) ], targets: [ .target(name: "Foo"), .target(name: "CFoo", dependencies: ["Foo"]) ] ) (edited)-emit-objc-header で作ったヘッダファイル。 App側でCFooを参照すれば、ObjCでも、 @import CFoo; だけでヘッダの参照ができるようになりました。 (edited)// swift-tools-version:5.0 import PackageDescription let package = Package( name: "Foo", products: [ .library(name: "Foo", targets: ["Foo"]), .library(name: "CFoo", targets: ["CFoo"]) ], targets: [ .target(name: "Foo", swiftSettings: [ .unsafeFlags(["-emit-objc-header-path", "Sources/CFoo/include/Foo-swift.h"]) ]), .target(name: "CFoo", dependencies: ["Foo"]) ] ) とか。
(edited)/// As some build flags could be exploited for unsupported or malicious /// behavior, the use of unsafe flags make the products containing this /// target ineligible to be used by other packages. 知りませんでした…cxxSettings に headerSearchPath で /usr/local/include を入れてみたのですが、絶対パスは指定できないようで… Package.swift は以下の通りです: import PackageDescription let package = Package( name: "ClosedRegion", dependencies: [ ... ], targets: [ .target( name: "LinBoxWrapper", // これが C++ ライブラリの wrapper dependencies: [] ), .target( name: "ClosedRegion", // これがプログラム本体 dependencies: ["...", "LinBoxWrapper"]) ], cxxLanguageStandard: .cxx11 ) C++ のライブラリは含まれておらず、ビルド済みのものが /usr/local/lib 下にある状況です。これが Xcode を立ち上げる必要なく swift run だけで走るようになるとさらに嬉しいです。
(edited) .target( name: "LinBoxWrapper", dependencies: [], cxxSettings: [ .unsafeFlags(["-I", "/usr/local/include"]) ], linkerSettings: [ .linkedFramework("Accelerate"), .unsafeFlags(["-L", "/usr/local/lib"]), .linkedLibrary("linbox"), .linkedLibrary("gmp"), .linkedLibrary("givaro") ] ), これで出来てそう! (edited)<unknown>:0: error: error opening '(...ProjectのDerivedDataのパス...)/SourcePackages/checkouts/Foo/Sources/CFoo/include/Foo-Swift.h' for output: Operation not permittederror: The package product 'Foo' cannot be used as a dependency of this target because it uses unsafe build flags. (in target 'App' from project 'App')unsafeFlagsが有効になる様にするとか。
unsafeFlags を有効にする方法ってあります?やってみようとしたら見つけられなかったので。// swift-tools-version:5.0 import PackageDescription import Foundation let package = Package( name: "Foo", products: [ .library(name: "Foo", targets: ["Foo"]), .library(name: "CFoo", targets: ["CFoo"]) ], targets: [ .target(name: "Foo", swiftSettings: { ProcessInfo.processInfo.environment["UPDATE_SWIFT_HEADER"] != nil ? [.unsafeFlags(["-emit-objc-header-path", "Sources/CFoo/include/Foo-swift.h"])] : [] }()), .target(name: "CFoo", dependencies: ["Foo"]) ] ) (edited)PackageDescriptionモジュールにもっと簡単に環境変数へアクセス出来る仕組みがあっても良い気もします。 (edited)[] はempty list not supportedって言われるので nil に変更。これで動くことは動くようです export UPDATE_SWIFT_HEADER=1;open /Applications/Xcode_11_Beta_4.app でXcodeを起動するのはあんまりだ(これでいちおう動くことは確認しましたが) でも、CIで使うにはいい方法だなと思いました。-Xswiftc -emit-objc-header-path -Xswiftc Sources/CFoo/include/Foo-swift.h を付けて呼べばいいだけのような気がしてきました -emit-objc-header-path が使われてしまうのでダメです。--enable-test-discoveryオプションつけるとLinux用のテストファイルを自動生成する?機能が使えるらしい。良さそう https://github.com/apple/swift-package-manager/pull/2174/IndexStore使ってますね。--enable-test-discoveryにはSourceKitより向いてる。XCTestCaseの孫クラスで、親クラスで定義されたテストメソッドを見つけてくれない、という制限が--enable-test-discoveryにはあった気がするけど、対応されたのかな? (edited)swift testでerror: use of unresolved identifier 'XCTUnwrap'エラー。$ MISSING_LIB_PATH="$(xcrun -sdk macosx -show-sdk-platform-path)/Developer/usr/lib" && swift test -Xswiftc -I -Xswiftc "${MISSING_LIB_PATH}" -Xswiftc -L -Xswiftc "${MISSING_LIB_PATH}"swift package init --type executable で作った target は,対応する testTarget から import して直接テストするようなことはできないんでしょうか?自動生成されたテストでは、プロセスを実行して出力された文字列をテストするようなものになっているようです. .target( name: "Clibxml2", // Headers and linking for libxml2 cSettings: [.headerSearchPath("$(SDKROOT)/usr/include/libxml2")], linkerSettings: [.linkedLibrary("xml2")] ), (edited)Package.swift内で使えなくしたみたいですね。意図せずXcode 11で使えていたのかと。 https://github.com/apple/swift-package-manager/pull/2206$ swift build では元々動かなかったんですよね?
$ swift package generate-xcodeproj で生成したxcodeprjで使えた、もしくは、 Xcode11のPackage.swift直接開く機能経由で使えた、 という意味ですよね。swift build -Xcc -I/usr/local/Cellar/libxml2/2.9.9_2/include/libxml2 (edited)pkgconfigとか使えないんだっけ? .systemLibrary( name: "Clibxml2", pkgConfig: "libxml-2.0.pc", providers: [ .brew(["libxml2"]), .apt(["libxml2-dev"]) ]), Xccでフラグ渡さないと、ヘッダが見つけられないんですよね。 /usr/local/Cellar/libxml2/2.9.9_2/include/libxml2/libxml/chvalid.h:17:10: error: 'libxml/xmlversion.h' file not found #include <libxml/xmlversion.h> (edited)$ pkg-config --cflags libxml2 でパスが出ない状況ですか?pkg-config --cflags --libs "libxml-2.0 > 2.6.17" ならパスがでますが pkg-config --cflags --libs "libxml-2.0 > 2.6.17" -I/usr/include/libxml2 -lxml2
$ pkg-config --cflags libxml2 では出ないですね Package libxml2 was not found in the pkg-config search path. Perhaps you should add the directory containing `libxml2.pc' to the PKG_CONFIG_PATH environment variable (edited)/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/usr/includeのやつはどこから来たんだ/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.13/libxml-2.0.pc これっぽい$SDKROOTが書きたい気持ちがわかってきました。 .target(name: "CNIOExtrasZlib", dependencies: [], linkerSettings: [ .linkedLibrary("z") ]), で/Sources/CNIOExtrasZlib/include/CNIOZlib.h で #include <zlib.h> してるだけっぽいので/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2/libxml/HTMLparser.h:15:10: error: 'libxml/xmlversion.h' file not found #include <libxml/xmlversion.h> (edited)MacOSX10.15.sdk/usr/include/libxml2/module.modulemapとか見ると、簡単にはいかなさそう。module libxml2 [system] [extern_c] { // Add "-Xcc -I$(SDKROOT)/usr/include/libxml2" to OTHER_SWIFT_FLAGS in Xcode project.headerSearchPathの話が出てた。 https://forums.swift.org/t/build-setting-headersearchpath-contains-invalid-component-s-srcroot/27960.systemLibrary を使う方法があることを知りました。Package.swift の target の中に .systemLibrary(name: "Choge") を入れておいて,Source/Choge/ 下に module.modulemap ファイルを module Choge [system] { header "/usr/local/include/hoge.h" link "hoge" export * } のようにしておくと、他の target で dependencies に Choge を入れておくだけで import して使えるようになります(みなさんもうとっくに知ってた話かな?) ただ(標準の library search path に入っていない?)ライブラリをリンクをするには linkerSettings: [ .unsafeFlags(["-L/usr/local/lib"]), .linkedLibrary("hoge") ] のようにしなきゃいけなくて、この unsafeFlag がどうにかならんもんかと思っています…swift run するだけなら export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib をするだけで library search path に追加してくれるようなのですが、Xcode にはこの設定が反映されないようです
2$ swift package config set-mirror \ --mirror-url https://github.com/kishikawakatsumi/KeychainAccess \ --package-url https://github.com/tikidunpon/KeychainAccess こうしても必ずmirrorの方がはじめにcloneされる..forkには対応していない? .package(url: "https://github.com/tikidunpon/KeychainAccess", from: "3.0.0"), beta3だからかな、beta6同梱の方で後で試すか (edited)swift-5.0.3-RELEASEツールチェインのSwiftPMがmanifest parse errorで動かない。 $ xcrun --toolchain org.swift.50320190830a swift test /Users/norio/github/SwiftLint: error: manifest parse error(s): <unknown>swift-4.2.4-RELEASEのSwiftPMは動く。swift-5.0.3-RELEASEツールチェインのSwiftPMはエラーになる。swift-5.0.3-RELEASEは署名がおかしかったらしい。再度ダウンロードしてインストールし直したら直った。Package@4.swift みたいな仕様って今もありますか?文書が見つけられず。.platforms: [.iOS(.v12)]を使いたいけど、 Swift4はその定義ができない、というもの。.swift, .c, .s, etc as source files, and has built-in rules to determine which build tool to invoke for each known type of source file. .sがサポートされてる?
(edited).Sを.cppにasm()で埋め込むとかしたことがある。swift-DEVELOPMENT-SNAPSHOT-2019-10-14-aでも対応してない様に見える。// swift-tools-version:5.0でサポートされてた。let package = Package( name: "Resources", targets: [ .target( name: "Resources", __resources: [ .copy("foo.txt"), ] ), ] )@package(url: "https://github.com/jpsim/Yams.git", from: "2.0.0") import Yams@import SPMNoModuleNoNamae; でシンプルにそんな奴はいないってエラーになるswift-5.1.5-RELEASE タグが付け直されて、OSSツールチェインも更新されてた。 https://github.com/apple/swift-package-manager/releases/tag/swift-5.1.5-RELEASEOTHER_LDFLAGSを構成ごとに-framework Fooと-lFoo.oで切り替える事は出来た。swift/utils/update_checkout/update-checkout-config.jsonにYamsのチェックアウト情報が載る様になってると気づいて調べたら、SwiftPMで--use-integrated-swift-driverオプションとか使える様になってたのね。 https://github.com/apple/swift-package-manager/pull/2736swift package clean後のswift build所要時間が10%くらい短くなるな。 (edited)xcshareddata にできる Package.resovled って (edited){ "object": { "pins": [ { "package": "KeyboardGuide", "repositoryURL": "https://github.com/niw/KeyboardGuide", "state": { "branch": null, "revision": "f52e9881d8aa9b93dd76b9596e4d2c40a9b99308", "version": "0.2.0" } } ] }, "version": 1 }/* Begin XCRemoteSwiftPackageReference section */ 5413B883249A7D32003873A4 /* XCRemoteSwiftPackageReference "KeyboardGuide" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/niw/KeyboardGuide"; requirement = { kind = upToNextMajorVersion; minimumVersion = 0.2.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ 5413B884249A7D32003873A4 /* KeyboardGuide */ = { isa = XCSwiftPackageProductDependency; package = 5413B883249A7D32003873A4 /* XCRemoteSwiftPackageReference "KeyboardGuide" */; productName = KeyboardGuide; };# See LICENSE folder for this sample’s licensing information. # # Apple sample code gitignore configuration. # Finder .DS_Store # Xcode - User files xcuserdata/ **/*.xcodeproj/project.xcworkspace/* !**/*.xcodeproj/project.xcworkspace/xcshareddata **/*.xcodeproj/project.xcworkspace/xcshareddata/* !**/*.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings **/*.playground/playground.xcworkspace/* !**/*.playground/playground.xcworkspace/xcshareddata **/*.playground/playground.xcworkspace/xcshareddata/* !**/*.playground/playground.xcworkspace/xcshareddata/WorkspaceSettings.xcsettingsWorkspaceSettings.xcsettings は無視か...!! が付いてるから ignore 対象ではなく commit ?
/* ってそのレベルだけだっけPackage.resovled はコミットなのかな?.gitignore は無視する(コミットから除外する)ファイルを書くもので、 !**/*.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings のように ! から始まるものは除外対象でなくす(つまりコミット対象とする)じゃないですか? WorkspaceSettings.xcsettings はコミット対象かと。.gitignore だと除外されちゃいますね。Package.resolved はやっぱりコミットするものですよね@import TestPackage; 実際これが出力されちゃうのが問題みたいですね。PrintAsObjCモジュールのバグな気がする。@objc 付きの protocol があるところか@import TestPackage は必要なのか。swiftSettings: [.unsafeFlags(...)] で無理矢理 ObjC用ヘッダを出すとか? (edited)module TestPackage { header "TestPackage-Swift.h" export * }swiftSettings: [.unsafeFlags(...)] でパッケージ側から注入できたらマシだなあOTHER_CFLAGS でも試してみるか...import TestPackageObjC は普通に成功したから (edited)module TestPackageObjC { export * }TestFramework-Swift.h には @import TestPackageObjC; が書かれるんですね。@objc で。SwiftPackage-Swift.h として Swiftで見えてるものを ObjC ふうにexportするんですよね@import 成功するいめっじinclude/module.modulemap をターゲットソースに入れておくと、C/ObjCターゲットの場合condition: .when(platforms: [.macOS])とかの時に-emit-objc-header相当の設定をPackage.swift内で持たせられる様になれば良いのだろうか。-Xcc -fmodule-map-file=.../GeneratedModuleMaps/... をつけてるなあ (edited)SWIFT_INSTALL_OBJC_HEADER = NO;@import TestPackage; って書いた.mファイルをframeworkに足すimport TestPackageもObjective-Cで@import TestPackage;のどちらも出来た。
(edited)type: .dynamicは.frameworkではなく.dylibになる。
-fmodule-map-file=で渡しているのは変わらないけどmodulemap内でのTestPackage-Swift.hの記述が、SwiftPMはフルパスでXcodeはファイル名だけという違いがあった。 (edited)-module-map-file here.SWIFT_INSTALL_OBJC_HEADER to NO, because you don't really need the generated ObjC compatibility header in that case.ViewController.oのビルド時にはついてないですね。
-module-map-fileがつけられてビルドされる。-module-map-fileが使われてて回答されてるSwiftの挙動と違うと、突っ込んでる人がいるね。挙動に一貫性が無いから、バグとして修正されそうな気がする。 (edited)swift build --arch x86_64 --arch arm64でユニバーサルバイナリになるらしい。 (edited)AboutWindow っていう xib は Resources として存在してるのかな...? (edited)なんとか.app/Contents/Resources かな?cp -Rp "$DERIVED_FILE_DIR/..." ".../Resource"let package = Package( name: "namae",let package = Package( name: "SwiftPM",.target の .dependencies: [] で .product(..., package: "一致してないやつのnamae") に書くとそんなpackageはありませんみたいなこと言われる (edited).product(name: "Fluent", package: "fluent"), みたいな書き方ありますけどそう言う話じゃないですよね?package: に書く文字列が namae だとそんなのねーよって言われるんですよねlet package = Package( name: "namae", っていうのが github.com/meow/chotto-chigau-namae.git にあるとして。Package@swift-5.3.swift って書き方があるんですね。Package.swift と両方あったら5.3だとそれを読んでくれるみたい。 public var versionSpecificKeys: [String] { return [ "@swift-\(major).\(minor).\(patch)", "@swift-\(major).\(minor)", "@swift-\(major)", ] } こんな感じで書けるっぽい。Package@swift-*.swiftはSwift 4.0のベータ期間中から使ってますね。 https://github.com/jpsim/SourceKitten/commit/299fcb45aacdf3044212d2c3f549eae096db3225targets: [ .target( name: "SwiftFiddleEditor", dependencies: [ .product(name: "LSPBindings", package: "SourceKitLSP"), .product(name: "ArgumentParser", package: "swift-argument-parser"), "Ambassador", ]), のようにターゲットの依存の記述には名前だけでOKなのと名前とパッケージのマッピングが必要なのもの、 let package = Package( name: "SwiftFiddleEditor", dependencies: [ .package(name: "SourceKitLSP", url: "https://github.com/apple/sourcekit-lsp", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")), .package(url: "https://github.com/envoy/Ambassador.git", from: "4.0.0"), ], パッケージの記述の方にもパッケージ名を示してあげる必要があるもの、と知らないとけっこう難しいな。エラーメッセージがかなり正確に教えてくれるからいいけど。 (edited)sourcekit-lsp になって、sourcekit-lsp でよくなるんですかね?.branch("main")) と from: "4.0.0" と.upToNextMinor(from: "0.3.1") とか正直いって型やパラメータ名を分ける必要ないと思う。 分かれてても結局文字列で書いたもので決まるわけで。~ とか <= とか使うけど、あれの書き方を忘れちゃうし、ミスするので、 .branch とか .upToNextMinor が補完で出てきて、 コンパイルが通れば文法があってる、というスタイルは僕は良いと思ってます。from: だけはよくわかんないので嫌い。~ と ^ があったりするけど、どっちがなんだったかもよくわからなくなるし、 そういう意味でも upToNextMinor とかは名前からわかりやすい。.package(name: "SourceKitLSP", url: "https://github.com/apple/sourcekit-lsp", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")), .package(url: "https://github.com/envoy/Ambassador.git", from: "4.0.0"), ちょうどこれがわかりやすいと思うんですけど、一貫性があまりなくてめっちゃ難しくないです? バージョンの指定は from: "4.0.0" と .upToNextMinor(from: "0.3.1") でupToNextMinor外側に書くのか、、、って感じだし、 from: "4.0.0" と .branch("main") もそっちは引数名でこっちは型なの?みたいな。from: "4.0.0" になるやつは、from: "4.0.0" と書くのは .upToNextMajor(from: "4.0.0") と書くのと同じなんですよね。.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")), .package(url: "https://github.com/envoy/Ambassador.git", from: "4.0.0"), の2つは一緒か。from: "4.0.0" この書き方できなくていいよね?from: "4.0.0" が提供されている。.upToNextMajor(from:) と .upToNextMinor(from:) に対して、 .branch() はラベルがないのは、.branchとか upToNextMinor が Package.Dependency.Requirement というのはわかったのでわかるけど。..< を活用しているのかな?Range<Version> って言われても書けないでしょ、とか。"1.2.3" ..< "1.3.0" とか書けるんでしょうね。 (edited)name については言及されてませんでした .product(name: "CSV", package: "CSV.swift"),name 指定がある時、package: にそのnameを指定するっぽい。-Xswiftc よりはよいと思うけれど、Package.swift が DSL で、これは JSON でとなんだかいろいろバラエティにとんできててちょっとアレな気持ち--helpの出力に載るかどうかで、そのオプションの扱いがわかる様です。--destinationは載ってこない。swift package completion-tool generate-zsh-scriptの出力には--helpに載ってこないオプションも含まれるので、completionを定期的に更新しておくと補完時に新機能に気づいたりします。--help-hidden 的なオプションは無いのかswift package completion-toolの出力はSE-0206 Hashable Enhancementsの影響を受けるので、SWIFT_DETERMINISTIC_HASHING=1を併用するのがおすすめ。@testable import してても Xcode 上で Enable Testability YES なら Release でテストできるけど、 SwiftPM で -c release でテストする方法ってないんですっけ?-enable-test-discovery をつければできる?--enable-testing だけを有効にするSwiftPMオプションが-Xswift --enable-testing でいけそう$ swift test -c release -Xswift --enable-testing error: unknown option -Xswift; use --help to list available options Did you mean -Xswiftc?$ swift test -c release -Xswiftc --enable-testing <unknown>:0: error: unknown argument: '--enable-testing'-enable-testing$ swift test -c release -Xswiftc -enable-testing ならいけた。-Xswiftc つけるのがめんどうなら Package.swift で unsafeFlags で設定できます (edited)--enable-test-discovery より -Xswiftc -enable-testing の方が直接的な感じでいいかな?--enable-test-discovery がついてるとアプリとしては動かなくなるの?--enable-test-discovery でも -Xswiftc -enable-testing でもどっちでも同じ話じゃない?--enable-testing が無いのか」でいいのかな--enable-test-discovery Enable test discovery on platforms without Objective-C runtime これできるなら LinuxMain って何のためにあるの?swift package _format でSwiftPMプロジェクトにswift-formatかけられるようになってた…!swift-format は公式のToolchainには入っていないのでまだ PATH に自前インストールしておく必要があるんですね。 (edited)$ swift format と何が違うんだ?$ swift format が使えるのだから、 $ swift package _format と打っても長いだけDYLD_LIBRARY_PATH で動的リンクするlib_InternalSwiftSyntaxParserを切り替える.build/checkout もフォーマット対象ですね。swift-format は主に Google が開発保守しているのですよね。swift build --arch x86_64 --arch arm64とするとSwiftPMはユニバーサルバイナリを生成する。 この時SwiftPMは、マニフェストを生成してジョブをXcode.app/Contents/SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuildへ丸投げするぽい。--show-bin-pathは.build/apple/Products/Releaseとかになる。 (edited)error: could not find executable for 'xcode-select'でエラーになる。fatalError("could not load resource bundle: from \\(mainPath) or \\(buildPath)")@main をつかった main.swift がない executable な Product が swift build できない気がするerror: executable product 'meowmeow' expects target 'meowmeow' to be executable; an executable target requires a 'main.swift' file@main な Struct があるから実行できるexecutableProductTargetNotExecutable かな。 /// Determine target type based on the sources. fileprivate func computeTargetType() -> Target.Kind { let isLibrary = !relativePaths.contains { path in let file = path.basename.lowercased() // Look for a main.xxx file avoiding cases like main.xxx.xxx return file.hasPrefix("main.") && String(file.filter({$0 == "."})).count == 1 } return isLibrary ? .library : .executable } @available(_PackageDescription, introduced: 999.0) public static func executableTarget( if targetType == .executable && manifest.toolsVersion >= .vNext && warnAboutImplicitExecutableTargets { diagnostics.emit(warning: "in tools version \(ToolsVersion.vNext) and later, use 'executableTarget()' to declare executable targets") }struct CounterApp: App { var body: some Scene { WindowGroup("Counter Demo") { Counter(count: 5, limit: 15) } } } // @main attribute is not supported in SwiftPM apps. // See https://bugs.swift.org/browse/SR-12683 for more details. CounterApp.main()// TODO: Remove `main.swift` and use `@main` here instead when Swift Package Manager // supports `executableTarget`. // See <https://github.com/apple/swift-package-manager/pull/3045>. // @mainswift build --arch x86_64 --arch arm64とするとSwiftPMはユニバーサルバイナリを生成する。 clangの呼び出しを乗っ取ってclangへ-march=nehalemオプションを渡す仕組みが入ってる。しかし--arch arm64のオブジェクトファイル生成時にも渡されてしまい、-march=nehalemがサポートされてないオプションとしてエラーとなる。 https://github.com/Homebrew/homebrew-core/pull/66918
(edited)Package.Dependency は URL と path 両方とれないんだなあ...Package.resolved をコミットするかどうかってなにかルールあるのかなあ。Gemfile.locl 的なものだからReactiveSwift が ReactiveCocoa にリンクされてる?Package.swift が TOML とかでなく Swift であるが故にコマンドで編集した時と手動で編集した時でインデントや改行のルールが違ったりしてヤキモキしそうですね (edited) /// Provides information about the input files in the target being built, /// including sources, resources, and other files. The order of the files /// is not defined but is guaranteed to be stable. /// This allows the implementation to be more efficient than a static /// file list. protocol FileList: Sequence { func makeIterator() -> FileListIterator struct FileListIterator: IteratorProtocol { mutating func next() -> FilePath? } } なんだこりゃimport PackagePlugin // This example configures `swiftgen` to write to a "SwiftGenOutputs" directory. let generatedSourcesDir = targetBuildContext.outputDir.appending("SwiftGenOutputs") commandConstructor.addPrebuildGeneratedSourceDirectory(generatedSourcesDir) // Create a command to run `swiftgen` as a prebuild command. It will be run before // every build and generates source files into an output directory provided by the // build context. commandConstructor.addCommand( displayName: "Running SwiftGen", executable: try targetBuildContext.lookupTool(named: "swiftgen"), arguments: [ "config", "run", "--config", "\(targetBuildContext.packageDir.appending("swiftgen.yml"))" ], environment: [ "PROJECT_DIR": "\(targetBuildContext.packageDir)", "TARGET_NAME": "\(targetBuildContext.targetName)", "DERIVED_SOURCES_DIR": "\(generatedSourcesDir)", ] )swiftgen.yml に書いてあるだろうけどどうやって動くんだstrings: inputs: Resources/Base.lproj outputs: - templateName: structured-swift5 output: Generated/Strings.swift xcassets: inputs: - Resources/Images.xcassets - Resources/MoreImages.xcassets - Resources/Colors.xcassets outputs: - templateName: swift5 output: Generated/Assets.swiftaddCommand にworkindDirectoryを指定するパラメータがあればswiftgenに手を入れずに解決できるのでは?let package = Package( name: "MyPackage", dependencies: [ .package(url: "https://github.com/SwiftGen/SwiftGen", from: "6.4.0") ] targets: [ .executable( name: "MyLibrary", plugins: [ .plugin(name: "SwiftGenPlugin", package: "SwiftGen") ] ) ] )
MyPackageの依存関係にプラグインの依存が入る?// swift-tools-version: 999.0 import PackageDescription let package = Package( name: "SwiftGen", targets: [ /// Package plugin that tells SwiftPM how to run `swiftgen` based on /// the configuration file. Client targets use this plugin by listing /// it in their `plugins` parameter. This example uses the `prebuild` /// capability, to make `swiftgen` run before each build. /// A different example might use the `builtTool` capability, if the /// names of inputs and outputs could be known ahead of time. .plugin( name: "SwiftGenPlugin", capability: .prebuild(), dependencies: ["SwiftGen"] ), /// Binary target that provides the built SwiftGen executables. .binaryTarget( name: "SwiftGen", url: "https://url/to/the/built/swiftgen-executables.zip", checksum: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ), ] )try targetBuildContext.lookupTool(named: "swiftgen"), じゃあこれは結構特殊なlookupなんだなswiftSettings: [ .define("XXX") ] とすればソース内 #if XXX のようにマクロが使えるようになりますが,依存パッケージに対してマクロを指定することってできますか? Package A で #if XXX のようなコードを書いておき,それに依存する Package B が dependency の中で A に対して上のように設定したい。 (既出だったらすみません) (edited) dependencies: [ #if USE_A .package(path: "../a/") #endif ],-Xswiftc -DUSE_A と指定すると,B は A も含めてビルドされるし,指定しなければ A を含めずにビルドされる,という感じにしたいです. (edited).condition(platforms: []) は昔と違って今はできるようになっているので、 なんかパッケージが自身のビルドに影響を与えるパラメータを宣言するような仕組みとセットでの導入ならありえるかも? ただ議論してるのは見たことないので言わないと始まらない状況かも。[features] # Defines a feature named `webp` that does not enable any other features. webp = [] なるほど?// This conditionally includes a module which implements WEBP support. #[cfg(feature = "webp")] pub mod webp; なるほど。// This conditionally includes a module which implements WEBP support. #[cfg(feature = "webp")] pub mod webp; なるほど。 swift test 経由と swift run 経由で、選択される言語が変わってしまうのですが、 何か知ってる人居ませんか.macOS("12.0") でなんとかimport Foundation print("begin") for (k, v) in ProcessInfo.processInfo.environment { print("\(k)=\(v)") } print("end")$ AAAAAAAAAAAAAAAAAA=foo swift run こうやって実行すると、 出力に AAAAAAAAAAAAAAAAAA=foo が出てくるんですが$ DYLD_PRINT_LIBRARIES=YES swift run これは、やってもだめで、 当然、DYLD_PRINT_LIBRARIES の効果も発動しないので困っていますexecve をまっすぐ呼び出しに行っているだけで、そのような特別な処理は見当たりませんでした$ swift package init --type executable でやってみた?DYLD_LIBRARY_PATH で通そうとしているのだけど、$ xcrun -find swift-run /Applications/Xcode12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-run$ DYLD_PRINT_LIBRARIES=YES /usr/local/bin/bash dyld[....]: ......... $ /usr/local/bin/bash dyld[....]: ......... $ /bin/bash The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. $ /usr/local/bin/bashwhich swift が /usr/bin/swift なのでそこで消されてそうDYLD_PRINT_LIBRARIES=YES xcrun swift run これだと大丈夫だ/usr/bin/swift を経由しないから!?00021520 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 |<?xml version="1| 00021530 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 |.0" encoding="UT| 00021540 46 2d 38 22 3f 3e 0a 3c 21 44 4f 43 54 59 50 45 |F-8"?>.<!DOCTYPE| 00021550 20 70 6c 69 73 74 20 50 55 42 4c 49 43 20 22 2d | plist PUBLIC "-| 00021560 2f 2f 41 70 70 6c 65 2f 2f 44 54 44 20 50 4c 49 |//Apple//DTD PLI| 00021570 53 54 20 31 2e 30 2f 2f 45 4e 22 20 22 68 74 74 |ST 1.0//EN" "htt| 00021580 70 3a 2f 2f 77 77 77 2e 61 70 70 6c 65 2e 63 6f |p://www.apple.co| 00021590 6d 2f 44 54 44 73 2f 50 72 6f 70 65 72 74 79 4c |m/DTDs/PropertyL| 000215a0 69 73 74 2d 31 2e 30 2e 64 74 64 22 3e 0a 3c 70 |ist-1.0.dtd">.<p| 000215b0 6c 69 73 74 20 76 65 72 73 69 6f 6e 3d 22 31 2e |list version="1.| 000215c0 30 22 3e 0a 3c 64 69 63 74 3e 0a 09 3c 6b 65 79 |0">.<dict>..<key| 000215d0 3e 63 64 68 61 73 68 65 73 3c 2f 6b 65 79 3e 0a |>cdhashes</key>.| 000215e0 09 3c 61 72 72 61 79 3e 0a 09 09 3c 64 61 74 61 |.<array>...<data| 000215f0 3e 0a 09 09 43 39 55 4b 59 6e 61 68 38 57 6d 47 |>...C9UKYnah8WmG| 00021600 68 50 42 4f 6e 38 31 52 6d 54 44 69 39 48 30 3d |hPBOn81RmTDi9H0=| 00021610 0a 09 09 3c 2f 64 61 74 61 3e 0a 09 3c 2f 61 72 |...</data>..</ar| 00021620 72 61 79 3e 0a 3c 2f 64 69 63 74 3e 0a 3c 2f 70 |ray>.</dict>.</p| 00021630 6c 69 73 74 3e 0a 30 0d 06 09 2a 86 48 86 f7 0d |list>.0...*.H...|$ strings /usr/bin/swift llvm-gcc clang llvm-g++ clang++swift-run からも見つからないなDYLD_PRINT_LIBRARIES=YES "$(xcrun -f swift)" とかしてやるとよさそうxcrun swift test はだめだった)xcrun swift だとダメですねDYLD_PRINT_LIBRARIES=YES "$(xcrun -f swift)" とかしてやるとよさそう $ swift build $ DYLD_LIBRARY_PATH=... ./build/debug/codegen でいいですね。$ swift test の生実行はどうやるんだ?$ xctest test.bundle だっけDYLD_PRINT_LIBRARIES=YES "$(xcrun -f swift)" test とかでいけないかなxcrun xctest .build/debug/ExamplePackageTests.xctestDYLD_LIBRARY_PATH=/Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx xcrun xctest .build/debug/SwiftTypeReaderPackageTests.xctest これはだめだったxcrun -f でとってきたパスに対する実行なのね。DYLD_LIBRARY_PATH=/Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx $(xcrun -f xctest) ./build/debug/SwiftTypeReaderPackageTests.xctest❯ DYLD_LIBRARY_PATH=/Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx /Applications/Xcode_13_beta.app/Contents/Developer/usr/bin/xctest -XCTest .build/debug/SwiftTypeReaderPackageTests.xctest/2021-06-11 13:40:03.625 xctest[27034:1392524] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSSetM addObject:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x00007fff205b287b __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff202ead92 objc_exception_throw + 48 2 CoreFoundation 0x00007fff206682ea _CFThrowFormattedException + 202 3 CoreFoundation 0x00007fff2066f993 -[__NSSetM addObject:].cold.2 + 0 4 CoreFoundation 0x00007fff205168de -[__NSSetM addObject:] + 720 5 XCTest 0x0000000109375314 -[XCTTestIdentifierSetBuilder addTestIdentifier:] + 64 6 xctest 0x0000000109174a84 main + 1963 7 libdyld.dylib 0x00007fff2045af5d start + 1 8 ??? 0x0000000000000003 0x0 + 3 ) libc++abi: terminating with uncaught exception of type NSException [1] 27034 abort DYLD_LIBRARY_PATH= -XCTest .build/debug/SwiftTypeReaderPackageTests.xctest/$(xcrun -f xctest) .build/debug/SwiftTypeReaderPackageTests.xctest/ Test Suite 'All tests' started at 2021-06-11 13:40:58.856 Test Suite 'SwiftTypeReaderPackageTests.xctest' started at 2021-06-11 13:40:58.857 Test Suite 'SwiftTypeReaderTests' started at 2021-06-11 13:40:58.857 Test Case '-[SwiftTypeReaderTests.SwiftTypeReaderTests testEnum]' started. Segmentation fault: 11#if swift(>=5.5) dependencies.append( .package( name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax", .branch("release/5.5-05142021") ) ) #elseif swift(>=5.4) dependencies.append( .package( name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax", .exact("0.50400.0") ) ) #elseif swift(>=5.3) dependencies.append( .package( name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax", .exact("0.50300.0") ) ) #else fatalError("This version of Periphery does not support Swift <= 5.2.") #endifcp "$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib" .releaseinstall_name_tool は使ってないな 実行ファイルの隣に置いてOSが自然に見つけるパターンか // NG products: [ .library( name: "MyView", type: .static, targets: ["MyView"] ), ] // OK products: [ .library( name: "Preview", type: .dynamic, targets: ["MyView", "MyView2"] ), .library( name: "App", type: .static, targets: ["App"] ), ], A2. Bundle.moduleの生成されたコードが、Previewの場合にはBundleが生成されずにFatalErrorに落ちる不具合がある。 https://forums.swift.org/t/swiftui-previewer-crashes-while-in-swift-package-that-depends-on-anothers-packages-bundle-module-reference/41736 Bundle.moduleは利用せずに自前でBundleのextensionを書く。辛いけど仕方ない。 (edited)Package.swift を Result Builder で書けるようにする話が出てる1. The manifest defines 2 publicly available build artifacts, an executable named MyExecutable and a library named MyLibrary. To define these artifacts, the manifest requires definition of two abstractions: a Target and a Product, having the Target representing a source module and the Product representing a public build artifact. Worth noting that in many cases, each Product points to exactly one Target.
1
1var package = Package(..) package.addProduct(name: "Foo") .module 指定でPreviewできない件、自分もハマったのでまとめました。特にココでの議論から進展はないのですが、実は他の解決方法とか新情報がありましたら教えていただけると嬉しいです .intentdefinition のように Xcode が自動生成するファイル( FooIntent.swift )があるものを、うまく Swift Package に閉じ込める方法をご存じの方がいたら教えてほしいです exact: の場合のコメントが /// It allows you to specify the minimum version you require, allows updates that include bug fixes /// and backward-compatible feature updates, but requires you to explicitly update to a new major version of the dependency. ↑マイナーバージョンは固定しないように見えるんだけど、 コメントが間違ってるのか、それともexactがこう変わった(元から?)んだろうか? (edited)@available(_PackageDescription, deprecated: 5.6, message: "use specific requirement APIs instead (e.g. use 'branch:' instead of '.branch')") public static func package( url: String, _ requirement: Package.Dependency.Requirement ) (edited).upToNextMajor → from: (前からあった) .branch → branch:
.revision → revision: の対応があるんだけど、 .upToNextMinor の対応が存在しなくて、コメントからするとそれが exact: に見える で .exact の対応してそうな exact: は消えた?.upToNextMinor はドット形式で今後も書けるのか。ただし実はドットがついてる左辺値型が変わるのか。.latestStable 的なものも欲しいですが、そこらへん何か議論あったりしますかね .upToNextMajor に直さないといけないので、他のパッケージが全部 .latestStable だったら、「あこの .upTpNextMajor のものはメジャーアプデがあるから移行対応しないとだな」ってすぐわかるswift run でコマンドラインツールを走らせたときに SIGINT で止まらなくなって困っていたんですが,意外と Jira でも Forums でも Pull requests でもそれらしい言及がなかったので原因を探って PR を出してみました.困っている人は本当に困っていそうな問題なので共有してみます. 理解が間違っているところとかがあればご指摘いただけると嬉しいです. https://github.com/apple/swift-package-manager/pull/4224swift run でコマンドラインツールを走らせたときに SIGINT で止まらなくなって困っていたんですが,意外と Jira でも Forums でも Pull requests でもそれらしい言及がなかったので原因を探って PR を出してみました.困っている人は本当に困っていそうな問題なので共有してみます. 理解が間違っているところとかがあればご指摘いただけると嬉しいです. https://github.com/apple/swift-package-manager/pull/4224 Showing Recent Issues The operation couldn’t be completed. (SwiftPM.SPMRepositoryError error 5.) 特定のパッケージを更新して Package.swift を resolve しようとすると発生しました。 詳細は以下のスレッドに載せています。 https://twitter.com/the_uhooi/status/1505577290444713989?s=20&t=OtpKypkRTqgGV1873rtONA (edited)~/Library/Developer/Xcode/DerivedData ディレクトリを消したら直りました。
The operation couldn’t be completed. (SwiftPM.SPMRepositoryError error 5.) はXcode 13.2とか前からのプロジェクトをXcode 13.3で開くと起こるっぽい。 だから新しいプロジェクトやCIでは起こらなかったんじゃないか。 解決方法はDerived Dataを消したり.buildを消したり。SwiftPM.SPMRepositroyError って SwiftPM 側のエラー型かと思いきや Xcode の内部的なエラー型なのですね.ということはもしかしたら Xcode 固有の問題かもしれないですね.(もしそうであれば .build が原因になることはないような気が...)SwiftPM.SPMRepositroyError って SwiftPM 側のエラー型かと思いきや Xcode の内部的なエラー型なのですね.ということはもしかしたら Xcode 固有の問題かもしれないですね.(もしそうであれば .build が原因になることはないような気が...)
1$ nm -g /Applications/Xcode-13.3.0.app/Contents/PlugIns/IDESwiftPackageCore.framework/Versions/A/Frameworks/SwiftPM.framework/SwiftPM | grep SPMRepositoryError 000000000006f64c T _$s7SwiftPM18SPMRepositoryErrorO010underlyingD010repositoryACSgSo7NSErrorC_So32DVTSourceControlRemoteRepositoryCSgtcfC 00000000005ae108 S _$s7SwiftPM18SPMRepositoryErrorO10Foundation09LocalizedD0AAMc 00000000005ae178 S _$s7SwiftPM18SPMRepositoryErrorO10TSCUtility27DiagnosticLocationProvidingAAMc 00000000006b0ba8 S _$s7SwiftPM18SPMRepositoryErrorO10TSCUtility27DiagnosticLocationProvidingAAWP 000000000006f9e8 T _$s7SwiftPM18SPMRepositoryErrorO11descriptionSSvg 00000000005ae1d8 S _$s7SwiftPM18SPMRepositoryErrorO11descriptionSSvpMV 000000000006f684 T _$s7SwiftPM18SPMRepositoryErrorO16errorDescriptionSSvg 00000000005ae1d8 S _$s7SwiftPM18SPMRepositoryErrorO16errorDescriptionSSvpMV 000000000006f9ec T _$s7SwiftPM18SPMRepositoryErrorO18diagnosticLocation8TSCBasic010DiagnosticF0_pSgvg 00000000005ae1d8 S _$s7SwiftPM18SPMRepositoryErrorO18diagnosticLocation8TSCBasic010DiagnosticF0_pSgvpMV 0000000000073e54 T _$s7SwiftPM18SPMRepositoryErrorOMa 00000000005ae204 S _$s7SwiftPM18SPMRepositoryErrorOMn 00000000006b0c78 S _$s7SwiftPM18SPMRepositoryErrorON 00000000005ae188 S _$s7SwiftPM18SPMRepositoryErrorOs0D0AAMc 00000000005ae150 S _$s7SwiftPM18SPMRepositoryErrorOs23CustomStringConvertibleAAMc~/Library/Developer/Xcode/DerivedData ディレクトリを消したら直りました。
.build フォルダなどを削除して resolve し直したら直りました。cause でチェーンして示すというのがいいんでしょうね。すべてが型付けされていれば、最上位レイヤーで起こり得るエラーが( cause も含めて)型で洗い出すことが可能になり、そこからユーザーが必要になる粒度に応じてエラーメッセージを提供するみたいな。めっちゃ実装面倒ですが。 Swift の Forums でも、仮に Typed Throws を採用しても、複数のエラー型を列挙できるようにはしないという話がされていて、おそらくその理由は各レイヤーでそれらの粒度に応じてエラーを包み直すのが望ましいからかと。.upToNextMajor → from: (前からあった) .branch → branch:
.revision → revision: の対応があるんだけど、 .upToNextMinor の対応が存在しなくて、コメントからするとそれが exact: に見える で .exact の対応してそうな exact: は消えた? .exact の非推奨コメントに自分も遭遇しました。 Xcode13.3を境に .exact -> exact: になったのですね! (新しい方のドキュメントの概要欄は、未記載の状態のようですが...。) .exact の非推奨コメントに自分も遭遇しました。 Xcode13.3を境に .exact -> exact: になったのですね! (新しい方のドキュメントの概要欄は、未記載の状態のようですが...。) exact: のコメントの文章はおかしいままですか?ドキュメントには出力されてないんですねw (edited)exact: のコメントが間違ってる話だったのですね!ちょっとズレた話題してしまいました.upToNextMinor はどうすればいいんだろう、という疑問で、 コメントの間違いもあったのでさらに疑問が深まってしまったというものでした。
1:exact だけでなく、 :from のコメントも同じくおかしいぽいです。おんなじコピペコメントでした。.exact は exact: に変わるけど、 .upToNextMinor はそのまま使える。exact: とかのAPI変更ってプロポーザルあるんだっけ @d_date 知ってる?:exact だけでなく、 :from のコメントも同じくおかしいぽいです。おんなじコピペコメントでした。 from: のやつを exact: に間違ってコピペしちゃったんだと思ってました
1from: のやつを exact: に間違ってコピペしちゃったんだと思ってました .exact は exact: に変わるけど、 .upToNextMinor はそのまま使える。 exact: とかのAPI変更ってプロポーザルあるんだっけ @d_date 知ってる? .upToNextMinor を使うのは非推奨にならない…のでしょうか? .package(url: String, "1.2.0"..<"1.3.0") のように範囲指定するのが推奨になるのかなぁと思っていました。 ref: https://developer.apple.com/documentation/swift_packages/package/dependency/requirement/2878234-uptonextminor 自分のイメージ↓ // Before .package(url: String, .branch("release/5.6")) .package(url: String, .revision("e74b07278b926c9ec6f9643455ea00d1ce04a021")) .package(url: String, .exact("1.2.0")) .package(url: String, .upToNextMajor(from: "1.2.0")) .package(url: String, .upToNextMinor(from: "1.2.0")) // After .package(url: String, branch: "release/5.6") .package(url: String, revision: "e74b07278b926c9ec6f9643455ea00d1ce04a021") .package(url: String, exact: "1.2.0") .package(url: String, from: "1.2.0") // `.package(url: String, "1.2.0"..<"2.0.0")` と同義 .package(url: String, "1.2.0"..<"1.3.0") ref: https://github.com/uhooi/mobile-app-trends/blob/main/2021/2021_4q.md#56リリース-0223.upToNextMinor を使うのは非推奨にならない…のでしょうか? .package(url: String, "1.2.0"..<"1.3.0") のように範囲指定するのが推奨になるのかなぁと思っていました。 ref: https://developer.apple.com/documentation/swift_packages/package/dependency/requirement/2878234-uptonextminor 自分のイメージ↓ // Before .package(url: String, .branch("release/5.6")) .package(url: String, .revision("e74b07278b926c9ec6f9643455ea00d1ce04a021")) .package(url: String, .exact("1.2.0")) .package(url: String, .upToNextMajor(from: "1.2.0")) .package(url: String, .upToNextMinor(from: "1.2.0")) // After .package(url: String, branch: "release/5.6") .package(url: String, revision: "e74b07278b926c9ec6f9643455ea00d1ce04a021") .package(url: String, exact: "1.2.0") .package(url: String, from: "1.2.0") // `.package(url: String, "1.2.0"..<"2.0.0")` と同義 .package(url: String, "1.2.0"..<"1.3.0") ref: https://github.com/uhooi/mobile-app-trends/blob/main/2021/2021_4q.md#56リリース-0223 .upToNextMinor は非推奨にならないです。 元々あった Package.Dependency.Requirement を返す .upToNextMinor は deprecated 指定されているんですが、 それとは別に新しく Range<Version> を返す .upToNextMinor が追加されるのです。 コードはここです。(Appleのドキュメントだとどこにあるかはわからなかったです) https://github.com/apple/swift-package-manager/blob/e25a590dc455baa430f2ec97eacc30257c172be2/Sources/PackageDescription/PackageRequirement.swift#L219 それが https://discord.com/channels/291054398077927425/304939011904897024/948065337448996955 で書いている事です。 つまり、 .upToNextMinor と書いたときに これまでは Package.Dependency.Requirement.upToNextMinor と解釈されていたのが、 これからは Range<Version>.upToNextMinor と解釈される、という事です。
2.upToNextMinor は非推奨にならないです。 元々あった Package.Dependency.Requirement を返す .upToNextMinor は deprecated 指定されているんですが、 それとは別に新しく Range<Version> を返す .upToNextMinor が追加されるのです。 コードはここです。(Appleのドキュメントだとどこにあるかはわからなかったです) https://github.com/apple/swift-package-manager/blob/e25a590dc455baa430f2ec97eacc30257c172be2/Sources/PackageDescription/PackageRequirement.swift#L219 それが https://discord.com/channels/291054398077927425/304939011904897024/948065337448996955 で書いている事です。 つまり、 .upToNextMinor と書いたときに これまでは Package.Dependency.Requirement.upToNextMinor と解釈されていたのが、 これからは Range<Version>.upToNextMinor と解釈される、という事です。
1"1.0.0"..<"1.1.0" は冗長なので微妙だと思うんですよね~from: ですが大きいライブラリは .upToNextMinor で指定してますね。 マイナーバージョンでも壊してしまう事はたまにあるだろうという前提で、 それが起こったときに大きいライブラリだと状況の解析が大変だから。Identifiable は Swift 5.1 からだけど、これを利用するライブラリを Swift 5.1 以降のみに提供したいとして、 Package.swift にどのように記述するのが良いでしょうか? platforms で記述すると全プラットフォームサポートするの大変だし( Linux や Windows は指定できない?)、 swiftLanguageVersions でも .v5 とかの単位でしか指定できない?// swift-tools-version: 5.6 ↑でも Identifiable を使おうとするとビルドエラーになりますね。ツールのバージョンとサポートされる言語のバージョンは別かと。 (edited)// swift-tools-version: 5.6 ↑でも Identifiable を使おうとするとビルドエラーになりますね。ツールのバージョンとサポートされる言語のバージョンは別かと。 (edited)#if swift は使いたくない?#if swift は使いたくない? Identifiable のためのライブラリなので、何もなくなってしまう。 (edited)final public var swiftLanguageVersions: [PackageDescription.SwiftVersion]? public enum SwiftVersion { /// A user-defined value for the Swift version. /// /// The value is passed as-is to the Swift compiler's `-swift-version` flag. case version(String) } (edited)swiftLanguageVersions: [.version("5.1")] って書けないのかなplatforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)], platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)], final public var swiftLanguageVersions: [PackageDescription.SwiftVersion]? public enum SwiftVersion { /// A user-defined value for the Swift version. /// /// The value is passed as-is to the Swift compiler's `-swift-version` flag. case version(String) } (edited)platforms: [.iOS(.v13)] とかじゃダメなのか・・・。
(edited)-swift-version flag. .version("5.1)" とかやっても。platforms: [.iOS(.v13)] のように書いておけば、サポートされてないプラットフォームには単にビルドエラーになるから OK ?platforms: [.iOS(.v13)] のように書いておけば、サポートされてないプラットフォームには単にビルドエラーになるから OK ? platforms 書かなかった場合は何でも OK だけど、 platforms: [.iOS(.v13)] みたいに書いたときは iOS 以外で使えなくなると思ってたんですよね。それが勘違いなら問題ないです。[] も [iOS()] も、tvOSに対してはビルド可能で同じ意味と思ってた// swift-tools-version: 5.6 これがダメだったっていうのがよくわからなかったんですけど、5.6なら使う方はSwift 5.6以上だから問題なさそうに思うんですけど違いますか?// swift-tools-version: 5.6 これがダメだったっていうのがよくわからなかったんですけど、5.6なら使う方はSwift 5.6以上だから問題なさそうに思うんですけど違いますか? Identifable 使うだけで、 platforms 指定がないとビルドエラーになります。 Swift 5.6 でビルドしてもそれ以前の Swift からそのバイナリを利用することはできるので、ビルドするツールのバージョンとサポートされる言語のバージョンは別じゃないでしょうか?platforms The list of supported platforms with a custom deployment target. Identifable 使うだけで、 platforms 指定がないとビルドエラーになります。 Swift 5.6 でビルドしてもそれ以前の Swift からそのバイナリを利用することはできるので、ビルドするツールのバージョンとサポートされる言語のバージョンは別じゃないでしょうか? Identifiable を利用するライブラリを作りたいという話でした。Identifable 使うだけで、 platforms 指定がないとビルドエラーになります。 Swift 5.6 でビルドしてもそれ以前の Swift からそのバイナリを利用することはできるので、ビルドするツールのバージョンとサポートされる言語のバージョンは別じゃないでしょうか? swift-tools-version:, #if compiler : ツールチェーンバージョン #if swift: 言語バージョン(ツールチェーンバージョンより低い事がある)、swiftLanguageVersion: や -swift-version で指定する。 (edited)MLKitFaceDetection.framework と MLKitBarcodeScanning.framework はStatic Frameworkだけど、アプリケーションパッケージ(Example.app)に含まれてしまっていることが直接の原因だと思う。https://date.notion.site/WIP-MLKit-SwiftPM-1f037fc18c834898851fc8d091dce613)を一通りやって、https://github.com/d-date/google-mlkit-swiftpmのワークスベースを開いてビルドします。するとExample.appは生成されるけれども、デバイスへのインストール時に Could not inspect the application package. Domain: com.apple.dt.MobileDeviceErrorDomain Code: -402653103 のようなエラーでインストールに失敗する。0x16d5ab000 -[MIBundle _validateWithError:]: 47: Failed to load Info.plist from bundle at path /var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.WVoNf1/extracted/Example.app/Frameworks/MLKitBarcodeScanning.framework; Extra info about "/var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.WVoNf1/extracted/Example.app/Frameworks/MLKitBarcodeScanning.framework/Info.plist": Couldn't stat /var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.WVoNf1/extracted/Example.app/Frameworks/MLKitBarcodeScanning.framework/Info.plist: No such file or directoryExample.app などのキーワードでログをフィルタすると良い。その上で installd プロセスが出力しているログを探すと見つかる。) (edited)Products/Example.app をShow Finderして、 Example.app パッケージをShow Contentsして Frameworks フォルダからMLKitFaceDetection.framework と MLKitBarcodeScanning.framework を削除します。 (他の人にもわかるように手順を書いています。) (edited)
1Example.app を直接XcodeのDevice and SimulatorsのインストールしたいデバイスのところにDrag & Dropします。 これはインストールに成功するはずです。 2つのFrameworkを取り除かずに同様の操作をすると、同じエラーで失敗します(メッセージも同じ。XcodeがやってることをGUIでやっているだけ)。type: .staticをつけてstatic linkにしても解決しないので、なんかバグっぽいですね。XXX.framework/XXX はstatic archiveファイルになっているはずなんですが、MLKitBarcodeScanningはオブジェクトファイルになっているのがおかしそうです。https://dl.google.com/dl/cpdc/bfc93c9fa703fe9e/MLKitBarcodeScanning-2.1.0.tar.gz を落としてくるだけ(他の人のために書いています)。.o)になっていて、make-xcframeworkがオブジェクトとして分離してしまっているので、そこでアーカイブし直せば良いと思います (edited)make run で MLKitBarcodeScanning.xcframeworkを作った後、 cd ./GoogleMLKit/MLKitBarcodeScanning.xcframework/ios-arm64/MLKitBarcodeScanning.framework/ mv MLKitBarcodeScanning{,.o} ar r MLKitBarcodeScanning MLKitBarcodeScanning.o ranlib MLKitBarcodeScanning rm MLKitBarcodeScanning.o を実行してクリーンビルド (edited) dependencies: [ .product(name: "MLKitBarcodeScanning", package: "google-mlkit-swiftpm"), .product(name: "MLKitFaceDetection", package: "google-mlkit-swiftpm"), ]),
google-mlkit-swiftpm にしろって言われた。Xcode 14だからかな?ar -h usage: ar -d [-TLsv] archive file ... ar -m [-TLsv] archive file ... ar -m [-abiTLsv] position archive file ... ar -p [-TLsv] archive [file ...] ar -q [-cTLsv] archive file ... ar -r [-cuTLsv] archive file ... ar -r [-abciuTLsv] position archive file ... ar -t [-TLsv] archive [file ...] ar -x [-ouTLsv] archive [file ...]ar r ってなんやろって思ってた。Active Compilation Conditions などが引き継がれるわけでもないからどこで紐付いているんだろうと気になった感じで........PackagePlugin や Foundation 以外のパッケージをimportできないみたいな縛りってあったりしますか?swift build --arch x86_64 --arch arm64` ってアーキテクチャを複数指定すると自動的にファットバイナリを作ってくれるんですね。(Macで実行した場合だけ?) そして .build 以下のディレクトリ構成が全然知らないカタチになった。error: Revision adc03993975f0a784daeb6fbfb7e1b70dc8f7554 for codabletotypescript remoteSourceControl https://github.com/omochi/CodableToTypeScript version 2.2.0 does not match previously recorded value 96c462e820ecdae0566695b0ecd81c6fee1ec167proj/.build proj/.swiftpm $HOME/.swiftpm/cache を削除しても駄目。$HOME/.swiftpm/cache は $HOME/Library/Caches/org.swift.swiftpm へのエイリアス。$HOME/Library/org.swift.swiftpm/security を削除する必要がある。
1Library/org.swift.swiftpm の存在知らなくてよくハマってました$HOME/.swiftpm/security が $HOME/Library/org.swift.swiftpm/security へのエイリアスにはなってるな。0.1.0-beta.2 とか使ってます。3.1.4-beta1 ではなく . を挟んで 3.1.4-beta.1 にしておかないと、 beta 9 と beta 10 の順序がおかしくなってしまうので要注意です。 -beta1 でも -beta9 までは文字列比較でうまくいっちゃうのかw-beta1 < -beta10 < -beta2 で 10のときに戻ってきちゃうからドットが要るんですね。Process とか使いづらいのでTSCBasicをいれようと思ったけど、importできなかった・・・// swift-tools-version: 5.6 import PackageDescription let package = Package( name: "MyFormatterPlugin", dependencies: [ .package(url: "https://github.com/apple/swift-format.git", from: "0.50500.0"), ], targets: [ .plugin( name: "MyFormatterPlugin", capability: .command( intent: .sourceCodeFormatting(), permissions: [ .writeToPackageDirectory(reason: "This command reformats source files") ] ), dependencies: [ .product(name: "swift-format", package: "swift-format"), ] ) ] ).plugin() で定義する MyFormatterPlugin は swift-format パッケージの swift-format executable product に依存を宣言していて・・・import PackagePlugin import Foundation @main struct MyFormatterPlugin: CommandPlugin { func performCommand( context: PluginContext, arguments: [String] ) async throws { // We'll be invoking `swift-format`, so start by locating it. let swiftFormatTool = try context.tool(named: "swift-format") // By convention, use a configuration file in the package directory. let configFile = context.package.directory.appending(".swift-format.json") // Iterate over the targets in the package. for target in context.package.targets { // Skip any type of target that doesn't have source files. // Note: We could choose to instead emit a warning or error here. guard let target = target as? SourceModuleTarget else { continue } // Invoke `swift-format` on the target directory, passing a configuration // file from the package directory. let swiftFormatExec = URL(fileURLWithPath: swiftFormatTool.path.string) let swiftFormatArgs = [ "--configuration", "\(configFile)", "--in-place", "--recursive", "\(target.directory)" ] let process = try Process.run(swiftFormatExec, arguments: swiftFormatArgs) process.waitUntilExit() // Check whether the subprocess invocation was successful. if process.terminationReason == .exit && process.terminationStatus == 0 { print("Formatted the source code in \(target.directory).") } else { let problem = "\(process.terminationReason):\(process.terminationStatus)" Diagnostics.error("swift-format invocation failed: \(problem)") } } } }MyFormatterPlugin のコードでは、 context.tool(named: "swift-format") という特殊なAPIを通して、 依存として宣言したexecutableのビルドされた実体を表すオブジェクトを取得し、swiftFormatTool.path.string でファイルパスが書いてあるので、後は Process でそれを発火する。 (edited)let stdout = Pipe() process.standardOutput = stdout let stderr = Pipe() process.standardError = stderr try process.run() process.waitUntilExit() if let data = try stderr.fileHandleForReading.readToEnd(), let error = String(data: data, encoding: .utf8) { print(error) } ... まあでもこんな感じでしょ。Foundation.Processでもまあいいんじゃないかなあ。stdoutPipe.fileHandleForReading.readabilityHandler の実行が task.waitUntilExit() が終わるまでに、 終わる保証が無いのかも (edited)-g が渡されてるか確認するかなぁ swiftSettings: [ .enableUpcomingFeature("BareSlashRegexLiterals") ] ↑使わないとRegex使えないっぽいのなんでや?Status: Implemented (Swift 5.7) Upcoming Feature Flag: BareSlashRegexLiterals (implemented in Swift 5.8) って書いてあってImplementation: apple/swift#42119, apple/swift#58835 Bare slash syntax /.../ available with -enable-bare-slash-regex-enable-bare-slash-regex で使えるよ、という話とTo accommodate the cases where source may be broken, /.../ regex literals will be introduced in Swift 6 mode. However, projects may adopt the syntax earlier by passing the compiler flag -enable-bare-slash-regex or the upcoming feature flag BareSlashRegexLiterals. Note this does not affect the extended delimiter syntax #/.../#, which will be usable immediately.// こういうのとか /* let regex = /[0-9]*/ */ // こういうの x+/y/foo(/a, b/) // Will become regex literal '/a, b/' qux(/, !/) // Will become regex literal '/, !/' qux(/,/) // Will become regex literal '/,/'qux(/,/)reduce(0, +) みたいなやつColor(1/255, 2/255, 3/255) みたいなのが誤動作するっていうのは前にみた。Color(1 / 255, 2 / 255, 3 / 255) って、隙間あけた除算にすればいいみたいですね。/ a / を許さない/ a / は正規表現リテラルとして無効なんすか?/ a / は正規表現リテラルとして無効なんすか? #/ a /# こっちを使う。 (edited)# 付ける・・・sandbox-exec: execvp() of '//Users/zunda/Documents/GitHub/SampleLibrary/DerivedData/SampleLibrary/Build/Products/Debug/SampleExec' failed: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code 検証用コード: https://github.com/zunda-pixel/SampleLibrary 手順: Clean(Shift + Command + K)してからビルドすると上のエラーになります。 何かのバグのように思えるのですが、どういった対処(報告)をすれば良いでしょうか? (edited)Apply build tool plug-in “SwiftLintPlugin” to target “XcodeCloud” in project “XcodeCloud” 2023-06-20T04:33:59.374110103Z 2023-06-20T04:33:59.374194651Z /usr/bin/sandbox-exec -p "(version 1) 2023-06-20T04:33:59.374307420Z (deny default) 2023-06-20T04:33:59.374420261Z (import \"system.sb\") 2023-06-20T04:33:59.374513971Z (allow file-read*) 2023-06-20T04:33:59.374657054Z (allow process*) 2023-06-20T04:33:59.374770999Z (allow file-write* 2023-06-20T04:33:59.374865119Z (subpath \"/private/tmp\") 2023-06-20T04:33:59.374981670Z (subpath \"/private/var/folders/n0/3380ckd54yl7lfjbwcy83w740000gn/T\") 2023-06-20T04:33:59.375082724Z ) 2023-06-20T04:33:59.375173795Z (deny file-write* 2023-06-20T04:33:59.375297157Z (subpath \"/Volumes/workspace/repository/XcodeCloud\") 2023-06-20T04:33:59.375377665Z ) 2023-06-20T04:33:59.375458446Z (allow file-write* 2023-06-20T04:33:59.375564433Z (subpath \"/Volumes/workspace/DerivedData/SourcePackages/plugins/XcodeCloud.output/XcodeCloud/SwiftLintPlugin\") 2023-06-20T04:33:59.375699684Z ) ログを発掘してみたけどこの辺かな。/private/var/folders/n0/3380ckd54yl7lfjbwcy83w740000gn/T って NSTemporaryDirectory()で返ってきそうなパスだけどそこが違うのかもしれない。NSDataWritingAtomic may crash app, so it’s unsafe option.BuildConfiguration が struct なのにプロパティを let にしてるのが無意味でイケてないと僕は思っています。実際にここでやっているように、setterを外部から実装可能なので、結局書き込み禁止できてないからです。最初からvarで良かったのです。 で、こういうextensionはその型に対する汎用的なもので、このファイル固有の目的で必要なものというわけではないので、 他の場所からも見えて良いと思うのです。 ただ定義するファイルがここだと不適切かなと思っています。 (edited)-enable-library-evolution はそれを吐く (edited)--static --disable-library-evolution を指定するのがめんどくさいので--static なら --disable-library-evolution は infer されて良いんじゃないかと思ったんだけど--static で--enable-library-evolutionは動かないんすか[Atomics#29] /Users/omochi/github/apple/swift-atomics/Sources/Atomics/autogenerated/Primitives.native.swift:22:8: error: no such module 'Builtin' import Builtin ^[NIOConcurrencyHelpers#28] /Users/omochi/github/apple/swift-nio/Sources/NIOConcurrencyHelpers/NIOLock.swift:154:5: error: deinitializer can only be '@inlinable' if the class is '@_fixed_layout' @inlinable ^~~~~~~~~~ /Users/omochi/github/apple/swift-nio/Sources/NIOConcurrencyHelpers/NIOLock.swift:195:14: error: 'let' property '_storage' may not be initialized directly; use "self.init(...)" or "self = ..." instead self._storage = .create(value: ()) ^ /Users/omochi/github/apple/swift-nio/Sources/NIOConcurrencyHelpers/NIOLock.swift:190:18: note: '_storage' declared here internal let _storage: LockStorage<Void> ^ /Users/omochi/github/apple/swift-nio/Sources/NIOConcurrencyHelpers/NIOLockedValueBox.swift:32:14: error: 'let' property '_storage' may not be initialized directly; use "self.init(...)" or "self = ..." instead self._storage = .create(value: value) ^@inlinableとか駆使してるライブラリがビルドできなくて扱いづらい
1@inlinableとか駆使してるライブラリがビルドできなくて扱いづらい @inlinable を駆使して高速なモードになってほしいとしたら? (edited)@inlinable を駆使して高速なモードになってほしいとしたら? (edited)NIOHTTP1 の中のちょっとした型とかがVapor の中でガチャガチャ操作されたりしている*.xcframework単体のポン置きをイメージしてしまったけどそれはそうか*.xcframework単体のポン置きをイメージしてしまったけどそれはそうか .binaryTarget 作ってねっていう配布方法も一応可能なのか。MODULEMAP_FILE_CONTENT というパラメータに文字列をいれてやる方法を使っているので、 (2)で持ってる自前のモジュールマップ生成結果を このパラメータに上書きしてやれば、統合できると思います。 生成先のパスも MODULEMAP_PATH かなんかで指定されているので変更できる。 問題があるケースというのもそれでうまく解決すると思う。 (edited)MODULEMAP_FILE_CONTENTS をなくして自動生成を抑止する-fmodule-map-file を渡さないようにするMODULEMAP_FILE に渡してFrameworkに含むようにする-Fで生成したフレームワーク内のモジュールを正としてあつかうようにする という変更を試してみたら、NIOSSLのビルドは維持出来たし動いてそうだMODULEMAP_FILE にわたすのではなくて、MODULEMAP_FILE_CONTENTS と MODULEMAP_PATH を使って、xcbuildに生成させたらどう?MODULEMAP_FILEとMODULEMAP_PATH一緒にしたらうまく動かないかなPackage(name:) ってなんの意味があるんだ??Package.name が表示されている.package(name:url:branch:) を使うと定義されてる名前のほうが使える、が、deprecatedだid というので指定できるらしい これもちょっと違う話だなPackage の name とリポジトリ名は意図して統一している感じですよね. (edited)SwiftSyntax から swift-syntax に変更している (edited)platforms 書かなかった場合は何でも OK だけど、 platforms: [.iOS(.v13)] みたいに書いたときは iOS 以外で使えなくなると思ってたんですよね。それが勘違いなら問題ないです。 #if !os(iOS) コンパイルエラー #endifplatforms にiOSだけ指定してるとmacOSのバージョンが適合できないと言われるし、かと言ってじゃあ platforms にmacOS追加したら今度は import UIKit で怒られるし、全部のファイルに #available iOS つけるのも大変だし… #if os(iOS) // コード #endifswift build とかしたい時が多々あって… swift build を素で打つと、暗黙にmac向けにビルドする話になっているのでswift build --platform とかほしいw--sdk とか --toolchain はあるけどplatforms: 指定があるのだから --platform iOS って書きたいですね。xcrun --sdk iphonesimulator --show-sdk-path" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"swift build で iOS 向けにビルドすることもできるようになりそうな気がしてます. 実際にそれを試してみた PoC リポジトリが以下にありますし. https://forums.swift.org/t/introducing-an-sdk-for-building-ios-macos-apps-on-linux-experimental/66233swift-foundation も一緒に進めてほしいなあ.framework の組み立てを自前でやるのはわかるけど、 PIF(xcbuild)の利用は続いてるみたいで、 PIFの加工は減ったけど無くなってはないみたいで、 結局元PIFの役割はどこまで残ってるのかが知りたい あと、元々それだとビルドできないから加工してたという認識だけど、 なぜ加工を減らしても大丈夫なの? (edited).framework の組み立てを自前でやるのはわかるけど、 PIF(xcbuild)の利用は続いてるみたいで、 PIFの加工は減ったけど無くなってはないみたいで、 結局元PIFの役割はどこまで残ってるのかが知りたい あと、元々それだとビルドできないから加工してたという認識だけど、 なぜ加工を減らしても大丈夫なの? (edited)\(ProcessInfo.processInfo.environment["PWD"]!)でできました。ありがとうございますPackage.swift を指定するオプションを使うとズレそうね#file は信用できそう 都度コンパイルされてるし.linkedLibraryを使ってるんですが、ここ-Lとして渡されるからLDサーチパス内の名前か絶対パスしか使えないんですよねswift build するときに-Xswiftc -L で渡す、かなぁ-lXで指定されたライブラリにlibX.soとlibX.aがあるとき普通のリンカは.soを優先するけど、-l:libX.a で指定するとライブラリのファイル名をフルで指定できる
1#filePath が一番マシかなぁ (edited)Missing required modules: Realm.Private, Realm, Realm.Swift というエラーが arm64-apple-ios.private.swiftinterfaceで出ているんですが、何が起こっているのか理解したいです。 Dynamic XCFrameworkというのが厄介な感じがしています。 @Kishikawa Katsumi 何かわかりますか?realm/realm-swift見に行ったらそれなりにコミットが活発だったxcodebuild -create-xcframework をするときに、以下のエラーが出るんですが、どうやって原因探っていったらいいですか? Message: "error: unable to determine the platform for the given binary '/var/folders/74/lws4xlls7fg_m4pkl499hp6h0000gn/T/XCFrameworkMaker_2B8CD624-6866-4376-BA29-58C144815E87/ios-device/MLKitBarcodeScanning.framework/MLKitBarcodeScanning'; check your deployment version settings" ビルド済みフレームワークでも成功するものと失敗するものがあって、原因を突き止めておきたいと思っています。 (xcframework-makerを使っていますが、失敗するのはxcodebuild -create-xcframeworkです。)MLKitBarcodeScanning.framework/MLKitBarcodeScanning のロードコマンドを otool -l でダンプして、LC_BUILD_VERSION が存在してるかチェックするのが良いかな?
3LC_VERSION_MIN_xxxというロードコマンドを使うっぽくて、もしかするとcreate-xcframework が古いやつを見ないのかもしれないなと。xcodebuild -create-xcframework -verbose -framework /var/folders/74/lws4xlls7fg_m4pkl499hp6h0000gn/T/XCFrameworkMaker_E10499DC-225D-4875-8D48-871BA5D66070/ios-device/MLKitBarcodeScanning.framework -framework /var/folders/74/lws4xlls7fg_m4pkl499hp6h0000gn/T /XCFrameworkMaker_E10499DC-225D-4875-8D48-871BA5D66070/ios-simulator/MLKitBarcodeScanning.framework -output GoogleMLKit/MLKitBarcodeScanning.xcframework error: invalid argument '-verbose'.Load command 1 cmd LC_VERSION_MIN_IPHONEOS cmdsize 16 version 11.0 sdk 16.2IPHONEOS_DEPLOYMENT_TARGET とかで指定してると無視されるようになったのでそれかもLoad command 2 cmd LC_VERSION_MIN_IPHONEOS cmdsize 16 version 10.0 sdk 10.0$ vtool -set-build-version 2 15 15 Pods/MLKitBarcodeScanning/Frameworks/MLKitBarcodeScanning.framework/MLKitBarcodeScanning -o Pods/MLKitBarcodeScanning/Frameworks/MLKitBarcodeScanning.framework/MLKitBarcodeScanningLC_BUILD_VERSION を設定できる-set-build-version <platform> <minos> <sdk> という意味になってて、platformの2はiphoneos、7がiphoneos-simulatorです (edited)-set-build-version <platform> <minos> <sdk> という意味になってて、platformの2はiphoneos、7がiphoneos-simulatorです (edited)static let が Concurrency unsafe な場合に警告が出るというケースは、そういえばこれまでもあったな (edited)swift package add-dependency <dependency> [--exact <version>] [--revision <revision>] [--branch <branch>] [--from <version>] [--up-to-next-minor-from <version>]OVERVIEW: Add a dependency to the package manifest USAGE: swift package add [--branch <branch>] [--from-version <from-version>] [--exact-version <exact-version>] [--revision <revision>] <url> ARGUMENTS: <url> The URL or directory of the package to add OPTIONS: --branch <branch> The branch to depend on --from-version <from-version> The minimum version requirement --exact-version <exact-version> The exact version requirement --revision <revision> A specific revision requirement --version Show the version. -h, -help, --help Show help information.add-dependency → add
--from → --from-vrersion だなswift package completion-toolがswift package completion-commandにしれっと変わっているのを知った。 https://github.com/apple/swift-package-manager/pull/7336# A function which filters options which starts with "-" from $argv. function _swift_swift_preprocessor set -l results# A function which filters options which starts with "-" from $argv. function _swift_swift_preprocessor set -l resultsNo such file or directory: '/Users/XXX/Library/Developer/Xcode/DerivedData/UIKitPlayground-drqizwqmrobvwngdzdetphhibhsl/Build/Products/Debug-iphonesimulator/PackageFrameworks/RxSwift-Dynamic.framework/RxSwift-Dynamic' サンプルプロジェクト: https://github.com/dazy1030/UIKitPlayground/tree/rxswift-dynamic$ git clone https://github.com/omochi/swift-deps-rebuild-bug $ cd swift-deps-rebuild-bug $ ./repro.bash ↑のステップを実行して、最後にリンクエラーが出れば再現成功+ pwd /home/katei/ghq/github.com/omochi/swift-deps-rebuild-bug + cd AppPackage + swift package clean + swift build Building for debugging... [30/30] Linking app Build complete! (3.71s) + cd .. + cd ToyboxPackage/Sources/ToyboxCore + sed 's/a: Int = 0/a: Int = 0, b: Int = 0/' Debug.swift + mv -f Debug.2.swift Debug.swift + cd ../../../AppPackage + swift build Building for debugging... error: link command failed with exit code 1 (use -v to see invocation) /home/katei/ghq/github.com/omochi/swift-deps-rebuild-bug/AppPackage/Sources/AppModule/App.swift:9: error: undefined reference to '$s10ToyboxCore8toyDebug1aySi_tF' clang: error: linker command failed with exit code 1 (use -v to see invocation) [14/16] Linking codegen$ swiftc --version Swift version 6.0-dev (LLVM 4e9ab6351de9f4d, Swift d1343dc55bac19f) Target: x86_64-unknown-linux-gnu[omochi@omochi-mbp swift-deps-rebuild-bug (main =)]$ ./repro.bash + pwd /Users/omochi/github/omochi/swift-deps-rebuild-bug + cd AppPackage + swift package clean + swift build Building for debugging... [24/24] Applying app Build complete! (0.95s) + cd .. + cd ToyboxPackage/Sources/ToyboxCore + sed 's/a: Int = 0/a: Int = 0, b: Int = 0/' Debug.swift + mv -f Debug.2.swift Debug.swift + cd ../../../AppPackage + swift build Building for debugging... error: link command failed with exit code 1 (use -v to see invocation) Undefined symbols for architecture arm64: "ToyboxCore.toyDebug(a: Swift.Int) -> ()", referenced from: AppModule.App.main() -> () in App.swift.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) error: fatalError [9/14] Linking app$ swift package clean しないといけなくて、その結果3000ファイル以上のリビルドが発生するのでツイッターが捗ってしまう.bashとつけてるところで変に感心してしまった。 $ ./repro.bash + pwd /Users/norio/ghq/github.com/omochi/swift-deps-rebuild-bug + swift package --package-path AppPackage clean + swift build --package-path AppPackage Building for debugging... [24/24] Applying codegen Build complete! (0.84s) + sed -i -e 's/a: Int = 0/a: Int = 0, b: Int = 0/' ToyboxPackage/Sources/ToyboxCore/Debug.swift + swift build --package-path AppPackage Building for debugging... error: link command failed with exit code 1 (use -v to see invocation) Undefined symbols for architecture arm64: "ToyboxCore.toyDebug(a: Swift.Int) -> ()", referenced from: AppModule.App.main() -> () in App.swift.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) error: fatalError [10/14] Linking codegen--package-path が出てるところがちょっと違うな?sed -i -e が mac と linux で互換にならないって話があって、mv使った2手で置換してるところがcdしたいな・・・(136点の回答) https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux (edited)Debug.step1|2.swift を見た) (edited)TARGET=ToyboxPackage/Sources/ToyboxCore/Debug.swift sed 's/a: Int = 0/a: Int = 0, b: Int = 0/' $TARGET | (sleep 1; tee $TARGET >/dev/null) (edited)--experimental-explicit-module-build で検出できる問題だな/home/katei/ghq/github.com/omochi/swift-deps-rebuild-bug/AppPackage/Sources/AppModule/App.swift:1:8: error: no such module 'ToyboxCore' 1 | import ToyboxCore | `- error: no such module 'ToyboxCore' 2 | 3 | public struct App {swift-collections とか import Collections することで import SortedCollections とか省略するようになってるけど@_exported だったりしませんか?#if !COLLECTIONS_SINGLE_MODULE @_exported import BitCollections @_exported import DequeModule @_exported import HashTreeCollections @_exported import HeapModule @_exported import OrderedCollections // Note: _RopeModule is very intentionally not reexported, as its contents // aren't part of this package's stable API surface (yet). #endif
Sources/Collections/Collections.swift@_exported 使わないと実用性が保てなさそうだimport C ってソースで書いてあるけど、それも無くなってしまう。 (edited)toyDebug 関数を呼び出してるからビルドしなおしが必要だけど { "swift": "AppModule" }, { "modulePath": "AppModule.swiftmodule", "sourceFiles": [ "/home/katei/ghq/github.com/omochi/swift-deps-rebuild-bug/AppPackage/Sources/AppModule/App.swift" ], "directDependencies": [ { "swiftPrebuiltExternal": "Swift" }, { "swiftPrebuiltExternal": "SwiftOnoneSupport" }, { "swiftPrebuiltExternal": "_Concurrency" }, { "clang": "_SwiftConcurrencyShims" }, { "swiftPrebuiltExternal": "_StringProcessing" }, { "swiftPrebuiltExternal": "ToyboxCore" } ], "details": { "swift": { "commandLine": [ ], "contextHash": "PAYFYPM8H050", "isFramework": false, "extraPcmArgs": [ "-Xcc", "-target", "-Xcc", "x86_64-unknown-linux-gnu", "-Xcc", "-fapinotes-swift-version=5" ] } } }, { "swift" : "AppModule" }, { "details" : { "swift" : { "extraPcmArgs" : [ "-Xcc", "-target", "-Xcc", "x86_64-unknown-linux-gnu", "-Xcc", "-fapinotes-swift-version=5" ], "isFramework" : false, "commandLine" : [ ], "contextHash" : "3BE0ZWLHZZ6AY" } }, "modulePath" : "AppModule.swiftmodule", "directDependencies" : [ { "swiftPrebuiltExternal" : "Swift" }, { "swiftPrebuiltExternal" : "SwiftOnoneSupport" }, { "swiftPrebuiltExternal" : "_Concurrency" }, { "clang" : "_SwiftConcurrencyShims" }, { "swiftPrebuiltExternal" : "_StringProcessing" } ], "sourceFiles" : [ "\/home\/katei\/ghq\/github.com\/omochi\/swift-deps-rebuild-bug\/AppPackage\/Sources\/AppModule\/App.swift" ] },.build/debug/Modules にToyboxCore.swiftmoduleが残ってるか否かで変わってるんだ--experimental-explicit-module-build で全然ビルドできないな@_exported 使っちゃだめですよswiftmodule ファイルを作るところが、レースコンディションになっているという話なのか
swiftLanguageVersions: [.v5, .version("6")]が書かれた外部パッケージはPackage.swiftのswift-tools-versionに関係なく-swift-version 6でビルドされることを確認した。 この挙動はバグってことで良いのかな。swiftLanguageVersionsにswift-tools-versionより大きいバージョンを設定できる意義ってのは何?swiftLanguageVersionsを優先してる。 // Figure out the swift version from declared list in the manifest. let declaredSwiftVersions = try declaredSwiftVersions() let computedSwiftVersion: SwiftLanguageVersion = if let declaredSwiftVersion = declaredSwiftVersions.first { declaredSwiftVersion } else { // Otherwise, use the version depending on the manifest version. self.manifest.toolsVersion.swiftLanguageVersion }swiftLanguageVersionsを参照する必要ない気がする。swiftLanguageVersionsにtools-versionより古いバージョンが書かれている場合を考えると、ここのキャップが ToolsVersion.current ではなく self.manifest.toolsVersion.swiftLanguageVersion になってるべき? https://github.com/swiftlang/swift-package-manager/blob/392a2a99510f391cb172ceef510d7aefce5c7c62/Sources/PackageLoading/PackageBuilder.swift#L1248swift-tools-version に基づいて実行するツールバーションが決まってるんじゃないんか。swift-tools-version:6でswiftLangaugeVersions: [.v5]の時に、-swift-version 5としたいかどうかによる? (edited)ToolsVersion.current ではなく self.manifest.toolsVersion.swiftLanguageVersion になってるべき? mainブランチでビルドとか通らなくて、色々めんどい// swift-tools-version:導入前からのコードぽい。 https://github.com/swiftlang/swift-package-manager/commit/c946f313e5ba5f96ebbed3e424befe45d41a2c8e#diff-68f661bfe880d4bf7059718964ee104add3839e7e2f5bc8bfd644ab706ff7149R812.v15 が書けるけど Linux 版だと書けない.macOS("15.0") でお茶を濁して (edited).macOS(.v15) にすると問題が起きることがわかった platforms: [ .macOS(.v15), ], にしなければ、OSアプデは問題ないすよ (edited)docker buildxの--progress=ttyみたいなものかな https://forums.swift.org/t/pitch-build-progress-display-control-for-swiftpm-plugins/78678docker buildxの--progress=ttyみたいなものかな https://forums.swift.org/t/pitch-build-progress-display-control-for-swiftpm-plugins/78678 --progress=plainが強制されていたので --progress=autoをオプトインできるようにする形です
1$ swift build や $ bin/build.sh じゃ足りないことあるん?swift package dump-packageの依存するパッケージの内容まで遡る版が欲しい...swift buildに-Xswiftc -emit-library -Xswiftc -staticって渡すと、パッケージに含まれるモジュールのスタティックリンクライブラリたちがカレントディレクトリに作られる。Package.swiftにtype: .staticで定義したlibraryをビルドしたものとは扱い方が違ってくる。Package.swiftのlibrary定義にtype: .static|.dynamicを書き足してビルドするのは、自動化しづらいのでなんとかしたい。type: .staticの方は.build/debug/description.jsonから対象モジュールにリンクするオブジェクト一覧を取り出すことはできる様になったので自動化できそう。lib/{swift,swift_static}/*に含まれるlib*.{a,dylib,so}と*.swiftmodule的なものを、パッケージから簡単に生成できるようにしたい。 (edited)--override-product-type的な?libFoundationEssentials.aの中身を見ると、依存パッケージは入ってなさそうだった。 (edited)_FoundationCollections.swiftmoduleってのがそうなのかな?_FoundationCollections module (including contents of the unstable _RopeModule) rather than separated modules like the SwiftPM build. - Due to Windows limitations, this _FoundationCollections module only contains the OrderedCollections and _RopeModule APIsPackage.swiftへ書いた時にコンフリクトしないためかな (edited)type: .static|dynamicで依存パッケージのオブジェクトも含んでる方が変?renamed 付きの deprecated にも適用してくれないかな
1