͜ΜͳΞΠίϯͰͬͯΔΑ Twitterʢݱ 𝕏ʣ GitHub ଞɿ@nnsnodnb iOSΞϓϦΤϯδχΞΛҾୀͨ͠ϓϩμΫτΤϯδχΞ I'm no longer an iOS apps engineer. ઍ༿ݝദࢢएࣲʹॅΜͰ͍·ͨ͠ I lived in Wakashiba Kashiwa-city, Chiba. ϑϥʔגࣜձࣾ͞ΜͰಇ͍͍ͯ·ͨ͠ I worked at Fuller. Inc. 2
Linux $ mkdir hello && cd hello $ swift package init --type executable Creating executable package: hello Creating Package.swift… $ swift build Building for debugging... [8/8] Linking hello… $ file .build/debug/hello .build/debug/hello: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, with debug_info, not stripped 4
on Ubuntu without Swift runtime. $ docker cp f95bff9ca073:/hello/.build/debug/hello ./hello Successfully copied 78.8kB to /Users/nnsnodnb/hello $ docker run --rm -t -v $(pwd)/hello:/hello ubuntu:24.04 /hello /hello: error while loading shared libraries: libswiftSwiftOnoneSupport.so: cannot open shared object file: No such file or directory 4
made at WWDC24 allows for fully statically linked for Linux programs. $ swift sdk install <URL> [--checksum <checksum>] $ swift build --swift-sdk x86_64-swift-linux-musl $ swift build --swift-sdk aarch64-swift-linux-musl 5
and launching the necessary libraries and modules at runtime. CocoaPodsجຊͪ͜Β͕༻͞ΕΔʢuse_frameworks!ʣ CocoaPods is generally used here. ࣮ߦόΠφϦ͕খ͍͞ The executable binary is small. ಈతϥΠϒϥϦΛΠϯετʔϧ͢Δඞཁ͕͋Δ It’s necessary to install dynamic libraries. 6
the required libraries and modules during the build process to generate product. Swift Package Managerجຊͪ͜Β͕༻͞ΕΔ Swift Package Manager is generally used here. ࣮ߦόΠφϦ͕େ͖͍ The executable binary is large. ಈతϥΠϒϥϦΛΠϯετʔϧ͢Δඞཁ͕ͳ͍ It’s not necessary to install dynamic libraries. 6
Linux SDK" included. Static Linux SDK ؚ͕·Εͨ Docker Πϝʔδ͕΄͍͠ I want Docker image that includes the Static Linux SDK. Θ͔ΔŊ ࣗ࡞ͨ͠ I know. I made one myself. @arasan01_me ఱ࠽ Genius. ΞϩέʔλΛmuslඪ४͔Βmimallocʹͨͭ͠ศར The one that switches the allocator from the musl default to mimalloc is also convenient. @arasan01_me https://x.com/nnsnodnb/status/1843598365839491082 ຊਓ͔Β༻ڐࡁΈʢThanks @arasan01_meʣ 7
Hello, world! real 0m0.005s user 0m0.002s sys 0m0.003s 2. ੩తϦϯΫ Static Linking $ time .build/debug/hello Hello, world! real 0m0.002s user 0m0.000s sys 0m0.002s 8
SDK is easy. Alpine LinuxͷΑ͏ͳܰྔͳڥͰ࣮ߦͰ͖Δ It can run even in lightweight environments like Alpine Linux. ඞͣ͠ಈతϦϯΫΑΓύϑΥʔϚϯε͕ྑ͍Θ͚Ͱͳ͍ It doesn’t necessarily offer better performance than dynamic linking. Swift ϥϯλΠϜͳ͠Ͱ࣮ߦόΠφϦΛͰ͖ΔΑ͏ʹͳΔ We can distribute the executable binary without Swift runtime. 11
development using the "Static Linux SDK"! Chiba.swift #2 Thank you Slide Source: https://github.com/nnsnodnb/chiba-swift-static-linux-sdk-presentation 15