-- Exit Code: 134 Command Output (stderr): -- <snip> terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc pure virtual method called terminate called recursively /home/buildnode/disk2/workspace/oss-swift-incremental-RA-linux-ubuntu-14_04/buildbot_incremental/swift-linux-x86_64/test-linux-x86_64/SourceKit/ExtractComment/Output/extract_comments.swift.script: line 19: 6097 Aborted (core dumped) /home/buildnode/disk2/workspace/oss-swift-incremental-RA-linux-ubuntu-14_04/buildbot_incremental/swift-linux-x86_64/bin/sourcekitd-test -req=extract-comment -pass-as-sourcetext /home/buildnode/disk2/workspace/oss-swift-incremental-RA-linux-ubuntu-14_04/swift/test/SourceKit/ExtractComment/Inputs/DocCommentEmptyLine1.swift > /home/buildnode/disk2/workspace/oss-swift-incremental-RA-linux-ubuntu-14_04/buildbot_incremental/swift-linux-x86_64/test-linux-x86_64/SourceKit/ExtractComment/Output/extract_comments.swift.tmp.DocCommentEmptyLine1.response# test/SourceKit ディレクトリ内だけ全部 $ utils/run-test --build-dir ../build/Ninja-DebugAssert/ test/SourceKit/ # 特定のテストケースだけ $ utils/run-test --build-dir ../build/Ninja-DebugAssert/ test/SourceKit/ExtractComment/extract_comments.swift # verbose出力 $ utils/run-test -v --build-dir ../build/Ninja-DebugAssert/ test/SourceKit/ExtractComment/extract_comments.swift verbose 出力で実際の実行コマンド群が見えるのでそれをデバッガで見ていく感じです。$ utils/build-script -R --debug-swift でビルドしてます。その場合は build-dir は ../build/Ninja-ReleaseAssert+swift-DebugAssert ですね。FAIL: Swift(linux-x86_64) :: SourceKit/CursorInfo/cursor_no_cancel.swift (443 of 9803) ******************** TEST 'Swift(linux-x86_64) :: SourceKit/CursorInfo/cursor_no_cancel.swift' FAILED ******************** Script: -- <省略> -- Exit Code: 1 Command Output (stderr): -- /home/rintaro/Documents/swift-oss/swift/test/SourceKit/CursorInfo/cursor_no_cancel.swift:39:11: error: expected string not found in input // RANGE: source.lang.swift.range.singleexpression ^ <stdin>:1:1: note: scanning from here #0 0x00007f124b02b0e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (BUILD_DIR/lib/libsourcekitdInProc.so+0x9850e8) ^ <stdin>:6:21: note: possible intended match here #5 0x00007f124b07024a SourceKit::SwiftLangSupport::~SwiftLangSupport() (BUILD_DIR/lib/libsourcekitdInProc.so+0x9ca24a) ^ -- ********************swift-DEVELOPMENT-SNAPSHOT-2017-05-09-a のLinux版に libsourcekitdInProc.so がもれなく入っていることを確認。NSDictionary の比較がLinuxで正しく動いていないことを知って、ガッカリ JSONSerializationによるJSON文字列作成結果がnondeterministicだったため、オブジェクト化して比較したのがあだになった。Foundation.TimeZone が /usr/share/zoneinfo の存在に依存していて、ubuntu だとデフォルトで存在しない場合があるからだった。 https://bugs.swift.org/browse/SR-4921NSArray に Hashable でない _ObjectBridgeable な要素が入ってる時の比較がおかしかった。
swift-DEVELOPMENT-SNAPSHOT-2016-08-18-aかららしい… (edited)swift/stdlib/public/SDK/(Dispatch|Foundation)/NS*辺りはLinuxで使えない。 (edited)DispatchやFoundationを実現するのがswift-corelibs-*。DispatchやFoundationのAPIは、swift本体でテスト実行されるからまだいい。 (edited)swift本体では使われていないObjective-Cを真似た機能を使おうとすると、それがテストされていないからmacOSの挙動と異なってたりする。 (edited)swift-corelibs-*プロジェクトにはフルタイムで見てるAppleの開発者がいないらしくて、その辺り見過ごされて実装されていってしまってるぽい。initでクラスのselfを置き換える手法を使うことで、swift-corelibs-foundationのNSNumberをCFNumberCreate()で作成する様に変更するPRを書いた。 https://github.com/apple/swift-corelibs-foundation/pull/1093 (edited)convenience init だから その先の self.init で alloc すればいいはず。poとか使おうとすると (lldb) po empty warning: Swift error in module YamsPackageTests.xctest. Debug info from this module will be unavailable in the debugger. error: in auto-import: failed to get module 'YamsTests' from AST context みたいなエラーが出て使えなかったのだけど、 https://bugs.swift.org/browse/SR-5524?focusedCommentId=27038&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-27038 に書かれてるC_INCLUDE_PATHとCPLUS_INCLUDE_PATHを設定したら、使える様になった。() -> NSNumber なクロージャを渡している。init(factory:) に渡しているクロージャの式が、 () -> Animal であるゆえに、 コンパイルエラーとなる。 ここは、 self の式の型は Animal ではなく Self なので、 () -> Self 型のクロージャを渡さねばならないからだ。fileprivate let decimal: Decimal ということは、現状でも convenience init 経由の NSDecimalNumber のコンストラクトで、 メモリがぶっ壊れる可能性がある・・・?func castCFNumber<T>() -> T { return unsafeBitCast(cfnumber, to: T.self) } slavaはこれを試してみるとこのこと。 NSDecimalNumber(value: true)このような「バグでコンパイルできてしまう」パターンは、 既存の NSNumber 実装が踏み抜いている。 https://github.com/apple/swift-corelibs-foundation/blob/87466c45462cba5a085d5cd41d785d681016542d/Foundation/NSNumber.swift#L266 僕のcommitですね I have a whole branch that refractors almost ALL of the classes that follow the self replacement pattern. (edited)NSDecimalNumber の decimal プロパティが初期化されない可能性は解決しないのでは・・・???
NSDecimalNumber は super.init() しか使ってないから問題ないと思う。 open override func description(withLocale locale: Locale?) -> String { guard locale == nil else { fatalError("Locale not supported: \(locale!)") } return self.decimal.description }public convenience init(value: Bool) は、 NSDecimalNumber に対しても呼び出せると思う。
$ docker run --privileged -it --rm norionomura/swift:4020170827a swift -I /usr/lib/swift/clang/include Welcome to Swift version 4.0-dev (LLVM 2dedb62a0b, Clang b9d76a314c, Swift 0899bd328a). Type :help for assistance. 1> import Foundation 2> let b = NSDecimalNumber(value: true) error: repl.swift:2:9: error: argument labels '(value:)' do not match any available overloads let b = NSDecimalNumber(value: true) ^ ~~~~~~~~~~~~~ repl.swift:2:9: note: overloads for 'NSDecimalNumber' exist with these partially matching parameter lists: (decimal: Decimal), (string: String?), (coder: NSCoder), (floatLiteral: Double), (booleanLiteral: Bool), (integerLiteral: Int) let b = NSDecimalNumber(value: true) ^ 3> (edited)class Animal { init() { } convenience init(init0 int: Int) { self.init() } } class Cat : Animal { override init() { } convenience init(init1 int: Int) { self.init() } } // Animal の convenience init が呼び出せる Cat.init(init0: 3)swift -I /usr/lib/swift/clang/include で。publicだからかな?[omochi@omochi-iMac temp]$ docker run --privileged -it --rm norionomura/swift:4020170827a swift -I /usr/lib/swift/clang/include Welcome to Swift version 4.0-dev (LLVM 2dedb62a0b, Clang b9d76a314c, Swift 0899bd328a). Type :help for assistance. 1> public class Animal 2. { 3. public init() {} 4. public convenience init(init0 int: Int) { self.init() } 5. } 6> public class Cat : Animal { 7. public override init() {} 8. } 9> Cat.init(init0: 33) $R0: Cat = { __lldb_expr_1.Animal = {} }Open access applies only to classes and class members, and it differs from public access as follows: - Classes with public access, or any more restrictive access level, can be subclassed only within the module where they’re defined. - Class members with public access, or any more restrictive access level, can be overridden by subclasses only within the module where they’re defined. - Open classes can be subclassed within the module where they’re defined, and within any module that imports the module where they’re defined. - Open class members can be overridden by subclasses within the module where they’re defined, and within any module that imports the module where they’re defined. (edited)### public Apply this modifier to a declaration to indicate the declaration can be accessed and subclassed by code in the same module as the declaration. Declarations marked with the public access-level modifier can also be accessed (but not subclassed) by code in a module that imports the module that contains that declaration. (edited)open class NSValue2 {} protocol Factory {} extension Factory { init(factory: () -> Self) { self = factory() } } extension NSValue2: Factory {} open class NSNumber2: NSValue2 { private override init() {} private convenience init(private: Int) { self.init(factory: { NSNumber2() }) } public convenience init(init0: Int) { self.init(private: init0) } } open class NSDecimalNumber2: NSNumber2 {} これでモジュール外の NSDecimalNumber2(init0:0) がビルドエラー error: 'NSDecimalNumber2' cannot be constructed because it has no accessible initializers になる。import Foundation internal protocol _Factory { init(factory: () -> Self) } extension _Factory { init(factory: () -> Self) { self = factory() } } open class NSValue2: _Factory { internal init() {} } open class NSNumber2: NSValue2 { internal override init() { super.init() } public convenience init(value: Bool) { self.init(factory: { NSNumber2() }) } } open class NSDecimalNumber2: NSNumber2 { // override init() { super.init() } // この行を復元するとビルドが通る。 public init(decimal dcm: Decimal) { super.init() } } これでモジュール外の NSDecimalNumber2(value: true) がビルドエラー error: incorrect argument label in call (have 'value:', expected 'decimal:') になる。 (edited)NSDecimalNumber2にoverride init() { super.init() }を足すと通る様になる。Rule 1 If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers. Rule 2 If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.open class NSNumber2 { public init() { } public convenience init(value: Bool) { self.init() } } open class NSDecimalNumber2: NSNumber2 { // A // public override init() {} // B public init(decimal dcm: Decimal) { super.init() } }swift-4.1-DEVELOPMENT-SNAPSHOT-2017-10-25-a を試したら、REPL起動時に-I/usr/lib/swift/clang/includeを渡さなくてもimport Foundationでエラーにならなくなってた func testNSStringPath1() throws { let actual = NSString(string: "").appendingPathComponent("*.txt") let expected = "*.txt" XCTAssertEqual(actual, expected) }/*.txt になってしまう。TestResources └── globstar ├── a │ ├── b │ │ ├── c │ │ │ ├── d0.txt │ │ │ └── d1.md │ │ ├── c0.txt │ │ └── c1.md │ ├── b0.txt │ └── b1.md ├── a0.txt └── a1.md
substSubpathStrs = try fm.subpathsOfDirectory(atPath: path) dump(substSubpathStrs)Test Case 'GlobTest.testExpandGlobStar1' started at 2017-11-11 07:57:51.502 ▿ 3 elements - "a" - "a0.txt" - "a1.md"$ swift --version が同じならこの手の挙動は同じですよね?[subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] enter [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryName=. [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryName=.. [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryName=a [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryType=0 (DT_DIR=4) [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryName=a0.txt [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryType=0 (DT_DIR=4) [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryName=a1.md [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] entryType=0 (DT_DIR=4) [subpathsOfDirectoryCompat(/home/travis/build/omochi/gysb/TestResources/globstar)] exit if tempEntryType == Int32(DT_DIR) { let subPath: String = path + "/" + entryName let entries = try subpathsOfDirectory(atPath: subPath) contents.append(contentsOf: entries.map({file in "\(entryName)/\(file)"})) }How do I contribute? We welcome contributions to Foundation! Please see the known issues page if you are looking for an area where we need help. We are also standing by on the mailing lists to answer questions about what is most important to do and what we will accept into the project.enumerator(atPath:)とかはどうだろうlibblocksruntime0 が入ってない。swift(>=) による検査は演算子が使えません。#if swift(>=4.0) #elseif swift(>=3.2) #else #endif みたいにするしかないと思います。#else ブロック以外は Swift3.0 ではパースされないので、その中であれば swift(>=4.0.2) など使えると思います。self.token = self.notificationCenter.addObserver(forName:object:queue:using:)(nil, nil, nil) { ... } っていう手もあり。#if swift(>=4.0) #if swift(>=4.0.2) #else extension NotificationCenter { func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol { ... } } #endif #endif みたいにメソッド生やすともうちょっとマシにできそうな気がしてきましたw (edited)import Dispatch func fib(_ i: Int) -> Int { switch i { case 0, 1: return 1 default: return fib(i-1) + fib(i-2) } } DispatchQueue.concurrentPerform(iterations: 30) { i in fib(i) } これ実行したら確率的に死んでしまう…… swift-DEVELOPMENT-SNAPSHOT-2018-01-29-a-ubuntu16.04にてDispatch のバグかもしれないけどimport Foundation import Dispatch for i in 0..<30 { DispatchQueue.global().async { print(i) sleep(1) _ = i } } sleep(10) (edited)printは一個も出ずに死にますね。さらにsleepを入れることで死亡率100%にDispatchQueueを個別に生成した場合死なないのでconcurrent queueの問題みたいですdocker run --privileged -it --rm norionomura/swift:swift-4.1-branch swift -I/usr/lib/swift/clang/includenorionomura/swift:swift-4.1-branchが最新のスナップショット。/usr/libに置かれたライブラリ、swiftcだとリンクされるけど、REPLだとerror: Couldn't lookup symbols:になってしまう。swift -I/usr/lib/swift/clang/include -L /usr/libで起動したREPLだとエラーにならないので、REPLはldとは違う仕組みでライブラリを検索するぽい?:type lookupだと型の情報が出るのに、使おうとするとunresolved identifierになる $ docker run --privileged -it --rm norionomura/swift:40 swift -I/usr/lib/swift/clang/include Welcome to Swift version 4.0 (swift-4.0-RELEASE). Type :help for assistance. 1> import Foundation 2> :type lookup DBL_DECIMAL_DIG var DBL_DECIMAL_DIG: Swift.Int32 { get {} } 2> print(DBL_DECIMAL_DIG) error: repl.swift:2:7: error: use of unresolved identifier 'DBL_DECIMAL_DIG' print(DBL_DECIMAL_DIG) ^~~~~~~~~~~~~~~ (edited)llvm-symbolizerにもオプションが増えてるなあ。 (edited)libunwind.Thread.callStackSymbols)とほぼ同じ出力が得られます。SwiftCompilerDiscordappBotのクラッシュ原因を突き止めたい…State changed from up to crashedってのが時々出てくるのですが、何がトリガーなのかさっぱりわかっていないのです。ProcessのstandardInputにパイプのFileHandleを渡してパイプへデータを書き込んでも、Linuxだと起動したプロセスが標準入力を読んでくれない現象に悩んでたのだけど、launch()の前にパイプへデータを書き込んでおく事で読んでくれる様になった。launch()後にパイプへ書き込んでも問題ない。 (edited)Process.waitUntilExit()がスレッドセーフではないため、Process.terminationStatusがおかしくなる。 @swift-4.2.4
import Foundation let process = Process() process.launchPath = "/bin/false" let group = DispatchGroup(), queue = DispatchQueue.global() process.launch() queue.async(group: group) { process.waitUntilExit() } group.wait() print("terminationStatus should be 1, actual: \(process.terminationStatus)") (edited)import Foundation let process = Process() process.launchPath = "/bin/false" let semaphore = DispatchSemaphore(value: 0) process.terminationHandler = { _ in semaphore.signal() } let queue = DispatchQueue.global() process.launch() queue.async { process.waitUntilExit() } print("terminationStatus should be 1, actual: \(process.terminationStatus)") semaphore.wait() print("terminationStatus should be 1, actual: \(process.terminationStatus)") (edited)terminationStatus should be 1, actual: 0 terminationStatus should be 1, actual: 1 (edited)terminationHandlerを使った方が良さそう。 https://github.com/apple/swift-corelibs-foundation/blob/swift-4.2-branch/Foundation/Process.swift#L341waitUntilExit()でも問題ないしその場合のオーバーヘッドもwaitUntilExit()の方が少ないかな。swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-06-aを使ったubuntu 16.04のdockerイメージ作成が失敗する様になった。 Step 7/7 : RUN swift --version ---> Running in bb3dce9f40cc swift: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by swift) (edited)GLIBCXX_3.4.22を含むlibstdc++.so.6はubuntu 16.04のパッケージとしては未リリースぽい。swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-07-aで直ってた。 /// - Note: this differs from the Darwin implementation in that the keys must be Strings open var threadDictionary = [String : Any]() (edited)Thread.current.threadDictionary を Thread Local Storage として使おうとしたときにObjectIdentifier の debugDescription をキーにするとか?"ObjectIdentifier(3001238)" みたいな?NSMutableDictionary だと何がまずいんだろう?Dictionary じゃなければいけない理由が本当にあるなら、 [AnyHashable: Any] ではだめなのかとか聞いてみると良いと思います。 (edited)[954/1340] Linking CXX executable bin/clang-check ... clang: error: unable to execute command: Killed clang: error: linker command failed due to signal (use -v to see invocation)cmake -G Ninja ../../../swift-corelibs-foundation \ -DCMAKE_C_COMPILER=../../llvm-linux-x86_64/bin/clang \ -DCMAKE_SWIFT_COMPILER=../../swift-linux-x86_64/bin/swiftc \ -DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=../../../swift-corelibs-libdispatch \ -DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=../../libdispatch-linux-x86_64[250/3012] Building CXX object+ /usr/bin/cmake --build /home/katsumi/work/swift-source/build/Ninja-DebugAssert/llvm-linux-x86_64 -- -j1 all [59/1905] Building CXX object lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86ISelLowering.cpp.o FAILED: /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Target/X86 -I/home/katsumi/work/swift-source/llvm/lib/Target/X86 -I/usr/include/libxml2 -Iinclude -I/home/katsumi/work/swift-source/llvm/include -Wno-unknown-warning-option -Werror=unguarded-availability-new -g -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wno-class-memaccess -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -g -fno-exceptions -fno-rtti -MMD -MT lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86ISelLowering.cpp.o -MF lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86ISelLowering.cpp.o.d -o lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86ISelLowering.cpp.o -c /home/katsumi/work/swift-source/llvm/lib/Target/X86/X86ISelLowering.cpp clang: error: unable to execute command: Killed clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang: note: diagnostic msg: ********************PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/X86ISelLowering-5d18e1.cpp clang: note: diagnostic msg: /tmp/X86ISelLowering-5d18e1.sh clang: note: diagnostic msg: ******************** ninja: build stopped: subcommand failed. utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting 2つのマシンで試してたけど片方は全然手前で死んだ。swift build -c releaseだとswift-nightlyボットのCIも通るみたい。[1071/2408] Linking CXX shared library lib/libLTO.so.7svn FAILED: : && /usr/bin/clang++ -fPIC -Wno-unknown-warning-option ^ 昨日ビルドしてた2つのマシンがリンクフェーズの同じところで死んでました。[31/78] Linking CXX shared library src/libdispatch.so ここでコケるようになった でも、例の謎の Killed じゃなくて /usr/bin/ld.gold: error: cannot find -lswiftSwiftOnoneSupportdocker-machine upgradeしたらハマったので共有。 https://twitter.com/norio_nomura/status/1063237666903273474docker-machine upgradeしたらdocker-machineが壊れた。boot2dockerをv18.06.1-ceにして復旧。 -- 18.09.0 iso breaks swarm ingress · Issue #4608 · docker/machine https://t.co/EwqzwMziDimissing required module 'SwiftShims' でコケた・・cached を設定すると良いらしいので、やってみるcachedはメモリ消費が多すぎて、使うのを止めました。docker-machine使う構成です。docker-machineを使った構成のメモ https://github.com/norio-nomura/swift-dev/blob/sourcekit-linux/docker-machine-on-mac.mdcachedで問題なくなるけど、大規模だとまだダメという認識です。cachedだとキャッシュメモリがバカみたいに消費されたと記憶。docker-machineを使わずにnfs使う方法。 https://qiita.com/kunit/items/36d9e5fa710ad26f8010 (edited)dockerにオプション指定ではなくdocker-composeを使う事が多いなら、こちらが良いのかも。$ docker volume create --driver local --opt type=nfs --opt o=addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3,acregmin=1,acdirmin=1 --opt device=:/Users Users $ docker run --privileged -it -v Users:/Users -w `pwd` --rm norionomura/swift:421 bash -c "time dd if=/dev/zero of=test bs=1k count=100000" 100000+0 records in 100000+0 records out 102400000 bytes (102 MB, 98 MiB) copied, 4.34849 s, 23.5 MB/s real 0m4.365s user 0m0.020s sys 0m0.220sdocker-machine VMware Fusion + NFS $ docker run --privileged -it -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:421 bash -c "time dd if=/dev/zero of=test bs=1k count=100000" 100000+0 records in 100000+0 records out 102400000 bytes (102 MB, 98 MiB) copied, 1.43024 s, 71.6 MB/s real 0m1.455s user 0m0.030s sys 0m0.180s$ docker run --privileged -it -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:421 bash -c "time dd if=/dev/zero of=test bs=1k count=100000" 100000+0 records in 100000+0 records out 102400000 bytes (102 MB, 98 MiB) copied, 45.2698 s, 2.3 MB/s real 0m45.259s user 0m0.370s sys 0m4.710sdocker-machineと同等の場合もある。cachedは使ってもあまり変わらなかった。ddでの書き込みですからね。読み込みはcachedの効果が出そうです。import Foundation class Cat {} let a: Cat = Cat() let array = NSMutableArray() array.add(a as Any)Could not cast value of type 'main.Cat' (0x7f180f3b0040) to 'Foundation.NSObject' (0x7f1801800a20). #0 0x000000000410ac94 PrintStackTraceSignalHandler(void*) (/usr/bin/swift+0x410ac94) #1 0x0000000004108b22 llvm::sys::RunSignalHandlers() (/usr/bin/swift+0x4108b22) #2 0x000000000410ae42 SignalHandler(int) (/usr/bin/swift+0x410ae42) #3 0x00007f180ef80390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #4 0x00007f180d6bf428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428) #5 0x00007f180d6c102a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a) #6 0x00007f18095ec742 (/usr/lib/swift/linux/libswiftCore.so+0x3c7742) #7 0x00007f18095e6b62 (/usr/lib/swift/linux/libswiftCore.so+0x3c1b62) #8 0x00007f18095e6bbb (/usr/lib/swift/linux/libswiftCore.so+0x3c1bbb) #9 0x00007f18095e7e43 swift_dynamicCastClassUnconditional (/usr/lib/swift/linux/libswiftCore.so+0x3c2e43) #10 0x00007f18016a4b52 $S10Foundation11_SwiftValueC5storeyAA8NSObjectCypFZTf4nd_n (/usr/lib/swift/linux/libFoundation.so+0x6ebb52) #11 0x00007f18016a42d9 $S10Foundation11_SwiftValueC5storeyAA8NSObjectCypFZ (/usr/lib/swift/linux/libFoundation.so+0x6eb2d9) #12 0x00007f1801342eb2 $S10Foundation14NSMutableArrayC6insert_2atyyp_SitF (/usr/lib/swift/linux/libFoundation.so+0x389eb2) #13 0x00007f1801342e3e $S10Foundation14NSMutableArrayC3addyyypF (/usr/lib/swift/linux/libFoundation.so+0x389e3e) #14 0x00007f180f3af102 #15 0x0000000001043efe llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) (/usr/bin/swift+0x1043efe) #16 0x0000000001048022 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) (/usr/bin/swift+0x1048022) #17 0x00000000004f8b42 swift::RunImmediately(swift::CompilerInstance&, std::vector<std::__cxx11::basic_string<char, std:Date, DateComponentsのnanosecond周りがSwift 5.0で直ったぽい。 @swift-4.2.4 @swift-5.0.3
import Foundation let now = Date() let comp = Calendar(identifier: .gregorian).dateComponents(in: .current, from: now) let recreatedDate = Calendar(identifier: .gregorian).date(from: comp) print(now.timeIntervalSinceReferenceDate == recreatedDate?.timeIntervalSinceReferenceDate)swift-4.2.x-RELEASEを毎月出すらしい。 https://forums.swift.org/t/announcing-swift-4-2-2-and-monthly-swift-4-2-x-dot-releases-for-linux/20148norionomura/swift 、5.0を機にubuntu16.04からubuntu18.04へ切り替えてたのだけど、Discordのボットをubuntu18.04にするとProcessで起動したswiftプロセスが終了せずにタイムアウトしてしまう不具合に遭遇。--enable-test-discoveryを試せるtoolchainのDockerイメージを作りました。 https://forums.swift.org/t/test-discovery-on-linux/26203/5.build/x86_64-unknown-linux/debug/testlist.derived/ にLinuxMain.swiftとXCTestManifests.swift相当を生成してそれを実行してる。 $ rm Tests/LinuxMain.swift remove Tests/LinuxMain.swift? y $ _docker_swift_run norionomura/swift:pr-25685 swift test --enable-test-discovery --parallel [117/117] Testing YamsTests.YamlErrorTests/testYamlErrorScanner $ tree .build/x86_64-unknown-linux/debug/testlist.derived/ .build/x86_64-unknown-linux/debug/testlist.derived/ ├── YamsTests.swift └── main.swift 0 directories, 2 files (edited)swift test --generate-linuxmainの生成物をリポジトリへ含めるのが不要になる。 (edited)LinuxMain.swiftがなかったら勝手に--enable-test-discoveryする、とかそんな挙動になるのかな。SourceKitではなくIndexStoreなのか? https://github.com/apple/swift-package-manager/pull/2174--enable-test-discoveryくらいしか利用法が思いつかないな。FoundationNetworkingに続き、FoundationXMLも分離するらしい。 https://github.com/apple/swift-corelibs-foundation/pull/2432Foundation は、全部入りを指すんですよね?FoundationはNetworkingとXMLが取り除かれたパッケージになる。全部入りパッケージは無い(と思う)。import Foundation したときに入るものが異なってしまいますよね。#if canImport(FoundationXML)とかが libcurlやlibxml2をインストールしなくても実行時エラーにならなくなる。 (edited)libunwind. - norio-nomura/SwiftBacktraceswift-DEVELOPMENT-SNAPSHOT-2019-09-24-a以降で発生してる事を確認した。 https://bugs.swift.org/browse/SR-11570Swift.swiftmoduleを生成するところから進まなくて、VMのメモリを3GBまで増やしたらようやく進む様になった。以前は1GBで問題なかったのに…import Foundation private final class _Thread: Thread { private let block: () -> Void init(block: @escaping () -> Void) { self.block = block } override func main() { block() } }<stdin>:8:5: error: 'super.init' isn't called on all paths before returning from initializer } ^Foundation.Thread の定義がずれてるってことですか?swift-DEVELOPMENT-SNAPSHOT-2020-08-18-aからNG (edited)swift-DEVELOPMENT-SNAPSHOT-2020-08-18-a版のswift-corelibs-foundationに入った変更で関係しそうなものは無さそうなので、コンパイラの挙動が変わったのだと思う。 https://github.com/apple/swift-corelibs-foundation/compare/swift-DEVELOPMENT-SNAPSHOT-2020-08-11-a...swift-DEVELOPMENT-SNAPSHOT-2020-08-18-a (edited)swift-5.3.1-RELEASEからLinux版のSwiftPMに渡された--static-swift-stdlibもswiftcへ-static-stdlibを渡す様になったけど、FoundationNetworking, FoundationXMLを使ってると-static-stdlib 渡ってなかったのか。swift-5.3-RELEASEでも同一条件で-Xswiftc -static-stdlibを使うとlib/swift_static のswiftmoduleの配置が変わった影響ですね-static-stdlibがLinuxでも動く様になったと報告されてる詳細に、FoundationNetworking, FoundationXML利用有無とか書かれてない。-static-stdlibを使うと外部依存するライブラリが変わるのか。--static-swift-stdlib付け外し後はswift package cleanではダメで、swift package resetが必要ぽいのも、混乱の要因かも…norionomura/swift:5.3.1で apt-get update && apt-get install -y libxml2-dev した後 swift package reset; swift build -Xswiftc -static-stdlib はリンク出来るが swift package reset; swift build --static-swift-stdlib はダメという事までわかった… (edited)import FoundationNetworking import Foundation print(try! String(contentsOf: URL(string: "https://example.com")!)) 僕の環境だとこれを swiftc main.swift -static-stdlib でコンパイルするとCoreFoundationのシンボルが足りないと怒られます。norionomura/swift:5.3.1を使ってます。Dockerfileからswift-5.3.1-RELEASE相当をビルドしようとしてるけど、途中でdocker buildが止まる…norionomura/swift:531 で試してみます--static-swift-stdlib の場合、オブジェクトファイルを作るときにはSwiftPMは-static-stdlibを渡さないので /usr/lib/swift/CoreFoundation/module.map を見て、autolinkのエントリを追加しないからリンク時に-lCoreFoundation が付かないんだ! (edited)apt-get update && apt-get install -y libxml2-dev swift build -Xswiftc -static-stdlib でリンク出来ることを確認しました。# ldd `swift build --show-bin-path`/sourcekitten linux-vdso.so.1 => (0x00007fffa45cd000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f50112a8000) libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f50110a5000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5010ea1000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5010b98000) libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f50107dd000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f501045b000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5010245000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f500fe7b000) /lib64/ld-linux-x86-64.so.2 (0x00007f50140a1000) libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f500fae7000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f500f8cd000) liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f500f6ab000) libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f500dbf4000).soがリンクされてる気がするんだけど、実際にシンボルを参照していなければ、.soが無くても動いたりするのだろうか?libicudata と libicuuc が.soでリンクされてるのがおかしい気がしますねlibxml2.soがlibicu*を使ってますね。apt-get update && apt-get install -y libxml2するだけで実行可能になりました。 (edited)sourcekitdが無いと動かないのですが。echo 'import Foundation'|swiftc -static-executable -はまた違ったリンクエラーになるのね。/usr/lib/swift_static/linux/libswiftImageInspectionShared.a(ImageInspectionELF.cpp.o):ImageInspectionELF.cpp:function swift::initializeProtocolLookup(): error: undefined reference to 'swift::addImageProtocolsBlockCallbackUnsafe(void const*, unsigned long)' ...libxml2しかインストールされていないので、libxml2-devへ変更した方が良いかなと。release/5.3 ベースにしてやり直してますSWXMLHash がビルドできなかったですswift-DEVELOPMENT-SNAPSHOT-2020-11-09-aでビルドできました。 (edited).so, .a 両方が入ってる場合に .aを優先する方法ってないのだろうか。-static を付けたら.aを優先してくれないですか? lldはそういう挙動だったと思います-staticは他のオプションの関係で使えないみたい。 # swift build -Xswiftc -static-stdlib -Xlinker -static /usr/bin/ld.gold: fatal error: -pie and -static are incompatible clang-10: error: linker command failed with exit code 1 (use -v to see invocation) <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation) [0/1] Linking sourcekitten.soを探さないという極端な挙動のオプションはあるけど、両方存在する場合に.aを優先する的なのは見当たらない… # ld.gold --help Usage: ld.gold [options] file... Options: … -Bstatic -l does not search for shared libraries (edited)swift-DEVELOPMENT-SNAPSHOT-2020-11-13-aで試そうと思ったら、まだPRの変更が含まれてなかった。swift-DEVELOPMENT-SNAPSHOT-2020-11-16-aで確認しました。 docker run -v$PWD:$PWD -w$PWD norionomura/swift:nightly sh -c 'apt-get update && apt-get install -y libxml2-dev && swift build -c release --static-swift-stdlib'で無事にsourcekittenをビルドできました。swiftlang/swift:nightlyはまだ更新されてないのでnorionomura/swift:nightlyで。$ docker-swift-run find /usr -name "*XCTest*" /usr/lib/swift_static/shims/XCTestOverlayShims.h /usr/lib/swift/shims/XCTestOverlayShims.h /usr/lib/swift/linux/libXCTest.so /usr/lib/swift/linux/x86_64/XCTest.swiftdoc /usr/lib/swift/linux/x86_64/XCTest.swiftmoduleswift/utils/build-script-implにlibXCTest.aをビルドする仕組みが入ってないぽい。foundation_staticを見ると、productとしてxctest_staticを用意していく作法ぽい。 https://github.com/apple/swift/blob/main/utils/build-script-impl#L2301swift-5.4-RELEASEでSwiftLintにswift build --configuration release -Xswiftc -static-stdlibするとundefined referenceでリンクエラーになる。 https://github.com/norio-nomura/docker-swiftlint/pull/18/checks?check_run_id=2445741371-Xlinker -lCoreFoundation で治ると思います。-Xlinker -lCoreFoundationでは治らないようです。 https://github.com/norio-nomura/docker-swiftlint/pull/18/checks?check_run_id=2446742238-Xlinker -lCFURLSessionInterface -Xlinker -lcurlで治りました。CIでも試し中。import FoundationNetworking _ = URLSession.shared (edited)Data(buffer: ByteBuffer) が NIOFoundationCompat モジュールに定義されていて、Linuxだとこれをimportしないと使えないんだけどutils/build-script --release-debuginfo --test --skip-early-swift-driver でビルドしてテスト実行まで含めてピッタリ2時間半ってところ。ARM CPUの4コアと24 GBメモリのマシン。swift:5.5.2-focal で、最適化バグで、実行ファイルが該当箇所でコアダンプ吐いてクラッシュする症状に出会いました。 しかも、その箇所 + 5.5.2 の組み合わせは過去に動いていて、 新規に追加した別のコードが、間接的に?なんらかの影響をその箇所に与えていたようです。 printを追加すると症状が消えたりしたので、 @_optmize(none) を付けて解決しました。 みなさんも気をつけて・・・DEVELOPMENT-SNAPSHOTはインストール先のディレクトリ名を見ればいつのものかわかるけど、Docker版はswift -versionに含まれるハッシュを元にリポジトリを検索しないとわからない。そのためにSwiftボットはGitHubのGraphQL APIを使ってタグを取得してたのだけど、その仕組みをGitHub CLI extensionとして独立させた。 https://github.com/norio-nomura/gh-query-tags (edited)swift:focalだと動くのにswift:bionicだとswiftlint versionすら動かない。 $ docker run -it --rm -v $(pwd):$(pwd) -w$(pwd) swiftlint:bionic swiftlint version free(): invalid pointerswift:latestはbionicなんだけど、focalを使った方が良いのかな。FileManager.DirectoryEnumerationOptions.producesRelativePathURLs という欲しかったものがあることに気がついて使ったが、Linuxに実装されてなかった。。
1--platform=linux/amd64を付けて実行した時に/proc/self/cmdlineの内容がバグってて、 $ docker run --platform=linux/arm64 alpine cat /proc/self/cmdline|xargs -0 echo cat /proc/self/cmdline $ docker run --platform=linux/amd64 alpine cat /proc/self/cmdline|xargs -0 echo /bin/cat cat /proc/self/cmdline
CommandLine.argumentsの取得にそれを利用してるSwift製のバイナリはその影響を受けるので、swift buildとか動かない。 $ docker run -it -v $PWD:$PWD:rw -w $PWD --platform=linux/amd64 swift swift build error: Unexpected argument '/usr/bin/swift-build' Usage: swift build <options> See 'build -help' for more information. 正規の手順(argc,argv)?を使ってる場合、影響を受けない。 https://lima-vm.io で立ち上げたdockerだと/proc/self/cmdlineの内容は少しおかしいけど、SwiftのCommandLine.argumentsは影響を受けない。 $ docker.lima run --platform=linux/arm64 alpine cat /proc/self/cmdline|xargs -0 echo cat /proc/self/cmdline $ docker.lima run --platform=linux/amd64 alpine cat /proc/self/cmdline|xargs -0 echo /bin/cat /proc/self/cmdline/proc/self/cmdline じゃなくてcrt0がくれるargvをコンパイラが吐くエントリポイントで保存しておくのが良いのかなぁ。docker buildx build --platform linux/amd64,linux/arm64は、Rosetta入りのlimaでもamd64がqemuになってめっちゃ遅かったけど、Docker DesktopだとちゃんとRosettaで動いて速い。$ docker run --privileged ghcr.io/norio-nomura/re-register-rosetta Rosetta is not correctly registered. Re-registering rosetta... Successfully re-registered Rosetta. $ docker run --privileged ghcr.io/norio-nomura/re-register-rosetta It looks like Rosetta is correctly registered. (edited)c++ ArgvGrabber::ArgvGrabber() : argv(nullptr), argc(0) { findArgv(findStack()); }/proc/self/maps から sscanf(line, "%p-%p", &base, &top) でスタックトップを取ってるけど、これは保険のチェック用っぽいなProcessInfo.arguments とか存在してるし、もうこれはプロセスでグローバルなものとして世の中回ってるって事やな (edited)ProcessInfo.arguments というか CommandLine.arguments ですねSwift自体が提供してるのは/proc/<pid>/cmdline が、その機能じゃないの?docker buildx build --platform linux/amd64,linux/arm64は、Rosetta入りのlimaでもamd64がqemuになってめっちゃ遅かったけど、Docker DesktopだとちゃんとRosettaで動いて速い。 --platform linux/amd64,linux/arm64 でRosettaが使われることが分かったので、Docker Desktopを使う理由はさらに減った。PackageDescription が見えないとか言い出したexport PATH=$HOME/.local/share/swiftly/toolchains/バージョン/usr/bin:$PATH を指定して何とか凌いでますwexport PATH=$HOME/.local/share/swiftly/toolchains/バージョン/usr/bin:$PATH を指定して何とか凌いでますw
1-Xswiftc -disallow-use-new-driver を渡すとある程度の部分までは動きました (1 月くらいに確認した時点では) (edited)docker image pull してコンテナ内のツールチェーンのバージョンとイメージのハッシュをメモして力技で何とかしてました.(自動化できそう)usr/ が出てくるのだと思ったら swift-DEVELOPMENT-SNAPSHOT-2024-04-02-a-ubuntu22.04/ が出てきた。--strip-components=1-Xswiftc -disallow-use-new-driver を渡すとある程度の部分までは動きました (1 月くらいに確認した時点では) (edited)swift コマンドの代わりに古い swift-driver で動いてくれる swift-legacy-driver コマンドがあったのを忘れてました.これが廃止されるまでは swiftly でインストールした場合はこっちでも何とかなりますね.(e.g. swift-legacy-driver build, swift-legacy-driver experimental-sdk install) (edited)/proc/self/cmdline 依存だったコマンド引数取得をスタックスキャンするようにしたところですかねぇ-M raspi4b が使えないのでたまたまリリースを待ち侘びてました. (edited)tonistiigi/binfmt:qemu-v8.1.5を試してみてます。
1tonistiigi/binfmt:qemu-v8.1.5を試してみてます。 --static-swift-stdlibをつけるとリンクエラーになる件、/usr/lib/swift_static/CoreFoundation/module.modulemapと/usr/lib/swift_static/dispatch/module.modulemapで指定されているライブラリがリンカへ渡されていないからみたい。swift-autolink-extractの担当かな?--swift-sdkを受け取ってるのはmainの20240604です。-lDispatchStubsとかが現れるので、それのレスポンスファイルを作成に関わってそうな5.10.1のclangかswift-autolink-extractが怪しいのかなと。-Xswiftc -save-tempsで残せました。ありがとうございます。 (edited)swift-autolink-extractの出力が違ってた。-public-autolink-library でFoundation.swiftmoduleのLINK_LIBRARYエントリとして登録しているので、$ diff -u cross-on-docker.autolink cross-on-mac.autolink --- cross-on-docker.autolink 2024-06-11 16:39:17 +++ cross-on-mac.autolink 2024-06-11 16:39:37 @@ -5,15 +5,12 @@ -lswiftGlibc -lBlocksRuntime -ldispatch --lDispatchStubs -lswiftDispatch --lCoreFoundation -lFoundation -lFoundationNetworking -lFoundationXML -lcurl -lxml2 --luuid -licui18nswift -licuucswift -licudataswiftmoudle.modulemapの定義として該当するのは、DispatchとCoreFoundationですね。 (edited)import Foundation であればリンカオプションなしでリンクできる…はず…import Foundationはあると思う。swift-autolink-extractはswift-driverのお仕事なのかな。swift-autolink-extract はフロントエンドのお仕事ですねswift-autolink-extractは5.10.1のやつが使われてるぽいから、mainで直っても恩恵を受けるのは当分先ですよね。swift.xctoolchain/usr/lib/swift_static/linux/static-stdlib-args.lnkに-lDispatchStubs -lCoreFoundation -luuidを追加することで--static-swift-stdlibでのビルドが通るようになりました。 (edited)
1swift-sdk-generatorの成果物に対して、さらに$ cd ubuntu-jammy.sdk/usr/lib; ln -sf aarch64-linux-gnu/ld-linux-aarch64.so.1と合わせて2箇所の修正が必要でした。 (edited)swift-sdk-generatorのubuntuパッケージダウンロードが不安定すぎて使いたくない。qemu-user-static検出に使おうと思ってたpmapがswiftlint同様にqemu-user-static環境でクラッシュする。apt-get install qemu-user-staticして入る6.2を使ったら、11回中3回クラッシュする感じになり、失敗したjobも再実行で通ったりして、とりあえずPRのビルドが全部通った。スッキリしない。 https://github.com/norio-nomura/docker-swiftlint/pull/37 (edited)/usr/lib/swift_static/linux/static-stdlib-args.lnkに記述する方法swift build --swift-sdkしてターゲットSwift 5.10のツールチェインを起動して、ホストとターゲットのtripleが同じ時、ホスト用にビルドされる.oとターゲット用にビルドされる.oって、混ざったりしないのかな。 (edited).build/aarch64-unknown-linux-gnu/release/SwiftLintExtraRules-tool.build ターゲット向けビルド: .build/aarch64-unknown-linux-gnu/release/SwiftLintExtraRules.build みたいな感じで混ざらないらしい。.oを渡していることが判明。失敗して当然だ。 (edited).build/aarch64-unknown-linux-gnu/release/description.jsonを比較してみたところ、swiftlintっていうモジュールが最終ターゲット用とプラグイン用で2つ作られていて失敗する方は中身が入れ替わってた。 それに合わせて、.build/release.yamlに記述されるswiftlint.product/Objects.LinkFileListの中身もプラグイン用にビルドされたものが渡されて、結果リンクが失敗するぽい。Package.swiftからプラグインのモジュール定義を外したらリンク通ることは確認した。/SwiftLint/.buildが残らないので、残せるように修正します。# repeat following until link error occurs docker buildx build --load builder/ --build-arg BUILDER_IMAGE=swiftlang/swift:nightly -t swiftlint:try --target native-builder --no-cache-filter native-builder --progress plain # if link error occurs, keep image with tag docker tag swiftlint:try swiftlint:link-error How to extract /SwiftLint/.build to link-error directory: mkdir -p link-error; docker run --rm swiftlint:link-error tar czO -C /SwiftLint .build | tar xzvf - -C link-error (edited)aarch64-on-aarch64, x86_64-on-x86_64でランダムで起き、aarch64-on-x86_64, x86_64-on-aarch64では起きません。 (edited)--target native-builderを追加。# repeat following until link error occurs docker buildx build --load . -t poc-module-name-conflict:try --progress plain \ --target builder --no-cache-filter native-builder # after link error occurs, keep image with tag using --target native-builder docker buildx build --load . -t poc-module-name-conflict:try --progress plain \ --target native-builder # if link error occurs, keep image with tag docker tag poc-module-name-conflict:try poc-module-name-conflict:link-error How to extract /poc-module-name-conflict/.build to link-error directory: mkdir -p link-error; \ docker run --rm poc-module-name-conflict:link-error \ tar czO -C /poc-module-name-conflict .build | tar xzvf - -C link-error (edited)--no-cache-filter が無いと怒られてしまったbrew install lima 2. if docker for mac is not installed, install docker cli brew install docker docker-buildx docker-completion 3. create docker instance limactl create https://gist.githubusercontent.com/norio-nomura/9f8d469252a13adf2efdc49af0a47a30/raw/a700cc7261f8e782fd0b7c5373ef1201b5158a0d/lima.yaml --tty=false --name docker 4. enable boot dokcer instance at login limactl start-at-login --enabled docker 5. create "lima-docker" context to use docker context create lima-docker --docker host=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock') 6. use "lima-docker" as default context docker context use lima-docker
https://gist.github.com/norio-nomura/9f8d469252a13adf2efdc49af0a47a30 (edited)template://dockerに対し containerd-snapshotterを有効にしてmulti arch build出来るようにbuildkitを有効にして、docker buildをdocker buildx buildに.buildと正常にリンクできた.buildをCIのアーティファクトからダウンロード出来るように、明日以降するかもしれません。 (edited)--mount=type=bind,target=${BUNDLE_PATH}/${TARGET_TRIPLE_ARCH},from=runtime これを維持したままシェルを繋ぎたい#if os(macOS)でbinaryTargetが定義されてるのだけど、linuxでもダウンロードされるのが気になってて。これって意図された動作なのかな。 https://github.com/realm/SwiftLint/blob/3e8a0516b248cfa4f51d7caa321c842013c42572/Package.swift#L166-L174--mount=type=bind,target=${BUNDLE_PATH}/${TARGET_TRIPLE_ARCH},from=runtime これを維持したままシェルを繋ぎたい buildx build --load . --progress plain --build-arg SLEEP=1 Build session will hangs at sleep like following: #31 0.090 Enter the following command to enter build session: #31 0.090 lima user: #31 0.090 limactl shell docker bash -c 'sudo nsenter --all --target=$(lsns|awk "/^4026532477/{print \$4}") bash' #31 0.090 #31 0.090 Docker for Mac user: #31 0.090 docker run -it --privileged --pid=host --rm ubuntu bash -c 'nsenter --all --target=$(lsns|awk "/^4026532477/{print \$4}") bash' Copy and paste the command to enter build session. $ docker run -it --privileged --pid=host --rm ubuntu bash -c 'nsenter --all --target=$(lsns|awk "/^4026532477/{print \$4}") bash' ################################################################ # # # Swift Nightly Docker Image # # Tag: swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a # # # ################################################################ root@buildkitsandbox:/#
(edited)nsenter(1)を使う手法。$ limactl shell docker bash -c 'sudo nsenter --all --target=$(lsns|awk "/^4026532602/{print \$4}") bash' ################################################################ # # # Swift Nightly Docker Image # # Tag: swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a # # # ################################################################ root@buildkitsandbox:/# docker buildx build https://gist.github.com/edf224977880e6e7598e76b1330f2990.git --build-arg SLEEP=1docker buildx build - DockerfileRUN --mount=type=cacheのターゲットディレクトリ内ならば、ビルドセッションを跨いでも維持されるのかな? (edited)swift-DEVELOPMENT-SNAPSHOT-2024-07-01-aキタswift -versionしか実行してないから、引っかからないぽい。swift-DEVELOPMENT-SNAPSHOT-2024-07-01-adockerイメージを使って、クロスビルド使った問題再現用プロジェクトのビルドでリンクエラーが起きなくなったことを確認した。
1swift -versionしか実行してないから、引っかからないぽい。 docker run --rm --privileged multiarch/qemu-user-static --reset -p yes使ってインストールする方法。 (edited)docker/setup-qemu-action、ubuntuやdebianからaptで配布されてるモノ、qemuのソース取得してビルドする、とか色々試してダメだったのに。multiarch/qemu-user-staticがインストールしているバージョンを調べたらdebian bookwormで使われてた7.2で、ubuntuでは使われていないバージョンだった。 ちなみにubuntuでのqemu-user-staticは focal: 4.2 jammy: 6.2 mantic: 8.0 noble: 8.2 で、僕が試してダメだったのは 6.2, 8.0, 8.2, 9.0.1(自前ビルド)swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-02-aにリンクエラー対策パッチがチェリーピックされてて swiftlang/swift:nightly-6.0-jammy も更新されてたので、対策なしでリンクエラーが起きないことも確認した。tonistiigi/binfmt, multiarch/qemu-user-static の各バージョンをインストールして、arm64版swiftlintを2回動作確認で起動するDockerfileを10回ビルドし、クラッシュやハングアップしないかテストしてみた。 https://github.com/norio-nomura/compare-qemu-user-static/actions/runs/9856830637 (edited)tonistiigi/binfmt:latest はダメで、multiarch/qemu-user-static:latestは通る。norionomura/swiftlintにaarch64追加した。 そしてqemu-user-staticのバージョンによりクラッシュ回避する情報をforumへ投稿した。 https://forums.swift.org/t/swift-runtime-unable-to-suspend-thread-when-compiling-in-qemu/67676/20environっていう環境変数ポインタが意図しない場所にある? setenvとかを使うとずれてしまうことがあるらしい?***GRABBING ARGV for 5534*** envp = 0xaaaaffb21da0, stack is from 0xffffebec0000 to 0xffffebee1000 ARGV is at (nil) with count 0 ***ARGV GRABBED***setenvを使うとenvironが大きくずれることはわかったけど、自前でsetenvを_swift_stdlib_getUnsafeArgvArgcよりも先に呼び出す方法がわからなくてうまく再現できないAppCモジュールをAppターゲットがimportする形にしてますa.cppの中にhttps://github.com/swiftlang/swift/blob/afe1fa0c09ff240756bd3e15d3e441bc4a71e776/stdlib/public/CommandLineSupport/CommandLine.cpp#L231 のArgvGrabberのコピペ実装を置いていて、そっちはsetenvのあとに呼び出されていい感じに壊れるんですよねCommandLine.argumentsで出てくるSwift標準ライブラリのArgvGrabberは正しい結果を返していて、うまく再現できないlibBadLib.soができたのでdynamicになったっぽいroot@36e7be3c11c2:/empty-args-test# swift run Building for debugging... [10/10] Linking App Build complete! (0.41s) 😈 use 'setenv' in static constructor a.cpp: ***GRABBING ARGV for 6756*** a.cpp: envp = 0xaaaaf3b8a940 a.cpp: envp = 0xaaaaf3b8a940, stack is from 0xffffd25d0000 to 0xffffd25f1000 ARGV is at (nil) with count 0 // ←自前実装のArgvGrabberは壊れてる a.cpp: ***ARGV GRABBED*** Hello, World! CommandLine.arguments: [".build/aarch64-unknown-linux-gnu/debug/App"] // ←SwiftStdLibのほうはうまく動いてる(lldb) bt * thread #1, name = 'App', stop reason = breakpoint 1.1 2.1 * frame #0: 0x0000fffff5adc9f4 libc.so.6`__setenv(name="ZES_ENABLE_SYSMAN", value="1", replace=1) at setenv.c:255:6 frame #1: 0x0000fffff7fc7624 frame #2: 0x0000fffff7fc772cZES_ENABLE_SYSMANとかいう怪しい文字列は得られた(lldb) image lookup -a 0x0000fffff58ac9f4 Address: libc.so.6[0x000000000003c9f4] (libc.so.6.PT_LOAD[0]..text + 88500) Summary: libc.so.6`__setenv at setenv.c:255:6(lldb) breakpoint set -n setenv Breakpoint 1: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (lldb) run Process 7724 launched: '/empty-args-test/.build/debug/App' (aarch64) 1 location added to breakpoint 1 Process 7724 stopped * thread #1, name = 'App', stop reason = breakpoint 1.1 frame #0: 0x0000fffff58ac9f4 libc.so.6`__setenv(name="ZES_ENABLE_SYSMAN", value="1", replace=1) at setenv.c:255:6 (lldb) bt * thread #1, name = 'App', stop reason = breakpoint 1.1 * frame #0: 0x0000fffff58ac9f4 libc.so.6`__setenv(name="ZES_ENABLE_SYSMAN", value="1", replace=1) at setenv.c:255:6 frame #1: 0x0000fffff7fc7624 frame #2: 0x0000fffff7fc772c (lldb) image lookup -a 0x0000fffff7fc7624 (lldb) image lookup -a 0x0000fffff7fc772c (lldb) (lldb) breakpoint set -n setenv Breakpoint 1: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (lldb) breakpoint set -r '^\$ss11CommandLine.*' Breakpoint 2: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (lldb) run Process 8380 launched: '/empty-args-test/.build/debug/App' (aarch64) 17 locations added to breakpoint 2 1 location added to breakpoint 1 Process 8380 stopped * thread #1, name = 'App', stop reason = breakpoint 1.1 frame #0: 0x0000fffff58ac9f4 libc.so.6`__setenv(name="ZES_ENABLE_SYSMAN", value="1", replace=1) at setenv.c:255:6 (lldb) c Process 8380 resuming :smiling_imp: use 'setenv' in static constructor Process 8380 stopped * thread #1, name = 'App', stop reason = breakpoint 1.1 frame #0: 0x0000fffff58ac9f4 libc.so.6`__setenv(name="FOO", value="BAR", replace=1) at setenv.c:255:6 (lldb) c Process 8380 resuming a.cpp: ***GRABBING ARGV for 8380*** a.cpp: envp = 0xaaaaaafee220 a.cpp: envp = 0xaaaaaafee220, stack is from 0xfffffffdf000 to 0x1000000000000 ARGV is at (nil) with count 0 a.cpp: ***ARGV GRABBED*** Hello, World! Process 8380 stopped * thread #1, name = 'App', stop reason = breakpoint 2.10 frame #0: 0x0000fffff7c20dec libswiftCore.so`$ss11CommandLineO9argumentsSaySSGvgZ libswiftCore.so`$ss11CommandLineO9argumentsSaySSGvgZ: -> 0xfffff7c20dec <+0>: stp x29, x30, [sp, #-0x10]! 0xfffff7c20df0 <+4>: adrp x0, 795 0xfffff7c20df4 <+8>: add x0, x0, #0x60 0xfffff7c20df8 <+12>: adrp x1, 0 main.swiftの中が走るまでの間にCommandLineに誰も触ってないな・・・CommandLineの呼び出しに関わらずargvを保持してるわDEBUG_ARGVGRABBERをセットしてstdlibを自前でビルドする必要が・・・--static-swift-stdlibしたらstdlibより先に自前コードのコンストラクタセクションが開始されてそこでsetenvすれば壊せる(dynamicにして壊せなかったのは、SwiftPMのdynamic libという時点でlibSwiftCoreの依存が自動で追加されてそっちが先にinitされるため。clang単体でやれば変わったかも) (edited)__attribute__((constructor(0)))とかすれば誤魔化せそうimport Foundation fflush(stdout)import Foundation fflush(stdout) <stdin>:2:8: error: reference to var 'stdout' is not concurrency-safe because it involves shared mutable state 1 | import Foundation 2 | fflush(stdout) | `- error: reference to var 'stdout' is not concurrency-safe because it involves shared mutable state 3 | SwiftGlibc.stdout:1:12: note: var declared here 1 | public var stdout: UnsafeMutablePointer<FILE>! | `- note: var declared here@preconcurrencyでよかった.swift-format がないディレクトリで実行した場合に動かなくなったなとおもっていたのですが,どうやら設定ファイルを探す処理で無限ループしていたみたいです. macOS では問題ないので Foundation の URL の挙動の違いが原因だったようです. https://github.com/swiftlang/swift-format/issues/694#issuecomment-2397669986 (edited)
1deletingLastPathComponent() の単体テストって String に対してはあるけれど,URL に対してのテストコードは一切無いんですね.URL(filePath: "/foo", directoryHint: .isDirectory).deletingLastPathComponent().path() が "/" になりました..swift-format がすでにあるディレクトリでしか実行しない人は踏まないので,踏む環境は限られると思いますがハマる人はめっちゃ踏みやすいですね. (edited)dirnameが同じ動作をしてたのを思い出した。はまりがちな罠なのかな。 override define dirname $(patsubst %/,%,$(dir $(patsubst %/,%,$1))) endef $(info dirname: $(call dirname,/foo)) test:
$ make test dirname: make: Nothing to be done for `test'.
(edited)/ の上が /.. になる環境もあるらしくて,その環境での無限ループを修正するために /foo の上が空になる環境 (Linux の Swift 6.0) でまた無限ループが再発してしまった... この辺は連鎖的に問題が起こっていて大変そうですね... https://github.com/swiftlang/swift-format/pull/845swift -versionしか実行してないから、引っかからないぽい。 swift test を aarch64 Linux の実機で実行するとクラッシュもしくはカーネルごとハングするので qemu-user-static の問題と関連していたりしないか気になってます. Fedora 40 (Asahi Linux) だとシェルごとクラッシュして,Raspberry Pi OS (Debian 12) だとカーネルごとハングしてマシンごと強制再起動するしかなくなります.どちらも aarch64 Linux です.x86_64 Linux 環境だと今のところ同じ条件でもこのような問題が起きたことはないです.aarch64 Linux 環境でもこのリポジトリの swift test 以外で同じ Swift ツールチェーンを使っている上では何も問題が起こったことがないです.Process.waitUntilExit() がハングするんですがそんなことってあります? import Foundation let process = Process() process.executableURL = URL(fileURLWithPath: "/bin/sh") process.arguments = ["-c", "echo 'Hello, World!'"] let stdout = Pipe() process.standardOutput = stdout try process.run() let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile() let stdoutString = String(data: stdoutData, encoding: .utf8)! process.waitUntilExit() // <- ここで固まって先に進まない print(stdoutString) (edited)waitUntilExit の前に while process.isRunning {} するだけで通るようになるのも謎Process.waitUntilExit() がハングするんですがそんなことってあります? import Foundation let process = Process() process.executableURL = URL(fileURLWithPath: "/bin/sh") process.arguments = ["-c", "echo 'Hello, World!'"] let stdout = Pipe() process.standardOutput = stdout try process.run() let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile() let stdoutString = String(data: stdoutData, encoding: .utf8)! process.waitUntilExit() // <- ここで固まって先に進まない print(stdoutString) (edited)waitUntilExit()がハングアップするようになって、16.04へ戻したことがある。 (edited)swift-5.0-RELEASEの時だった。まあ今でも実行環境により動かなくなる実装になっててもおかしくはない?swift package init --type executable して swift build --swift-sdk arm64-apple-macosx --product test で作成したtestがmacOS上で動くところまで確認できたけど、botに使わせるのはかなりハードルが高いな。swift build --swift-sdkが生成するコマンドラインを、botのCLIへ渡す必要がある。
1swift build --verbose --swift-sdkで観測できる、生成されるfrontendへのコマンドラインオプションをコピーしてbotのCLIへ渡そうとすると、Discordのメッセージ長制限に引っかかる。swift build --swift-sdkは、最後codesignしようとしてcodesignがなくて失敗する。import SwiftUIもいける--swift-sdk相当のオプションを暗黙で渡せるようにするのは現状では難しいです。 特定バージョンのコンパイラに最新SDKの組み合わせが常に使われるbotを別途用意するのはできるかも?ってところ。
-target arm64-apple-macosx15.0 -Onone -resource-dir /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -color-diagnostics -swift-version 6 -sdk /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -use-ld=lld -Xfrontend -tools-directory -Xfrontend /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/toolset/bin -sdk /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -ld-path=/home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/toolset/bin/ld64.lld -g -Xcc -isysroot -Xcc /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -Xcc -g -I /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/lib -swift buildが--swift-sdkオプションの指定で上記オプションを生成する部分が、botが利用しているswiftには存在しないので、この面倒をみないと簡易にSwiftSDKを切り替えられる様にはできない。 (edited)/usr/bin/swift-frontend --version Swift version 6.0.3 (swift-6.0.3-RELEASE) Target: x86_64-unknown-linux-gnuTarget: x86_64-apple-macosx15.2 Swift version 6.0.3 (swift-6.0.3-RELEASE) Target: x86_64-apple-macosx15.2 (edited)import SwiftUI (edited)import SwiftUI (edited)/usr/bin/swift-frontend -frontend -interpret - -target x86_64-apple-ios18.2-macabi -enable-objc-interop -sdk /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/lib -tools-directory /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/toolset/bin -empty-abi-descriptor -resource-dir /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -Xcc -isysroot -Xcc /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -module-name main -target-sdk-version 18.2 -target-sdk-name macosx15.2 -prebuilt-module-cache-path /home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/prebuilt-modules -external-plugin-path '/home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -external-plugin-path '/home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/home/bot/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/pluginsTarget: x86_64-apple-ios18.2-macabi Swift version 6.0.3 (swift-6.0.3-RELEASE) Target: x86_64-apple-ios18.2-macabi (edited)#if canImport(Musl) print("Hello, Musl!") #endif#if canImport(Musl) print("Hello, Musl!") #endif Hello, Musl!Target: x86_64-swift-linux-muslsdkRootPath: /home/bot/.swiftpm/swift-sdks/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64 swiftResourcesPath: /home/bot/.swiftpm/swift-sdks/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static swiftStaticResourcesPath: /home/bot/.swiftpm/swift-sdks/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static includeSearchPaths: not set librarySearchPaths: not set toolsetPaths: ["/home/bot/.swiftpm/swift-sdks/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.3-RELEASE_static-linux-0.0.1/swift-linux-musl/toolset.json"] (edited)import Musl print("Hello, Musl!")import Musl print("Hello, Musl!") Target: x86_64-swift-linux-musl <unknown>:0: error: compiled module was created by an older version of the compiler; rebuild 'Swift' and try again: /home/bot/.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a_static-linux-0.0.1.artifactbundle/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/Swift.swiftmodule/x86_64-swift-linux-musl.swiftmoduleimport Musl print("Hello, Musl!") Hello, Musl!Target: x86_64-swift-linux-muslimport Musl print("Hello, Musl!") Hello, Musl!Target: x86_64-swift-linux-musl$ curl -fLsS https://download.swift.org/swift-6.1-branch/static-sdk/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz -O $ sha256 swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz SHA256 (swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz) = c701d3f5bb69464fd443f20c4748cab068c9c6d8f6995f1ba5be70022778d21f $ cat swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz <?xml version="1.0" encoding="UTF-8" standalone="no"?><Error><Code>404</Code><Message>No message</Message><RequestId>7e2efc3d-e9a6-48be-935e-8c25252d5475</RequestId></Error>$ swift sdk install --checksum c701d3f5bb69464fd443f20c4748cab068c9c6d8f6995f1ba5be70022778d21f https://download.swift.org/swift-6.1-branch/static-sdk/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz Downloading a Swift SDK bundle archive from `https://download.swift.org/swift-6.1-branch/static-sdk/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz`... Downloading 100% [=====================================================================================================] Downloading swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz Swift SDK bundle archive successfully downloaded from `https://download.swift.org/swift-6.1-branch/static-sdk/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz`. Verifying if checksum of the downloaded archive is valid... Downloaded archive has a valid checksum. Swift SDK bundle at `https://download.swift.org/swift-6.1-branch/static-sdk/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_static-linux-0.0.1.artifactbundle.tar.gz` is assumed to be an archive, unpacking... Error: tar: Error opening archive: Unrecognized archive formatcurlでAccept-Encoding: ...を渡していないのにたまにContent-Encoding: gzipで返されて、鍵のインポート時にエラー gpg: no valid OpenPGP data found. で失敗してた。 curlで明示的に--compressedを使うことでエラー回避。swiftのサブコマンド追加、macOSだとPATHが通ってればどこに置いても良いけど、Linuxだとswiftと同じディレクトリしか認識しない。CommandLine.arguments[0]がAbsolutePathだとそのパスのディレクトリ決め打ちになる。 [https://github.com/swiftlang/swift-driver/blob/8cbf26f4024d333cc5108403d08f8dd07048141f/Sources/swift-driver/main.swift#L125]swift-driverをmacOSでビルドして実行すると、Linux同様swiftと同じディレクトリからしか見つけてくれない macOSでPATHが通ってればサブコマンドが動く動作は、もしかしてmacOSの/usr/bin/swiftがswift-driverとは関係なく、勝手にやってる動作なのでは (edited)curlでAccept-Encoding: ...を渡していないのにたまにContent-Encoding: gzipで返されて、鍵のインポート時にエラー gpg: no valid OpenPGP data found. で失敗してた。 curlで明示的に--compressedを使うことでエラー回避。 Dockerfile をビルドしようとしてもいつまで経ってもビルドに失敗し続けたり,いろんなところで影響してますね... (edited)Dockerfileのツールチェインインストールをswiftlyへ変えようかと思ったけど、キーのgzip対策がされてなさそうなので却下。swift-driverをmacOSでビルドして実行すると、Linux同様swiftと同じディレクトリからしか見つけてくれない macOSでPATHが通ってればサブコマンドが動く動作は、もしかしてmacOSの/usr/bin/swiftがswift-driverとは関係なく、勝手にやってる動作なのでは (edited)swiftly経由だと直接swift-driverを起動するから、macOSでもサブコマンドをPATHから探してくれない、Linux版ツールチェインの動作と同じになる。 (edited)swift hoge じゃなくて swift-legacy-driver hoge なら PATH にある swift-hoge を呼び出してくれるので,macOS かどうかじゃなくてそもそも legacy driver と new driver (swift-driver repo) の違いだと思います.swift-driver は drop-in replacement を目指していると書いていたので,issue を立てたら確認してもらえたりしないですかね? https://github.com/swiftlang/swift-driver/issues (edited)swift hoge -disallow-use-new-driver でも swift-legacy-driver hoge と同じで PATH にある swift-hoge を呼び出してくれます./usr/bin/swiftにはTOOLCHAINS環境変数によって実行するswiftを切り替える機能が入っています。これって、swift-legacy-driverの挙動ですかね? $ /usr/bin/swift -version swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3) Target: arm64-apple-macosx15.0 $ TOOLCHAINS=org.swift.610202503251a /usr/bin/swift -version Apple Swift version 6.1-dev (LLVM 83bb915697f5992, Swift 1e211b4d3227ecc) Target: arm64-apple-macosx15.0 (edited)TOOLCHAINS は xcrun の機能ですね./usr/bin/swift のシンボルを nm で一覧してみても xcrun を呼んでいるっぽいです./usr/bin/swiftはlegacy-driverではなさげ。 swift-driverへサブコマンド機能が移植された時点でロジックが変わってしまってるぽい。 https://github.com/swiftlang/swift-driver/commit/eeab9a631e1308e41179c8be4a98ce584d896b64#diff-1e920c3af1340bd633526f526ae0d6b734b448ebadf128e699cbd4c212591180R29-R36/usr/bin/swiftはlegacy-driverではなさげ。 swift-driverへサブコマンド機能が移植された時点でロジックが変わってしまってるぽい。 https://github.com/swiftlang/swift-driver/commit/eeab9a631e1308e41179c8be4a98ce584d896b64#diff-1e920c3af1340bd633526f526ae0d6b734b448ebadf128e699cbd4c212591180R29-R36 sudo fs_usage -w|grep legacyに何も出ないから違うと思うけどな。swift -disallow-use-new-driver とかはそれだと出てこないけれど legacy driver を使いますし.swift-legacy-driverってコマンドが無い。そしてLinuxだとswift-frontendへのシンボリックリンクだ。swift-legacy-driver が legacy driver 本体だと思われているならそれは違いますよ.あれは swift のデフォルトが legacy driver から new driver に切り替わったときに色々問題が起こることを想定して,デフォルトで legacy driver を選択する swift コマンド,として用意されたものだったはずです.swift build とかの swift を swift-legacy-driver に置き換えて,swift-legacy-driver build とか書くとこれまで通りビルドしてくれるという.swift-dirverはSWIFT_USE_OLD_DRIVERが定義されていたり-disallow-use-new-driverが渡されたりすると、swift-legacy-driverをexecしてますよ。 [https://github.com/swiftlang/swift-driver/blob/swift-6.0.3-RELEASE/Sources/swift-driver/main.swift#L74-L84]swift-legacy-driver ができたからそっちを呼び出すようにしよう!となったか)-disallow-use-new-driverが渡された時に、どうやってlegacy-driverを起動しているのかという謎が気になってしまったwotool -L (xcrun -find swift)を見るとlibswiftCore.dylibとかリンクされてるからswift-driverだと思うけど。lib/DriverTool/driver.cppのswift::mainEntry()から起動するやつだと思ってた。/usr/bin/swiftの小ささからすると、実装は/usr/lib/libxcselect.dylibにあるのだろうけど、dylibはOSに隠されてしまって見られないから、その中に警告メッセージを削ったswift-legacy-driverが入っていてもおかしくはない。 $ otool -L /usr/bin/swift /usr/bin/swift: /usr/lib/libxcselect.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0) $ otool -tv /usr/bin/swift|wc -l 149 けど確認しようがない。 (edited)/usr/lib の実体が見えないやつ・・・execsnoop(1m)ってのを使えばプロセス起動を監視できそうだけど、そこまでしたくないwxcrunも実装は/usr/lib/libxcselect.dylibの中。/usr/bin/xcrunは逆アセンブルをここに貼れるほど小さい。 $ otool -tv /usr/bin/xcrun /usr/bin/xcrun: (__TEXT,__text) section 0000000100000520 pacibsp 0000000100000524 stp x22, x21, [sp, #-0x30]! 0000000100000528 stp x20, x19, [sp, #0x10] 000000010000052c stp x29, x30, [sp, #0x20] 0000000100000530 add x29, sp, #0x20 0000000100000534 mov x19, x1 0000000100000538 mov x20, x0 000000010000053c bl 0x100000578 ; symbol stub for: _getprogname 0000000100000540 mov x8, x0 0000000100000544 ldrb w9, [x8], #0x1 0000000100000548 cmp w9, #0x2d 000000010000054c csel x21, x0, x8, ne 0000000100000550 adrp x1, 0 ; 0x100000000 0000000100000554 add x1, x1, #0x5a8 ; literal pool for: "xcrun" 0000000100000558 mov x0, x21 000000010000055c bl 0x100000588 ; symbol stub for: _strcasecmp 0000000100000560 cmp w0, #0x0 0000000100000564 csel x0, xzr, x21, eq 0000000100000568 sub w1, w20, #0x1 000000010000056c add x2, x19, #0x8 0000000100000570 mov w3, #0x0 0000000100000574 bl 0x100000598 ; symbol stub for: _xcselect_invoke_xcrun (edited)_xcrun_main を持ってますし.$ dive_in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin; ls -la swift swift-frontend swift-driver lrwxr-xr-x 1 norio staff 14 3 26 10:24 swift@ -> swift-frontend -rwxr-xr-x 1 norio staff 9265296 3 18 19:40 swift-driver* -rwxr-xr-x 1 norio staff 356405232 3 18 19:40 swift-frontend* $ DOCKER_UBUNTU_IMAGE=swift docker-ubuntu all contents will be removed after the container is stopped root@swift:~# cd /usr/bin root@swift:/usr/bin# ls -la swift swift-frontend swift-driver lrwxrwxrwx 1 root root 12 Dec 11 17:01 swift -> swift-driver -rwxr-xr-x 1 root root 38219560 Dec 11 18:23 swift-driver -rwxr-xr-x 1 root root 182984296 Dec 11 16:38 swift-frontend macOSは swift -> swift-frontend Linuxは swift -> swift-driver だ。 (edited)swift-frontendは-disallow-use-new-driverが無ければswift-driverを起動する。swift-driver は-disallow-use-new-driverが有ればswift-frontendを起動する。fs_usage -w | grep swift-help しながら swift help と swift help -disallow-use-new-driver を比較した場合も swift-help を execve しているのが swift-driver (new driver) か swift-frontend (legacy driver) かでクッキリ分かれてました.swiftシンボリックリンク先の違いだけだ。swiftをswift-frontendへのシンボリックリンクにしてswift-legacy-driverを削除してしまえば、サブコマンド検索について望む動作になるのでは。swiftをswift-frontendへのシンボリックリンクにしてswift-legacy-driverを削除してしまえば、サブコマンド検索について望む動作になるのでは。 swiftをswift-frontendへのシンボリックリンクにしてswift-legacy-driverを削除してしまえば、サブコマンド検索について望む動作になるのでは。 swiftシンボリックをいじる必要があるけど、それぞれにオレオレサブコマンドを入れるよりマシか。 (edited)xcrunにswiftの挙動を切り替えるような謎機能がなさそうで良かった (edited)swiftly経由だと直接swift-driverを起動するから、macOSでもサブコマンドをPATHから探してくれない、Linux版ツールチェインの動作と同じになる。 (edited)swiftはswift-driverを指してて、swiftlyを使った時の挙動になるw (戻ってきた!)swiftlyがツールチェインの選択にxcrun (TOOLCHAINS環境変数)を使ってくれれば、サブコマンド検索も望む動作になるのでは?と考えてたけど、今までの理由を考えるとダメってことだよね。 インストールされたツールチェインのswiftシンボリックリンクを変えないと望む動作にはならない。/usr/bin/swiftはlegacy-driverではなさげ。 swift-driverへサブコマンド機能が移植された時点でロジックが変わってしまってるぽい。 https://github.com/swiftlang/swift-driver/commit/eeab9a631e1308e41179c8be4a98ce584d896b64#diff-1e920c3af1340bd633526f526ae0d6b734b448ebadf128e699cbd4c212591180R29-R36 swift-driverへの移植時にコメントと違う動作になってしまったのを、直さないと治らない。 (edited)alias swift=swift-legacy-driver で解決じゃ無いですか?廃止されるまでの命ですが.cp swift-legacy-driver swift (or mv) で上書きする. (edited)*** Signal 11: Backtracing from 0x7f38f3844c1d... done *** *** Program crashed: Bad pointer dereference at 0x00007f3f27880849 *** Thread 0 "jsvPackageTests": 0 0x00007f38f384280a <unknown> in libc.so.6 Thread 1: 0 0x00007f38f391e88d <unknown> in libc.so.6 Thread 2: 0 0x00007f38f3925e2e <unknown> in libc.so.6 ... Thread 10 crashed: 0 0x00007f38f3844c1d <unknown> in libc.so.6 Thread 11 "SGLTN-TP-#0": 0 0x00007f38f3891117 <unknown> in libc.so.6 ... Backtrace took 29.94s (edited)- run: swift testubuntu-22-8cpu をそのまま使ってるのだけど、これにデバッグシンボルが入ってないのかも
1container image pull ghcr.io/norio-nomura/swift_discord_bot:main と docker pull ghcr.io/norio-nomura/swift_discord_bot:main を同時に開始すると、dockerが完了した時点でcontainerは30%ちょっとくらいでした。docker pullはlinux/arm64だけで5分43秒 container image pullはlinux/amd64,linux/arm64の2つで24分30秒 (edited)dockerとcontainerを同時(1秒差)で開始しての結果なので、ネットワーク帯域云々は処理時間差に関係ないかと。 (edited)
RUNとかはMacのファイルシステムをvirtio-fsでマウントしたVM内で実行して、ファイルシステムへの変更はMac側で収集するらしい。 Virtualization.frameworkのvirtio-fsマウントはVM内でのファイルのオーナー操作が無視される筈だから、そのあたり非互換になりそう。 (edited)container run --name docker --detach --publish-socket /var/run/docker.sock:/var/run/docker.sock --memory 16G docker.io/library/docker --feature containerd-snapshotter この一文でcontainerにdockerホストを作れるけど、docker compose buildとか実行するとVMがkernel panic起こして途中で止まってしまう。残念。 (edited)RUNとかはMacのファイルシステムをvirtio-fsでマウントしたVM内で実行して、ファイルシステムへの変更はMac側で収集するらしい。 Virtualization.frameworkのvirtio-fsマウントはVM内でのファイルのオーナー操作が無視される筈だから、そのあたり非互換になりそう。 (edited)RUN --device=lima.io/rosetta=enable-aot-caching ... みたいな記述をすることで、RUNの環境にホスト側で動くAOT Cachingを受け持つrosettad daemonが使うソケットをコンテナ内にbindマウントする様に構成できる。 すると、コンテナ内のrosettaがrosettadと通信できるようになり、AOT Cachingが動くようになる。 (edited)curlでAccept-Encoding: ...を渡していないのにたまにContent-Encoding: gzipで返されて、鍵のインポート時にエラー gpg: no valid OpenPGP data found. で失敗してた。 curlで明示的に--compressedを使うことでエラー回避。 --compressed が付きましたね.swiftly にもついて欲しい... https://github.com/swiftlang/swift-docker/pull/495curl --silent --retry 3 --location --fail --compressed https://swift.org/keys/all-keys.asc | gpg --import - で先に鍵がインポート済みの状態になるようにして解決しました.(なので swiftly の外側で回避自体は可能ではある) (edited)--compressed なし) を入れた後の再現だったので,swiftly というより curl での再現例でした… すみません普通に私の勘違いかもしれないので,改めて確認し直します.-Xlinker -z -Xlinker stack-size=... が macOS だと使えない問題」って,WASI 向けのクロスコンパイル時も以前は同様だったので困っていたんですが,最近のツールチェーンでは起こらなくなってませんか?私の方では起こらなくなりました.(そもそも Wasm のリンクだと wasm-ld が使われるはずなのに ld-prime (ld64) がエラーを吐いているのはなぜなんだろうとずっと思ってました) (edited)# swift-syntax swift build -c release --build-tests --swift-sdk swift-6.2-RELEASE_wasm -Xlinker -z -Xlinker stack-size=16777216 では起こらなくなりましたが # SwiftLint swift build -c release --product swiftlint --swift-sdk aarch64-swift-linux-musl -Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT -Xlinker -z -Xlinker stack-size=0x80000 では起こりますね... (edited)
2-Xlinkerってマクロビルドにも適用されちゃうのか--toolsetで渡す、くらいかなー
1-Xlinker -z -Xlinker stack-size=4194304 の代わりに --toolset toolset.json を指定してみたらビルドが通りました. { "schemaVersion": "1.0", "linker": { "extraCLIOptions": [ "-z", "stack-size=4194304" ] } }